Example usage for org.apache.pdfbox.pdmodel.common.filespecification PDEmbeddedFile toByteArray

List of usage examples for org.apache.pdfbox.pdmodel.common.filespecification PDEmbeddedFile toByteArray

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.common.filespecification PDEmbeddedFile toByteArray.

Prototype

public byte[] toByteArray() throws IOException 

Source Link

Document

This will copy the stream into a byte array.

Usage

From source file:dev.ztgnrw.ExtractEmbeddedFiles.java

License:Apache License

private static void extractFile(String filePath, String filename, PDEmbeddedFile embeddedFile)
        throws IOException {
    String embeddedFilename = filePath + filename;
    File file = new File(filePath + filename);
    System.out.println("Writing " + embeddedFilename);
    FileOutputStream fos = null;//from  ww w . j av a  2s.com
    try {
        fos = new FileOutputStream(file);
        fos.write(embeddedFile.toByteArray());
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:org.mustangproject.ZUGFeRD.ZUGFeRDImporter.java

License:Open Source License

private void extractFiles(Map<String, PDComplexFileSpecification> names) throws IOException {
    for (String filename : names.keySet()) {
        /**//from w  ww . j ava 2s.c om
         * currently (in the release candidate of version 1) only one attached file with
         * the name ZUGFeRD-invoice.xml is allowed
         */
        if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) //$NON-NLS-1$
                || filename.equals("factur-x.xml"))) {
            containsMeta = true;

            PDComplexFileSpecification fileSpec = names.get(filename);
            PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
            // String embeddedFilename = filePath + filename;
            // File file = new File(filePath + filename);
            // System.out.println("Writing " + embeddedFilename);
            // ByteArrayOutputStream fileBytes=new
            // ByteArrayOutputStream();
            // FileOutputStream fos = new FileOutputStream(file);

            rawXML = embeddedFile.toByteArray();
            setMeta(new String(rawXML));

            // fos.write(embeddedFile.getByteArray());
            // fos.close();
        }
        if (filename.startsWith("additional_data")) {

            PDComplexFileSpecification fileSpec = names.get(filename);
            PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
            additionalXMLs.put(filename, embeddedFile.toByteArray());

        }
    }
}

From source file:org.pdfmetamodifier.IOHelper.java

License:Apache License

private static void extractFile(final File outputDir, final PDComplexFileSpecification fileSpec)
        throws IOException {
    final File file = new File(outputDir.getAbsolutePath() + File.separatorChar + fileSpec.getFilename());
    final PDEmbeddedFile embeddedFile = getEmbeddedFile(fileSpec);
    Files.write(file.toPath(), embeddedFile.toByteArray());
}