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

前端 未结 2 1289
野趣味
野趣味 2021-01-13 12:45

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 file

相关标签:
2条回答
  • 2021-01-13 13:11

    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.

    0 讨论(0)
  • 2021-01-13 13:12

    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
    0 讨论(0)
提交回复
热议问题