Examples of PDComplexFileSpecification


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

    /**
     * {@inheritDoc}
     */
    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
    {
        return new PDComplexFileSpecification( (COSDictionary)base );
    }
View Full Code Here

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

            //embedded files are stored in a named tree
            PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();

            //first create the file specification, which holds the embedded file
            PDComplexFileSpecification fs = new PDComplexFileSpecification();
            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("ISO-8859-1");
            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 );

            // create a new tree node and add the embedded file
            PDEmbeddedFilesNameTreeNode treeNode = new PDEmbeddedFilesNameTreeNode();
            treeNode.setNames( Collections.singletonMap( "My first attachment",  fs ) );
            // add the new node as kid to the root node
View Full Code Here

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

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

                if (embeddedFileNames != null) {
                    for (Map.Entry<String,Object> 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());
View Full Code Here

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

            PDDocumentCatalog catalog = doc.getDocumentCatalog();
            PDDocumentNameDictionary names = catalog.getNames();
            assertEquals("expected two files", 2, names.getEmbeddedFiles().getNames().size());
            PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles();

            PDComplexFileSpecification spec = (PDComplexFileSpecification)
                                            embeddedFiles.getNames().get("non-existent-file.docx");

            if (spec != null)
            {
                embeddedFile = spec.getEmbeddedFile();
                ok = true;
            }
            //now test for actual attachment
            spec = (PDComplexFileSpecification)embeddedFiles.getNames().get("My first attachment");
            assertNotNull("one attachment actually exists", spec);
            assertEquals("existing file length", 17660, spec.getEmbeddedFile().getLength());
            spec = (PDComplexFileSpecification)embeddedFiles
                                                    .getNames().get("non-existent-file.docx");
        }
        catch (NullPointerException e)
        {
View Full Code Here

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

                            {
                                if (debug)
                                {
                                    System.err.println("Processing embedded file " + ent.getKey() + ":");
                                }
                                PDComplexFileSpecification spec = (PDComplexFileSpecification) ent.getValue();
                                PDEmbeddedFile file = spec.getEmbeddedFile();
                                if (file.getSubtype().equals("application/pdf"))
                                {
                                    if (debug)
                                    {
                                        System.err.println("  is PDF (size=" + file.getSize() + ")");
View Full Code Here

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

            //embedded files are stored in a named tree
            PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();


            //first create the file specification, which holds the embedded file
            PDComplexFileSpecification fs = new PDComplexFileSpecification();
            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("ISO-8859-1");
            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() );
            names.setEmbeddedFiles( efTree );
View Full Code Here

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

    private static void extractFiles(Map<String,COSObjectable> names, String filePath)
            throws IOException
    {
        for (String filename : names.keySet())
        {
            PDComplexFileSpecification fileSpec = (PDComplexFileSpecification)names.get(filename);
            PDEmbeddedFile embeddedFile = getEmbeddedFile(fileSpec);
            String embeddedFilename = filePath+filename;
            File file = new File(filePath+filename);
            System.out.println("Writing "+ embeddedFilename);
            FileOutputStream fos = new FileOutputStream(file);
View Full Code Here

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

    private static void extractFiles(Map<String,COSObjectable> names, String filePath)
            throws IOException
    {
        for (String filename : names.keySet())
        {
            PDComplexFileSpecification fileSpec = (PDComplexFileSpecification)names.get(filename);
            PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
            String embeddedFilename = filePath+filename;
            File file = new File(filePath+filename);
            System.out.println("Writing "+ embeddedFilename);
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(embeddedFile.getByteArray());
View Full Code Here

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

            PDDocumentCatalog catalog = doc.getDocumentCatalog();
            PDDocumentNameDictionary names = catalog.getNames();
            assertEquals("expected two files", 2, names.getEmbeddedFiles().getNames().size());
            PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles();

            PDComplexFileSpecification spec = (PDComplexFileSpecification)
                                            embeddedFiles.getNames().get("non-existent-file.docx");

            if (spec != null)
            {
                embeddedFile = spec.getEmbeddedFile();
                ok = true;
            }
            //now test for actual attachment
            spec = (PDComplexFileSpecification)embeddedFiles.getNames().get("My first attachment");
            assertNotNull("one attachment actually exists", spec);
            assertEquals("existing file length", 17660, spec.getEmbeddedFile().getLength());
            spec = (PDComplexFileSpecification)embeddedFiles
                                                    .getNames().get("non-existent-file.docx");
        }
        catch (NullPointerException e)
        {
View Full Code Here

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

        {
            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"));
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.