mpdf / mpdf

PHP library generating PDF files from UTF-8 encoded HTML
https://mpdf.github.io
GNU General Public License v2.0
4.4k stars 1.07k forks source link

The attachment pane is automatically opened #947

Open mmeciar opened 5 years ago

mmeciar commented 5 years ago

I would like to have this new functionality

The attachment pane is automatically opened with PDF viewer.

I tink it is possible to insert code to end of method MetadataWriter\writeCatalog

if($this->mpdf->page_mode == 'UseAttachments') {

    $this->writer->write('/PageMode /UseAttachments');
}

It will be necessary to define new config parameter page_mode.

There are more possible values: /UseNone /UseOutlines /UseThumbs /FullScreen /UseOC /UseAttachments

see https://wwwimages2.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf#page=82

PDF result

`52 0 obj << /Type /Catalog /Pages 24 0 R /Metadata 25 0 R /Names 27 0 R /PageLabels << /Nums [ 0 << /S /D /St 1

]

/PageMode /UseAttachments /Version /1.7

endobj`

peterdevpl commented 5 years ago

The method MetadataWriter\writeCatalog already utilizes some of the page modes you proposed: /UseOutlines, /FullScreen and /UseOC. They are all conditional. For example, it does not make sense to show bookmarks pane if there are no bookmarks/outlines in the document :)

I believe we should follow this philosophy. We could add /PageMode /UseAttachments if and only if there exist any file annotations (attachments) in the document. I already did a working Proof-of-concept. It requires adding a new method to Mpdf class: hasFileAnnotations().

However, /UseThumbs could be specified whenever we want as the thumbnails pane do not need embedded thumbnails. This is something we could add to the existing Mpdf::$DisplayPreferences.

We need to consider what to do when multiple /PageMode commands will be specified. What happens when we have both bookmarks and attachments in the same document? I've checked it - specifying multiple /PageMode commands do not break the document, however only the last setting is taken into account by the reader.

peterdevpl commented 5 years ago

@finwe what do you think about my proposal?