Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a PDF which will always opens at zoom level 100%?

I am running into an issue with PNG to PDF conversion.

Actually I have big PNG files not in size but in contents.

In PDF conversion it creates a big PDF files. I don't have any issue with its quality, but whenever I try to open this PDF in PDF viewer, it opens in "Fit to Page" mode.

So, I can't see the created PDF in the initial view, but I need to zoom it up to 100%.

My question is: can I create a PDF which will always open at zoom 100% ?

like image 948
Abhijit Muke Avatar asked Jan 28 '15 10:01

Abhijit Muke


People also ask

How do I change the zoom percentage on a PDF?

One can see this setting (using Adobe Acrobat) by “right-clicking” on a single bookmark and selecting “Properties”. Click on the “Actions” tab and you can then see the customized/specific zoom level for that specific bookmark. Clicking the “Edit” button allows the PDF document creator to select a different zoom level.

How do I save a PDF with 200% zoom?

1 Answer. With Acrobat you need to open the 'Preferences" for the PDF and use the "Initial View" tab to set the "Magnification" for the PDF. Since that value is not listed, you can type it in as 68.3 and save the PDF.


1 Answers

You can possibly achieve what you want with the help of Ghostscript.

Ghostscript supports to insert PostScript snippets into its command line parameters via -c "...[PostScript code here]...".

PostScript has a special operator called pdfmark. This operator is not understood by most PostScript interpreters, but is understood by Acrobat Distiller and (for most of its parameters) also by Ghostscript when generating PDFs.

So you could try to insert

-c "[ /PageMode /UseNone /Page 1 /View [/XYZ null null 1] \
      /PageLayout /SinglePage /DOCVIEW pdfmark"

into a PDF->PDF conversion Ghostscript command line.

Please take note about various basic things concerning this snippet:

  1. The contents of the command line snippet appears to be 'unbalanced' regarding the [ and ] operators/keywords. But it is not! The initial [ is balanced by the final pdfmark keyword. (Don't ask -- I did not define this syntax...)

  2. The 'inner' [ ... ] brackets delimit an array representing the page /View settings you desire.

  3. Not all PDF viewers do respect the view settings embedded in the PDF file (Acrobat software does!).

  4. Most PDF viewers allow users to override the view settings embedded in PDF files (Acrobat software also does this). That is, you can tell your viewer to never respect any settings from the PDF files it opens, but f.e. to always open it with "fit to width".

Some specific things about this snippet:

  1. The page mode /UseNone means: the document displays without bookmarks or thumbnails. It could be replaced by
    • /UseOutlines (to display bookmarks also, not just the pages)
    • /UseThumbs (to display thumbnail images of the pages, not just the pages
    • /FullScreen (to open document in full screen mode)
  2. The array for the view mode constructed as [/XYZ <left> <top> <zoom>] means: The zoom factor is 1 (=100%), the left distance from the page origin is the special 'null' value, which means to keep the previously user-set value; the top distance from the page origin is also 'null'. This array could be replaced by
    • /Fit (to adapt the page to the current window size)
    • /FitB (to adapt the visible page content to the current window size)
    • /FitH <top>' (to adapt the page width to the current window width);` indicates the required distance from page origin to upper edge of window.
    • ...plus several others I cannot remember right now.

So to change the settings of an existing PDF file, you could do the following:

gs                                                              \
  -o out.pdf                                                    \
  -sDEVICE=pdfwrite                                             \
  -c "[ /PageMode /UseNone /Page 1 /View [ /XYZ null null 1 ] " \
  -c "  /PageLayout /SinglePage /DOCVIEW pdfmark"               \
  -f in.pdf

To check if the Ghostscript command worked, open the PDF in a text editor which is capable of handling binary files. Search for the /View or the /PageMode keywords and check if they are there, inserted as values into the PDF root object.

If it worked, check if your PDF viewer honors the settings. If it doesn't honor them, see if there is an overriding setting within the viewers preference settings.

I did a quick test run on a sample PDF of mine. Here is how the PDF root object's dictionary looks now, checked with the help of pdf-parser.py:

pdf-parser-beta.py -s Catalog a.pdf
 obj 1 0
  Type: /Catalog
  Referencing: 3 0 R, 9 0 R

   <<
     /Type       /Catalog
     /Pages      3 0 R
     /PageMode   /UseNone
     /Page       1
     /View       [/XYZ null null 1]
     /PageLayout /SinglePage
     /Metadata   9 0 R
   >>

To learn more about the pdfmark operator, google for 'pdfmark reference filetype:pdf'. You should be able to find it on the Adobe website and elsewhere:

  • https://www.google.de/search?q=pdfmark%20reference%20filetype%3Apdf&oq=pdfmark%20reference%20filetype%3Apdf

In order to let ImageMagick create a PDF as you want it, you may be able to hack the file defining your delegate settings. For more help about this topic see for example here:

  • http://www.imagemagick.org/Usage/files/#delegates
like image 184
Kurt Pfeifle Avatar answered Sep 30 '22 03:09

Kurt Pfeifle