I want to be able to reference an image in a postscript file from a separate file location on my Xerox FreefLow print server rather than embed it into the postscript directly. This is to allow for print files that are very variable and have over a hundred variable images to choose from. I have tried using 'run exec' or 'GetTiff' Commands without success. Any advice on using VIPP postscript commands would be appreciated - postscript output is generated from PreS and PDF output is not an option.
Sample postscript I have tried
%!PS-Adobe-3.0
/Times-Bold findfont
20 Scalefont
setfont
200 450 moveto
(The Document Company Bryan) show
gsave
initgraphics
(/opt/XRXnps/resources/bf/czrdrf.ps.p000000001.ps) run exec)
grestore
showpagetext
I don't know anything about the Xerox Freeflow server, but I can offer some critique of your postscript code.
First, initgraphics should never be used in a document program. The graphics should already be initialized to the default settings by default, and if not, maybe it's because the code has been embedded into an altered context. Here, the only things altered are the current font (default is an invalid font), and defined the current point (default is undefined). Unless the embedded program depends upon these two elements of the graphics state to be undefined, there's no need to mess with resetting the state.
run runs the program in the named file. exec would only be needed if the result of the program file were a partially-evaluated procedure of some kind. I doubt this is the case. So my guess is that exec is causing a stackunderflow error and aborting the program. There should be some way to configure the server to report postscript errors back to you. Or error reports may be in a log file.
showpagetext is not a standard ps operator. showpage is.
I'd suggest you try with a simpler ps program, rather than the image program. First, we need to be sure that the file is accessible to the interpreter. So, we need to know if the error in the above program was actually stackunderflow as I suspect, or invalidfilename or invalidfileaccess or ioerror or something else.
If any or all of these efforts fail, there is an older postscript technique that you might consider. If the interpreter can create and write files, you can download the image by writing a program which writes the image program to disk. If that works, reading from the file later should also work.
Related
I have a file located at C:\printme.txt
I want to print it to my printer which is named POS80
Is there not a simple command for windows in the command prompt to say Print C:\printme.txt to POS80?
It should be noted that POS80 is also the default printer so a command that does not include the printer name but just sends to the default printer would be acceptable too.
Your mileage can vary using the legacy command Print
It MAY work if you have a line printer set to LPT1 and worth trying
Print C:\printme.txt "POS80" However I expect you are getting the error message "Unable to initialize device PRN" that is not unusual as PRN was traditionally LPT1.
Later you say its USB connected. which means its serial (old Com ports) whereas Line Printer (old LPT ports) were parallel hence the potential needs for fettling, but in windows you can use the port name for the printer and that resolves ports issue (files can become ports or vice versa) thus no real problem.
Now you could try messing with printer port redirections to get around that but it would likely mess up other application printing. Thus by far the simplest is make the printer the default one which is what you have.
To avoid the Save Output File As dialog when adding a print job to the default queue, ensure that your default printer isn't Microsoft XPS Document Writer, Microsoft Print to PDF, or other print-to-file options.
So what is Windows 10 doing when you right click print? Generally it fires up the associated FTA (File Type Application) which for .txt (or similar chosen) is NotePad.
Thus the simplest way to command line print plain text is
NotePad /pt C:\printme.txt "POS80"
NotePad settings can be changed in the registry before and after you print, via the command line, even skewing letters (fun to prank colleagues if you use 1 degree off kilter), however you cannot set line spacing or add graphics, for those you need to step up to WordPad which will accept docx, rtf, odt and most simple text file types.
Several other file types can also be printed in a similar way such as graphics images, using mspaint.
Later you say you are sending html as text and want graphic output not textual.
So the x problem is the files are not plain.txt they are plain.htm so need translation from html by graphic conversion (rendering) to pass through a printer language converter (printer driver) That's a totally different question but the answer is still much the same.
Traditionally you would simply use
rundll32.exe mshtml.dll,PrintHTML "C:\printme.txt"
But security exploits have made that simplicity more of a challenge thus
best to run it like this.
cd /D C:\Windows\System32 & rundll32.exe mshtml.dll,PrintHTML "C:\printme.txt"
And Microsoft Current Policy is "User confirmation is needed to print an HTML page through MSHTML.DLL." thus you need to hit print using sendkeys.
If your preference is FireFox rendering, from the command line you needed to install an extension, however with tightened security in windows 10, I dont know if that's still possible.
If you wish to print xml or html graphically in windows 10+ you can ask Edge --headless to print those for you to PDF, either as screen shot or rendered text, silently without enforced html confirmation ! And again you can print html automatically by using sendkeys to replace the user.
However printing PDF from the command line is where the real fun begins.
It is possible if the PDF is the correct type prepared for the printer (even a simple thermal or inkjet) then an old school copy /b file.pdf "printer" may work but dont send a big file to test, just a tiny Hello World!, or your carbon neutrality is instantly wiped out by reams of paper with one or two letters each.
My dirt cheap HP accepts files that can be viewed as PDF that start textually like this i.e. which have the PCLm 1 comment.
%PDF-1.7
%PCLm 1.0%
223 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/XObject <<
/Image0 3 0 R
/Image1 4 0 R
For most POS printers a PDF either needs to be processed in middleware or usually top end firmware such as onboard Direct PDF
Thus we come back to using html bitmap and text directives that will either need a print driver or be programmed to a port or file for later copy /b to device.
As you no doubt know Microsoft have not made it simple to print file.html default in fact the opposite resulting in many third part apps for win xp-win 11 such as https://www.bersoft.com/htmlprint/index.htm#overview amongst many other options.
Background:
Sometime I have the need to monitor the change of a value in a certain program.
My solution is to use a batch file to capture the part of the screen with where the value is shown with Minicap and then use Tesseract to convert the value to plain text. However this script would not work so good if I would need to monitor value change every second for several hours.
Current solution (simplified example):
minicap.exe -captureregion 800 600 850 620 -save C:\file.png -exit -escapequit
tesseract.exe C:\file.png out.txt
Question:
What I would like is some simple way to OCR a value directly from the screen to use in the batch file, perhaps buffer several values before appending them to a csv file. I would prefer to do this without the need to install python or write compiled software
(Posted on behalf of the question author, to move the solution to the answer space).
I found that I could use Capture2Text. The following command takes the on screen text and prints it to stdout:
Capture2Text_CLI.exe --screen-rect "800 600 850 620"
This way it's possible to run the command, check if the value is changed, and if so, append it to a log file together with a timestamp.
My program loads a lot of images, but i have a problem with 1 image that used the print-screen button to copy it, from a game, however it is bmp, like all the rest. Whenever i run the program, it says project1.exe raised exception class Ereaderror with message 'stream read error' process stopped....
The code is this:
procedure TForm1.FormCreate(Sender: TObject);
var path, destination:string;
begin
path:=paramstr(0);
destination:=extractfilepath(path)+'Leagueoflegendsdesktop.bmp';
image1.Picture.LoadFromFile(destination);
end;
Which is correct. What do you suggest me?
The only explanation is that the file is not a valid Windows bitmap (maybe the file is truncated). Or perhaps the file uses some esoteric format not supported by Delphi. Is it using run-length encoding, for example.
If the file did not exist you'd get a different error, one that indicated that no such file exists. So, the file exists but cannot be loaded. Ergo, it's not a Windows bitmap.
Step 1 to diagnose this is to look at the format of the file. Load up the bitmap file header and check that the values make sense. Probably the easiest way to do this is to step through the VCL code when running your program under the debugger. Enable the Debug DCUs option so that you can do that. Set a breakpoint in TBitmap.ReadStream in the Graphics unit and take it from there.
Having said all that, it may just be easier for you to avoid trying to debug the problem at all. If you can load the image into an image editor, simply save a new copy of the image in a format that will be read by Delphi. For example a plain vanilla Windows bitmap, or, even better, a PNG file which will admit compression.
I have several large PDF reports (>500 pages) with grid lines and background shading overlay that I converted from postscript using GhostScript's ps2pdf in a batch process. The PDFs that get created look perfect in the Adobe Reader.
However, when I go to print the PDF from Adobe Reader I get about 4-5 ppm from our Dell laser printer with long, 10+ second pauses between each page. The same report PDF generated from another proprietary process (not GhostScript) yeilds a fast 25+ ppm on the same printer.
The PDF file sizes on both are nearly the same at around 1.5 MB each, but when I print both versions of the PDF to file (i.e. postscript), the GhostScript generated PDF postscript output is about 5 times larger than that of the other (2.7 mil lines vs 675K) or 48 MB vs 9 MB. Looking at the GhostScript output, I see that the background pattern for the grid lines/shading (referenced by "/PatternType1" tag) is defined many thousands of times throughout the file, where it is only defined once in the other PDF output. I believe this constant re-defining of the background pattern is what is bogging down the printer.
Is there a switch/setting to force GhostScript to only define a pattern/image only once? I've tried using the -r and -dPdfsettings=/print switches with no relief.
Patterns (and indeed images) and many other constructs should only be emitted once, you don't need to do anything to have this happen.
Forms, however, do not get reused, and its possible that this is the source of your actual problem. As Kurt Pfiefle says above its not possible to tell without seeing a file which causes the problem.
You could raise a bug report at http://bubgs.ghostscript.com which will give you the opportunity to attach a file. If you do this please do NOT attach a > 500 page file, it would be appreciated if you would try to find the time to create a smaller file which shows the same kind of size inflation.
Without seeing the PostScript file I can't make any suggestions at all.
I've looked at the source PostScript now, and as suspected the problem is indeed the use of a form. This is a comparatively unusual area of PostScript, and its even more unusual to see it actually being used properly.
Because its rare usage, we haven't any impetus to implement the feature to preserve forms in the output PDF, and this is what results in the large PDF. The way the pattern is defined inside the form doesn't help either. You could try defining the pattern separately, at least that way pdfwrite might be able to detect the multiple pattern usage and only emit it once (the pattern contains an imagemask so this may be worthwhile).
This construction:
GS C20 setpattern 384 151 32 1024 RF GR
GS C20 setpattern 384 1175 32 1024 RF GR
is inefficient, you keep re-instantiating the pattern, which is expensive, this:
GS C20 setpattern
384 151 32 1024 RF
384 1175 32 1024 RF
GR
is more efficient
In any event, there's nothing you can do with pdfwrite to really reduce this problem.
'[...] when I print both versions of the PDF to file (i.e. postscript), the GhostScript generated PDF postscript output is about 5 times larger than that of the other (2.7 mil lines vs 675K) or 48 MB vs 9 MB.'
Which version of Ghostscript do you use? (Try gs -v or gswin32c.exe -v or gswin64c.exe -v to find out.)
How exactly do you 'print to file' the PDFs? (Which OS platform, which application, which kind of settings?)
Also, ps2pdf may not be your best option for the batch process. It's a small shell/batch script anyway, which internally calls a Ghostscript command.
Using Ghostscript directly will give you much more control over the result (though its commandline 'usability' is rather inconvenient and awkward -- that's why tools like ps2pdf are so popular...).
Lastly, without direct access to one of your PS input samples for testing (as well as the PDF generated by the proprietary converter) it will not be easy to come up with good suggestions.
I can't copy the information in softice to disk/file. I am aware of IceExt but everytime I execute the command to dump the screen to disk(such as "!DumpScreen \??\c:\test.raw")it crashes my system entirely. When I try to copy with the mouse, the cursor only makes it possible to copy one line. I have already read through the softice manual. I just need a way to retrieve data from softice. Any help would be appreciated. I am using xp professional.
Turns out that no addons are required to accomplish this. Using the command "u cs:eip L 1000" from softice. You will then see a duplicate of the data within softice's screen displayed in the command window.
The u 'unassembles' code at the address cs:eip (the current EIP), the L specifies a length of 1000 bytes, you might need more than 1000 so adjust accordingly. Once you've done this you should exit SoftICE and select File / Save SoftICE History As from Symbol Loader, with any luck the resulting file will contain your code dump.You may have to to use F10 to step through inorder to get the data in softice's history log.
Using this method, I successfully dumped the entire code window and data window. The main drawback to this method is that the resulting text will contain alot of noise(unnecessary data). I haven't figured out how to get around this. This is a adaptation of woodmann's method.