Command line tool to mark PDF to open in single page mode

Short question: Is there a PDF command line / wrapper program (for osx) that can set the required property in a PDF file to initially open it in "Single Page View" (suitable for a window)


Additional Information

I am currently creating PDFs using WkhtmlToPdf, and in some cases merging the generated files with PDFTK via PHP and some shell calls on Mac.

However, I would like these documents to be opened by users' PDF readers by default under Single Page View / Fit to Window.

I came across the following question , which says that this feature has been put on the feature request list for PDFTk, but I cannot find a link to it ever implemented. I also came across Advanced PDF Tools (see the -q [OpenAction] flag), however this tool is only available for Windows and I need something that OSX supports

+3


source to share


2 answers


You can do it with CPDF :



cpdf in.pdf -set-page-layout SinglePage AND -fit-window -o out.pdf

      

+1


source


You can use PostScript snippets using a special operator pdfmark

to insert the appropriate settings DOCVIEW

with Ghostscript into the target PDF.

Here's an example embedded in a text file my-pdf-docview-pdfmark.ps

:

[ /PageMode /UseOutlines  % Display bookmarks upon opening the doc
 %/PageMode /UseThumbs    % Display thumbnails upon opening the doc
 %/PageMode /FullScreen   % Open the document in fullscreen mode
 %/PageMode /None         % Display neither bookmarks nor thumbnails upon opening
  /Page 2                 % Open document with page 2, not page 1!
 %/View [ /XYZ null null null ]
                          % Go to specified page and retain same ... 
                          % ... horizontal/vertical offset+zoom as current page
  /View /Fit              % Fit page to window
 %/View /FitB             % Fit visible part of page to window
 %/View [/FitH 220]       % Fit page width to window; 220 is distance ...
                          % ... of page origin from top of window
                                         /DOCVIEW    pdfmark

 [ {Catalog} <<
              /PageLayout /SinglePage
             %/PageLayout /OneColumn
             %/PageLayout /TwoColumnRight
             %/PageLayout /TwoColumnLeft
             >>                          /PUT        pdfmark

      

Note that it is not a bug to only see the opening square bracket , but not close it. is an operator and is closed by the last keyword . [

[

pdfmark



Some of the lines above are not commented out with a start character %

to show other alternatives.

Please be aware that this may not work for all users or all viewers. These settings are only hints and tips for viewers who may or may not respect them. Alternatively, users can override the configuration of their viewer and tell it to always ignore these prompts and instead open all PDFs as the user instructs.

After creating the above file, apply it to the PDF:

gs -o output.pdf               \
   -sDEVICE=pdfwrite           \
     my-pdf-docview-pdfmark.ps \
   -f input.pdf

      

0


source







All Articles