【问题标题】:attach compressed file to PDF将压缩文件附加到 PDF
【发布时间】:2013-08-16 07:11:21
【问题描述】:

使用 PDF 框我可以将文档附加到 PDF。

PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFile( "Test.txt" );
InputStream is = ...;
PDEmbeddedFile ef = new PDEmbeddedFile(doc, is );
//set some of the attributes of the embedded file
ef.setSubtype( "test/plain" );
ef.setSize( data.length );
ef.setCreationDate( new GregorianCalendar() );
fs.setEmbeddedFile( ef );
Map efMap = new HashMap();
efMap.put( "My first attachment", fs );
efTree.setNames( efMap );
PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog() );
names.setEmbeddedFiles( efTree );
doc.getDocumentCatalog().setNames( names );

但是如何压缩该文件?我知道 PDStream 有方法 addCompression()。我应该使用它吗?

我找到了解决方案:

            PDEmbeddedFile embeddedFile = new PDEmbeddedFile(doc, attachedFileInputStream );  
            List<COSName> list = new ArrayList<COSName>(); 
            COSName filter = COSName.LZW_DECODE;

            list.add(filter);
            embeddedFile.setFilters(list);
            embeddedFile.setFileFilters(null);
            embeddedFile.addCompression();

【问题讨论】:

    标签: pdf adobe digital-signature pdfbox


    【解决方案1】:

    我找到了解决方案:

            PDEmbeddedFile embeddedFile = new PDEmbeddedFile(doc, attachedFileInputStream );
            embeddedFile.addCompression();
            List<COSName> list = new ArrayList<COSName>();
            list.add(COSName.FLATE_DECODE);
            embeddedFile.setFilters(list);
    

    【讨论】:

      猜你喜欢
      • 2021-03-17
      • 2010-12-19
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      相关资源
      最近更新 更多