Originally Posted by dgvirtual
Thanks for explanation. Native mode does not work here, since the file is scanned. It might well be jpeg-based... Now, if the original pdf is composed of jpeg images, would the k2pdfopt convert it to a png based pdf in any step of the three below?
But then I tried to repeat the steps by which I got the pdf with quality loss and I got stuck
I do not know how I succeeded the first time...
Could you tell me what is it that goes wrong here? I am attaching the original image... Attachment 103604
It took a little tinkering, but the commands I used are:
k2pdfopt -ui- -mode copy -cmax -1 -g 1 -bpc 8 -grid 2x1x0 -n- -w 1t -h 1t -dr 2 page01.pdf -o temp.pdf
k2pdfopt -ui- -as -ml 0.4 -mr 0.4 -w 758 -h 942 -odpi 213 -om 0.04 temp.pdf -o out.pdf
The 'e-14' issue is a bug in my code. Apparently scientific notation is not allowed for move commands in PDF files, and since I use %g as a formatter and your document has a /Rotate 90 directive in the page objects, there end up being some very small scientifically formatted values in the move commands (e.g. 1.00234e-14), which aren't allowed in PDF. So I'll fix that, but for now I've provided a work around. Note that if k2pdfopt didn't have this bug, native mode would have worked fine in the first command--it doesn't matter whether the source document is scanned or not. Native mode conversion is the best way to preserve the fidelity of the original file.
Anyway, because of the bug, I had to use bitmap mode in the first conversion command. And yes, k2pdfopt, in bitmap mode, will effectively convert the scanned JPEG images to PNG (4-bit grayscale by default).
Here are what the less obvious options do:
sets the output to be a copy of the input, with the output in bitmap mode.
-cmax -1 -g 1 -bpc 8
preserves the source contrast, gamma, bits per pixel (none of this would have been necessary if I could have done a native mode conversion) so that you don't get dithering artifacts.
breaks each page into 2 output pages (2 x 1 grid, no overlap)
turns off native mode (-grid
turns it on, so you have to turn it back off--again, not necessary if native mode had worked)
-w 1t -h 1t
sets the output page size to mirror the gridded pieces of the source
doubles the output resolution so that we don't lose fidelity (not necessary if native mode had worked)
The other options are pretty straightforward and can be reviewed in my command-line options page