7

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% ?

3
  • Can you provide a sample PNG? Commented Jan 28, 2015 at 14:16
  • I do not understand how you should need to "zoom up to 100%", if the PDF already opens in "Fit to Page" mode? Fit to Page is at such a (automatic) zoom level so that you always see the full page. 100% zoom can make view to the page very tiny (for small dimensions of the original PDF page) and very large so that you only see part of the page content (for big dimensions of the PDF page). Commented Jan 28, 2015 at 14:19
  • Are you aware that you can also set most PDF viewers to override whatever is set in the PDF for initial view mode? You can tell f.e. Acrobat Reader to always open a file with 100% zoom. Look for the "Preferences" menu.... Commented Jan 28, 2015 at 14:21

2 Answers 2

9

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:

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:

0

PDF specification supports this functionality in this way: create a GoTo action that goes to first page and sets the zoom level to 100% and then set the action as the document open action.
How exactly you implement it in real life depends very much on the tool you use to create the PDF file. I do not know if ImageMagick can create such actions.

4
  • 1
    Thanks for reply..can you give an example...How can I achieve this in pdf ? Commented Jan 28, 2015 at 12:21
  • What tool do you use to create the PDF file?
    – iPDFdev
    Commented Jan 28, 2015 at 14:05
  • I don't think a PDF action is required. The PageMode setting of the page needs to be set to original size when it is created or afterwards, as Kurt Pfeifle has suggested.
    – gn1
    Commented Jan 29, 2015 at 3:19
  • @iPDFdev am using ImageMagick to create a pdf from png by using convert command.. Commented Jan 29, 2015 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.