PDF to PNG using Ghost Script - crop to top third of page - png

I am trying to convert a PDF file to an image, and in the process crop to the first third(approx) of top of the first page.
This command gives me the whole page and changing the -g option crops toward the bottom left corner if I make the values smaller.
for %%x in (*) do "......\program\gs\gs9.23\bin\gswin32c.exe" -g2500x3300 -dFIXEDMEDIA -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r300x300 -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -SOutputFile="%%~nx.png" "%%~nx.pdf"
I want the smaller image so that OCR on the image is then faster, and most letters/docs I am dealing with have the information I am after in the top third.

The origin (0, 0) of the PostScript page (and the PDF page) is at the lower left. So by reducing the media size you make the uppermost portion of the content lie off the media and therefore its not rendered.
So what you need to do is reduce the size of the media (which you have done) **and* translate the origin so that the top of the content lies on the media.
Try adding -c "<< /BeginPage {-300 0 translate} >> setpagedevice" -f before the input PDF file. That should translate the origin to be 1 inch below the bottom of the media at 300 dpi which should make 1 inch more of the top of the page, and 1 inch less of the bottom of the page render.
Obviously since I don't know how large your content is, I can't give you an exact answer.

Related

Bigger file for narrower screenshot of web page?

I was trying to archive a web page, and made a screenshot of it which I then saved as heic, but I ran into this weird phenomenon: When I tried a narrower window the image became bigger, and apparently the original png too?
This is my screenshot for a full-sized browser window:
PNG 2,1 MB 6016×3336 HEIC 796 KB 6016×3336.
This is my screenshot for a narrower browser window
PNG 2,4 MB 1532×3408 HEIC 1,1 MB 1532×3408.
How does this make sense? I would love to know.
Web page from the screenshot
PNG encoders filter your image on a line-by-line before compressing them. They can look at a line of pixels and determine if each pixel is heavily based on the line above, or the previous pixel to the left or some more complicated combination of these. They then choose the optimal filter for the line and store it in the output file for the decoder.
As a result, repetitive lines which are largely identical to the line above, or unchanging across the width of the image, are compressed extremely well.
That's what you have in your wider image - there are vast areas of pure white on left and right and they compress very well so although the pixel dimensions are larger, the compression is more effective.

How to get rid of the vertical line in SAP Crystal report

​I am not sure how to get rid of this vertical line? is it in the margin?
and when I click the Design Tab, the page is not in full screen
The line indicates a page break when printing. Your report is designed to print on paper that is either A2 or ANSI C in size, likely with landscape orientation.
First you need to determine what size paper this report is intended to use when printing. Then go to File > Page Setup in your Crystal Report designer and configure the Printer Options and Page Options. Printer Options should either be set to No Printer, or the printer that can print the paper size you plan to use. Page Options will define the paper size, orientation and margins.
If you plan to use a paper size that is smaller than 22 inches in width, you will need to reduce the size of the objects in your report to fit the size of the paper or allow it to span multiple pages.

Advanced image scaling in JasperReports

I need to include many images of unknown origin in a report. I have no idea what the images might be: portrait or landscape fotos, large or small, or even something with an atypical shape, like a 400x80 logo.
I'd like to scale down images with the following rule: proportionally downscale until the larger side is 200. And resulting image shouldn't take more space than needed (i.e. 1000x600 should be downscaled to 200x120, not to 200x200), so that there are no unneeded blank margins around non-square images.
Is what I need possible with JasperReports?
EDIT:
To clarify: "real size" mode is almost what I need. However, I don't see a way to limit height of resulting image. As a result, if the image I want to print is a portrait foto (or has even larger height compared to width), generated PDF looks ugly; in this case I would prefer to somehow downscale it to a smaller width.
I solved the Problem of resizing images of various sizes to a fixed size with "RetainShape" by writing an ImageResizer, based on the idea of the ImageTransformer from https://stackoverflow.com/a/39320863/8957103 , using https://github.com/rkalla/imgscalr for scaling the image.

iTextSharp - Scaling and positioning page

I am reading an existing PDF file into a new PDF file, and scaling the first page based on the page dimensions. The page gets scaled to 90-95% in order to make room for some footer text. The problem I have is that the resulting scaled page leaves white space at the top of the page, NOT the bottom. Is there a way to control the results so that they start in the top left of the page and not the bottom left?
Here's my code that adds the scaled page:
cb.AddTemplate(importedPage, scaleSize, 0, 0, scaleSize, 5, 20);
Object "cb" is a PDFContentByte class, while "scaleSize" is a float set to .9 or .95. The scaling works great, but the positioning is an issue. Thanks!
figured it out: the value of "20" for the final parameter was incorrect. A value of 100 is far more suitable for my purposes, and now I understand far better the coordinate system in PDF/iText. For those interested, the 0, 0 point for a PDF document is the lower left corner.

Libreoffice Draw Export Resolution makes no sense

I am attempting to make a very simple label using Libreoffice Draw v 4.0.2.2. The label has not much more to it than regularly spaced lines of centered text
This image will be printed, and I have a fixed size/ppi requirement to ensure appropriate print quality.
I set the page size to my specs, and layout the text as I desire. The print shop takes several image formats including .tiff and .png. When I export the image, a dialog pops up that asks for the image size/ resolution. The given ppi is very low (~40) and I require a minimum of 180ppi. When I enter this, the image size adjusts itself and results in an image that is far too small.
The only solution that appears to be viable is to explode the page size and the drawing text size so it gets shrunk upon export. This is a very imprecise and illogical feature (bug?) of the program that I really wish is a result of my ignorance.
I found a thread in the mailing list which describes this issue exactly. The only answer that is given is essentially "yes, this is ridiculous and doesn't help anybody".
Can anyone give some advice to this? Or at least shed some light on who might need this "feature"?
There is something off about the Export tool of LibreOffice in general. It has been years since it is broken. Taking a screenshot is an alternative, but obviously you cannot control the resolution.
So, a better work around is exporting to SVG, and then convert the SVG to PNG with Inkscape. Once downloaded, convert the file with the following command:
inkscape -z -e out.png -w 1024 in.svg
If you are in Windows (x64), you will need to indicate the full path:
"C:/Program Files/Inkscape/inkscape.exe" -z -e out.png -w 1024 in.svg
If you install the 32 bit version, this should work:
"C:\Program Files (x86)/Inkscape/inkscape.exe" -z -e out.png -w 1024 in.svg
This can be done from inside Libre Office, there is no need to use any external tool. The Export dialog is very confusing, yes; you have to realize that both size and resolution can be set independently.
Select File -> Export -> choose the desired format. The export dialog should appear.
TAKE NOTE of Width and Height. Set the desired resolution; notice how Width and Height change (?). Don't worry, restore Width and Height to your saved values. And that's it. You get a high resolution image with the desired size and DPI.
Libre Draw (the one I'm using anyway) is a vector drawing app - have you asked the print shop if they can use vector formats like eps, pdf? Most should be able to in my experience. Then resolution becomes irrelevant.
-Terry