将压缩文件附加到PDF

将压缩文件附加到PDF,pdf,adobe,digital-signature,pdfbox,Pdf,Adobe,Digital Signature,Pdfbox,使用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( "

使用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();
        PDEmbeddedFile embeddedFile = new PDEmbeddedFile(doc, attachedFileInputStream );
        embeddedFile.addCompression();
        List<COSName> list = new ArrayList<COSName>();
        list.add(COSName.FLATE_DECODE);
        embeddedFile.setFilters(list);
我找到了解决办法:

            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();
        PDEmbeddedFile embeddedFile = new PDEmbeddedFile(doc, attachedFileInputStream );
        embeddedFile.addCompression();
        List<COSName> list = new ArrayList<COSName>();
        list.add(COSName.FLATE_DECODE);
        embeddedFile.setFilters(list);