據我所知,PDFBox不包含單一專用該任務的方法。另一方面,使用現有的通用 PDFBox方法來實現它是相當容易的。
首先,任務就有效地定義做相當於
stamper.makePackage(PdfName.T);
使用PDFBox的。在iText的該方法被記錄爲:
/**
* This is the most simple way to change a PDF into a
* portable collection. Choose one of the following names:
* <ul>
* <li>PdfName.D (detailed view)
* <li>PdfName.T (tiled view)
* <li>PdfName.H (hidden)
* </ul>
* Pass this name as a parameter and your PDF will be
* a portable collection with all the embedded and
* attached files as entries.
* @param initialView can be PdfName.D, PdfName.T or PdfName.H
*/
public void makePackage(final PdfName initialView)
因此,我們需要改變一個PDF(相當最低限度),使之成爲便攜式採集與平鋪視圖。
根據第12.3.5 ISO 32000-1的「集合」(我沒有第二部分還沒有),這意味着我們必須添加一個集合詞典到PDF目錄與查看條目以值T。因此:
PDDocument pdDocument = PDDocument.load(...);
COSDictionary collectionDictionary = new COSDictionary();
collectionDictionary.setName(COSName.TYPE, "Collection");
collectionDictionary.setName("View", "T");
PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
catalog.getCOSObject().setItem("Collection", collectionDictionary);
pdDocument.save(...);
來源
2017-10-09 13:03:01
mkl