据我所知,PDFBox 不包含用于该任务的单一、专用 方法。另一方面,使用现有的 generic 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(相当少),使其成为具有平铺视图的便携式集合。
根据 ISO 32000-1 的第 12.3.5 节“集合”(我还没有第二部分),这意味着我们必须在 PDF 目录中添加一个 Collection 字典,并带有 查看 值为 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(...);