Scale PostScript Image via GhostScript - ghostscript

I have a postscript image, which I wanted to scale down to 84x84 pixels.
I tried the following line ( and different ones, but this one is the furthest I got ):
gs -sOutputFile=somefile.bmp -sDEVICE=bmpgray -q -g84x84 -dDEVICEWIDTH=84 -dDEVICEHEIGHT=84 -dPDFFitPage frames/frame_00000055.ps
This did not achieve what I wanted (all it does is showing a white image).

You have several problems with that command line. There is no command line switch -dDEVICEHEIGHT or -dDEVICEWIDTH, the relevant switches are -dDEVICEHEIGHTPOINTS and -dDEVICEWIDTHPOINTS. You should never attempt to set the media size in two different ways anwyay, it will only lead to problems of some kind. You've specified -dPDFFitPage, but you appear to have supplied a PostScript program as the input.
Unsurprisingly, the PDFFitPage parameter does not scale PostScript.
When you are having problems of any kind, its best not to mute the application using -q (for quiet), in case its trying to tell you something.
Try using -dFitPage instead of -dPDFFitPage. If that still doesn't work, then I'll need to see your PostScript program.
84x84 pixels is tiny, its entirely conceivable that the result of downscaling a PostScript program could result in no pixel centers being touched, in which case the output will indeed be blank.

Related

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.

Prevent ugly kerning when using DrawText

I use simple GDI DrawText to output blocks of text to a printer.
The font used in the sample is Segoe UI. But you can use Arial or others too. It doesn't matter.
The algorithm for large text blocks is simple. DrawText is called with DT_CALCRECT with a kind of binary search for the length to get the largest possible text to print. Than DrawText is called without DT_CALCRECT to print the block.
Simple one line text column text is written with one call to DrawText with the given coordinates of the rectangle.
The result is real strange and can be seen in this sample PDF.
Just look on the first line after the header. You can see the text "Test, Test" and you can see the strange kerning here perfectly. The kerning os sometimes so bad, that you can't even read the words.
How to get around this? Is it a problem with the used printer? Is it a problem with DrawText?
The distance between some chars in a word seem to be random in some case. Some spacing are wide other to narrow. The letter combination looks strange unreadable and ugly.
I tried different fonts and printers but the problem just varies but it is always present.
I know about ExTextOut and the capabilities to define the distance/kerning between all chars, but frankly I don't want to care about this. I just want that DrawText behaves on the printer like on the screen. The stuff works on the screen perfectly.
Added 2018-08-23 08:49 GMT+2*
To the code (it is a complex printing engine).
1.Fonts to print are created simply with CFont::CreatePointFont, so the LOGFONT structure is cleared to zero and no additional flags are used except point and face.
2.The mapping mode is MM_ANISOTROPIC. To scale what is seen on the screen and what is to be printed I just use the size of a komparable object (textblock) on the printer and the same size on the screen. The real values for the sample printout to the Microsoft PDF Printer are as follows, the real way I calculate them is not of interest:
m_pDC->SetMapMode(MM_ANISOTROPIC);
m_pDC->SetViewportExt(2363,100);
m_pDC->SetWindowExt(355,13);
This has the effect that the height of a line in LPs is 13, the average character width in LPs is 6...

How to change font size with shell script?

Is there any way to change the size of the text in shell script ?
I mean dynamically during the execution .
For example I have an image drawn with ASCII code and i want to reduce the size of text .
Now when echo or cat the image it will be shown as the command prompt actual size (the actual font size) .
A couple of comments note that font size/style are under the control of the terminal emulator, and that xterm (and a few others) support escape sequences to change these.
However - almost all terminal emulators (all that you would be likely to encounter) rely upon keeping the characters in a nice row/column grid. All of the characters have the "same" size. If you change the size of the font in xterm, all of the characters on the screen change to the same size. So there is no way to (as OP asks) to reduce the font-size temporarily, e.g., while using ASCII graphics to draw a picture using aalib, etc.
If you want to do something like that, the easiest way to do it is to have the script run its graphics in a separate window, e.g., by splitting it up into one part that starts the window and another script to draw the graphics.
For an alternate via of terminals and fonts, there is always something like 9term (no rows, no columns, no vi).

PostScript on a Dymo labelwriter

I'm trying to print a postscript file to a Dymo LabelWriter (tried a LabelWriter 450 and LabelWriter 330-Turbo), i'm getting it trough ok, but the margin seems to be way to high, 1/3 of the label isn't printable (see pic, the black square is supposed to cover the entire label over the width).
The label is 89mm on 39mm (so 252pt x 123pt)
I'm using a boundig box of 8 8 252 123 and the page orientation is set to portrait.
I even tested it with an eps-file generated from Gimp, it leaves the same area blank.
anyone has an idea why it isn't printing correctly?
EDIT:
The file can be viewed here : http://pastebin.com/c7YC5ftb
The command I use to print it on a Dymo LabelWriter is:
C:\ps\gswin32c.exe -sDEVICE=mswinpr2 -dNoCancel -dNOPAUSE -dSAFER -sOutputFile="%%printer%%DYMO LabelWriter 450" -q "C:\ps\dymo.ps" -c quit
Not without seeing the PostScript file, no. I don't see from the Dymo web site that the printer accepts PostScript input, so how are you sending the PostScript file to it ?
Added in response to edits in the question.
Well its not absolutely clear to me what you expect this to look like.
Your original comment refers to a black square, but the PostScript doesn't contain a black square, it draws a rectangle with an aspect ratio of 20:1. You have set the media up to be wider than it is long (252,123) but you then use the Orientation to rotate the content by 270 degrees. Its true this is portrait, but upside down. If you want portrait why not just set the media to be portrait ?
Simply put the origin is the corner directly above your thumb in the photograph, and I think the long and short sides of the print are reversed with respect to the actual label.
Note that the BoundingBox comment is a comment and is ignored by the PostScript interpreter so changing it has no effect.
Perhaps if you could explain what you are trying to achieve ?
Problem is solved, the printer wasn't set to accept this type of labels
If you ever have this problem go the advanced settings of your printer driver and set the label.

Resources