PostScript, can't see visual output with ghostscript - ghostscript

%!
/Times-Roman 12 selectfont
100 100 moveto
(Hello) show
How can I take the output as PDF and EPS
formatted file.

Your question really needs some editing, its not clear (to me anyway) what your problem is.
You say 'PostScript, can't see visual output with Ghostscript' as the title, and then want to know about 'taking the output'. So which is it ? A problem viewing a PostScript file when using Ghostscript ? Or a problem with the output ?
You can use the eps2write device to get EPS output and the pdfwrite device to get PDF output, as per the documentation. Neither has 'visual output'.

Related

Ghostscript - Indentation of postscript code

Is there an option for to me to ask Ghostscript to indent the Postscript it creates?
Everything starts at the beginning of a line and I find it difficult to follow.
Alternatively, I am using Emacs and ps-mode.
If anyone know how to indent code in this mode I would appreciate a tip (apologize because this may not be relevant to this StackExchange)
No, there is no option for indenting the output.
PostScript is pretty much regarded as a write-only language anyway, and the output of ps2write (which is what I assume you are using though you don't say) is particularly difficult since it fundamentally outputs PDF syntax with a PostScript program on the front to parse it into PostScript operations.
Why do you want to read it ?
[EDIT]
You can always edit your question, you don't need to post a new answer.
I'm afraid what you want to do isn't as simple as you might think.
It might be possible for this use case if the PDF files you receive are always created the same way, but there are significant problems.
The font you use as a substitute for the missing font must be encoded the same way. Say for example the font in the PDF file is encoded so that 0x41 is 'A', you need to make sure that the replacement font is also encoded so that 0x41 is an 'A'. So just the findfont, scalefont, setfont sequence is not always going to be sufficient, sometimes you will need to re-encode the font.
CIDFonts will be a major stumbling block. Firstly because ps2write simply doesn't emit CIDFonts at all. These were not part of level 2 PostScript. As a result all text in a CIDFont will be embedded as bitmaps. If your original file doesn't contain the CIDFont then you'll get the fallback CIDFont bitmapped.
Secondly CIDFonts can use multiple-byte character codes, of variable length. You can't simply replace a CIDFont with a Font, it just won't work.
The best solution, obviously, is to have the PDF files created with the fonts required embedded. This is best practice. If you can't get that, then I'd suggest that rather than trying to hand edit PostScript, you use the fontmap.GS and cidfmap files which Ghostscript uses to find font.
Ghostscript already has a load of code to do font substitution automatically, using both Fonts and CIDFonts as substitutes, and it does all the hard work of re-encoding the fonts or building CMaps as required. If you are on Windows much of this may already be done for you, when you install Ghostscript it will ask if you want to create font mappings. If you said yes then it will
Add the font substitutions you want to use in those files (they have comments explaining the layout) and then use the pdfwrite device to make a new PDF file. Set EmbedAllFonts to true (you may need to add a AlwayEmbed font array as well, listing the fonts specifically) and SubsetFonts to false.
That should create a new PDF file where the missing fonts have been replaced by your defined substitutes, those substitutes will have been embedded in the new PDF file and they have will not been subset (Acrobat will generally refuse to edit text in a subset font).
The switches I mentioned above are standard Adobe Distiller parameters, but they are documented for pdfwrite here. There's some documentation on adding fonts here and here and specifically for CIDFonts here.
Basically I'd suggest you define your substitutions and let Ghostscript do the work for you.
This is not an answer to the problem but rather an answer to KenS's question about "Why do you want to read it?"
I tried to put it in the comment box but it was too long.
I am a retired engineer with a strong programming background.
I would like to read and understand the postscript code for the reason shown below.
I play duplicate bridge as a hobby. I recieve a PDF file of what is know as a convention card (a single page document of bridge agreements).
Frequently I would like to edit these files.
When I open with Adobe Illustrator I have to spend a significant amount of time replacing fonts that are not on my system with fonts that I do have.
I can take the PDF and export it as a postscript file using Ghostscript.
I was going to write a little program to replace the embedded fonts with the fonts that I use to replace them.
I was going to leave the postscript file unaltered and insert things like
/HelveticaMonospacedPro-RG findfont
12 scalefont setfont
just above where the text is written.
I was planning on using the fonts that I have on my system (e.g., HelveticaMonospacedPro-RG).

R Studio font outputs

I'd like to understand how to change the text that is output in the source pane of R Studio. For instance, when I issue the command data(), to view the built in data sets, the output is displayed in what might be Time New Roman and it is quite small and not nicely formatted. I've been able to successfully change the console text size and type with the Global Options, or Preferences selections.
In addition, my output code chunks in R Markdown documents are likewise in possibly New Times Roman, not Monaco, or Courier, or whatever font I change to with the Preferences or Options. I'd like to have the code chunk outputs look better formatted, and in the font of my choice. I also have no problem manipulating the R Markdown font - it is output of the code chunks that is in the same font as the output at my source pane. I've included a screen shot. Any suggestions?
font differences
Appears that this might have been an R Studio version issue. I just updated to 1.2.5019 and all the fonts are the same now - both in the console window and in R Markdown chunk outputs.

How to print halftone from Ghostscript

I have a PostScript file with image and text. I want to print it to a laser printer so that the images print in a halftone round pattern.
I am trying to print it from the command line. I would prefer a PDF output first and then I'll print to the laser printer.
I have an HP Laserjet P2015 printer installed in Windows 10.
gswin64c.exe -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf test.ps -c "<< /HalftoneType 1 /Frequency 37 /Angle 45 /SpotFunction {180 mul cos exch 180 mul cos add 2 div} >> sethalftone"
The PDF file is generated. However, the images does not appear to be in Round Halftone format. I see no change in the image.
This is the original Image
I want the printout to look like this: Required output
For some reason the output is the same as the original.
pdfwrite doesn't create monochrome output, so no, the output won't be halftoned. The whole point of the pdfwrite device is to maintain the output as close in quality as possible to the input.
There is no way to get monochrome output from pdfwrite unless the monochrome is in the input.
If you instead use a monochrome output device (e.g., tiffg3 or tiffg4) you should see a difference, unless the input file (which you haven't supplied) also sets a screen, in which case the last one encountered will take effect. That is, if the PostScript input file specifies a halftone screen, that's the one that will get used.
What you are asking for is what I might generally describe as a hard problem, probably much harder than you expect.
Your best bet is to send the PostScript directly to the printer, since it supports PostScript.
Problem 1; your PostScript file may already contain a halftone in it which overrides the one you want to use. You can usually prevent that by redefining the sethalftone and setscreen operators:
/sethalftone {pop} bind def
/setscreen {pop pop pop} bind def
You do that after you'[ve defined your own halftone, obviously. Or you can just edit the PostScript file and remove the halftone definition, its usually not that hard to find.
Problem 2 is that printer manufacturers sometimes 'tweak' the interpreter to always use their preferred halftone and prevent you overriding it in PostScript. The only way to find out if that's happening is to try a quick test; print a simple image with the default screen, then set a really coarse screen, say 10 lpi and print the same image. If there's no difference then you know that's not a viable option. If there is, then you can just set the screen you want.
Now, if the printer won't let you change the halftone then the only solution is to render the PostScript to an image using Ghostscript (which will let you change the halftone) and then send the resulting image to the printer. You will need to use a 1 bpp device, something like tiffg3 or tiffg4 should work fine.
The problem here is that you need to ensure that the image fits on the media of the printer, because if it doesn't then the likelihood is that the printer will slightly scale down the image so that it does fit, thereby squashing the halftone cells.
Even more subtly, the printable area of the media in the printer may not be the same as the size of the media. Paper handling can mean that there are some areas of the paper that can't be printed on, and the variability in the feeding of the paper can mean that the printer will refuse to print right to the edges anyway. Because if it did, and there was, say, a 1 mm deviation in the paper handling, then 1 mm of the edge would 'fall off' and there would be a 1 mm white gap at the other edge...

Question about retaining mixed plex when converting from PS to PDF

Good day,
We print Postscript files directly on industrial Xerox printers.
One client's Postscript files were getting garbled due to a font issue that I was unable to track down, so I used Adobe's Distiller to convert from PS to PDF. The same font issues turned up in the PDFs that were generated from Distiller. No amount of option tweaking helped me out, and find/replace font operations using the Callas pdfToolbox didn't work out for me.
So, I downloaded Ghostscript and spent an entertaining hour remembering how DOS worked. I was eventually able to convert several PS files into flawless-looking PDFs by going to the Ghostscript directory and doing this:
gswin64 -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=myoutputfilename.pdf myinputfilename.ps
But, I didn't think things all the way through because now I'm faced with the problem of mixed-plex. Some of the documents in the file are one-page documents and some are two-page documents, which should be printed duplex.
PS handles all of this for us when we put it on one of the Xerox printers. PDF, of course, does not. I can only specify simplex or duplex on the printer - so it's either one or the other, which doesn't work for a PDF with both.
Is there any clean, (or dirty), way to get around this? I was thinking of somehow instructing Ghostscript to insert blank pages after every simplex page of a PS file, and then just printing the entire PDF duplex, but have no idea how I would begin to do this.
Any assistance greatly appreciated. :)
It 'sounds like' you have concatenated several PostScript program together here, is that the case ?
This isn't really a great idea, it can lead to incorrect output, I wonder if this is the source of your problem with Distiller and your printer.
Have you tried producing PostScript instead of PDF, by using the ps2write device instead of pdfwrite ? While this won't carry any of the device-specific controls (such as /Duplex), you can easily put them back. In fact recent versions of the device will allow you to specify code to be inserted at document and/or page level.

Hooks in ghostscript

Anyone know the right places to hook into ghostscript, so that when interpreting a ps file, I can get logs of all calls of the form:
draw_character(float x, float y, string font_name, int char_id); ?
Basically I want to take a postscript file, and get a list of where all characters are drawn to the screen.
Thanks!
I'm not sure if this answer is going to help you... but do you know how to harvest debugging information from Ghostscript on the commandline? Simply add "-dDEBUG" to the commandline and it will spit out lots of additional info. To get debugging info from only specific topics, you have these options:
-dCCFONTDEBUG Compiled-in Fonts
-dCFFDEBUG CFF Fonts
-dCMAPDEBUG CMAP
-dDOCIEDEBUG CIE color
-dEPSDEBUG EPS handling
-dFAPIDEBUG Font API
-dINITDEBUG Initialization
-dPDFDEBUG PDF Interpreter
-dPDFOPTDEBUG PDF Optimizer (Linearizer)
-dPDFWRDEBUG PDF Writer
-dSETPDDEBUG setpagedevice
-dSTRESDEBUG Static GS Resources
-dTTFDEBUG TTF Fonts
-dVGIFDEBUG ViewGIF
-dVJPGDEBUG ViewJPEG
Possibly, a PostScript programmer guru could write a little PostScript program that could do what you want by re-defining one of the operators (showglyph?) in a way that it prints out the info you want instead of (or before) drawing each individual character and run that against your target PS file.
Maybe you should ask your question in comp.text.pdf or in comp.lang.postscript ?

Resources