Examples of PDEmbeddedFile


Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

    }

    @Test
    public void testOSSpecificAttachments() throws IOException
    {
        PDEmbeddedFile nonOSFile = null;
        PDEmbeddedFile macFile = null;
        PDEmbeddedFile dosFile = null;
        PDEmbeddedFile unixFile = null;

        PDDocument doc = PDDocument.load(TestEmbeddedFiles.class
                .getResourceAsStream("testPDF_multiFormatEmbFiles.pdf"));

        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        PDDocumentNameDictionary names = catalog.getNames();
        PDEmbeddedFilesNameTreeNode treeNode = names.getEmbeddedFiles();
        List<PDNameTreeNode> kids = treeNode.getKids();
        for (PDNameTreeNode kid : kids)
        {
            Map<String, COSObjectable> tmpNames = kid.getNames();
            COSObjectable obj = tmpNames.get("My first attachment");
            if (obj instanceof PDComplexFileSpecification)
            {
                PDComplexFileSpecification spec = (PDComplexFileSpecification) obj;
                nonOSFile = spec.getEmbeddedFile();
                macFile = spec.getEmbeddedFileMac();
                dosFile = spec.getEmbeddedFileDos();
                unixFile = spec.getEmbeddedFileUnix();
            }
        }

        assertTrue("non os specific",
                byteArrayContainsLC("non os specific", nonOSFile.getByteArray(), "ISO-8859-1"));
        assertTrue("mac", byteArrayContainsLC("mac embedded", macFile.getByteArray(), "ISO-8859-1"));

        assertTrue("dos", byteArrayContainsLC("dos embedded", dosFile.getByteArray(), "ISO-8859-1"));

        assertTrue("unix",
                byteArrayContainsLC("unix embedded", unixFile.getByteArray(), "ISO-8859-1"));

    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

                                if (debug)
                                {
                                    System.err.println("Processing embedded file " + ent.getKey() + ":");
                                }
                                PDComplexFileSpecification spec = (PDComplexFileSpecification) ent.getValue();
                                PDEmbeddedFile file = spec.getEmbeddedFile();
                                if (file != null && file.getSubtype().equals("application/pdf"))
                                {
                                    if (debug)
                                    {
                                        System.err.println("  is PDF (size=" + file.getSize() + ")");
                                    }
                                    InputStream fis = file.createInputStream();
                                    PDDocument subDoc = null;
                                    try
                                    {
                                        subDoc = PDDocument.load(fis);
                                    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

            fs.setFile( "Test.txt" );
            //create a dummy file stream, this would probably normally be a FileInputStream
            byte[] data = "This is the contents of the embedded file".getBytes();
            ByteArrayInputStream fakeFile =
                new ByteArrayInputStream( data );
            PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile );
            //now lets some of the optional parameters
            ef.setSubtype( "test/plain" );
            ef.setSize( data.length );
            ef.setCreationDate( new GregorianCalendar() );
            fs.setEmbeddedFile( ef );

            //now add the entry to the embedded file tree and set in the document.
            efTree.setNames( Collections.singletonMap( "My first attachment",  fs ) );
            PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog() );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

            fs.setFile( "Test.txt" );
            //create a dummy file stream, this would probably normally be a FileInputStream
            byte[] data = "This is the contents of the embedded file".getBytes();
            ByteArrayInputStream fakeFile =
                new ByteArrayInputStream( data );
            PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile );
            //now lets some of the optional parameters
            ef.setSubtype( "test/plain" );
            ef.setSize( data.length );
            ef.setCreationDate( new GregorianCalendar() );
            fs.setEmbeddedFile( ef );

            //now add the entry to the embedded file tree and set in the document.
            Map efMap = new HashMap();
            efMap.put( "My first attachment", fs );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

            PDComplexFileSpecification spec = (PDComplexFileSpecification) ent.getValue();
            if (spec == null) {
                //skip silently
                continue;
            }
            PDEmbeddedFile file = spec.getEmbeddedFile();
            if (file == null) {
                //skip silently
                continue;
            }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

                Map<String, COSObjectable> embeddedFileNames = embeddedFiles.getNames();

                if (embeddedFileNames != null) {
                    for (Map.Entry<String,COSObjectable> ent : embeddedFileNames.entrySet()) {
                        PDComplexFileSpecification spec = (PDComplexFileSpecification) ent.getValue();
                        PDEmbeddedFile file = spec.getEmbeddedFile();

                        Metadata metadata = new Metadata();
                        // TODO: other metadata?
                        metadata.set(Metadata.RESOURCE_NAME_KEY, ent.getKey());
                        metadata.set(Metadata.CONTENT_TYPE, file.getSubtype());
                        metadata.set(Metadata.CONTENT_LENGTH, Long.toString(file.getSize()));

                        if (embeddedExtractor.shouldParseEmbedded(metadata)) {
                            TikaInputStream stream = TikaInputStream.get(file.createInputStream());
                            try {
                                embeddedExtractor.parseEmbedded(
                                                                stream,
                                                                new EmbeddedContentHandler(handler),
                                                                metadata, false);
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

                    Map<String, Object> names_file = ef.getNames();
                    if (names_file != null) {
                        for (Object o : names_file.values()) {
                            if (o instanceof PDComplexFileSpecification) {
                                PDComplexFileSpecification a = (PDComplexFileSpecification) o;
                                PDEmbeddedFile f = a.getEmbeddedFile();
                                if (f != null) {
                                    String subtype = f.getSubtype();
                                    log.info("found file of type " + subtype + ": " + a.getFile());
                                    result.add(new String[]{subtype, decodeStream(f.getStream())});
                                }
                            }
                        }
                    }
                } catch (IOException e) {
View Full Code Here

Examples of org.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile

            fs.setFile( "Test.txt" );
            //create a dummy file stream, this would probably normally be a FileInputStream
            byte[] data = "This is the contents of the embedded file".getBytes();
            ByteArrayInputStream fakeFile =
                new ByteArrayInputStream( data );
            PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile );
            //now lets some of the optional parameters
            ef.setSubtype( "test/plain" );
            ef.setSize( data.length );
            ef.setCreationDate( new GregorianCalendar() );
            fs.setEmbeddedFile( ef );
           
            //now add the entry to the embedded file tree and set in the document.
            Map efMap = new HashMap();
            efMap.put( "My first attachment", fs );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.