Package org.pdfbox.pdfwriter

Examples of org.pdfbox.pdfwriter.COSWriter


        InputStream is2 = null;
        PDFParser parser1 = null;
        PDFParser parser2 = null;

        OutputStream os = null;
        COSWriter writer = null;
        try
        {
            is1 = new FileInputStream(in1);
            parser1 = new PDFParser(is1);
            parser1.parse();
            doc1 = parser1.getDocument();

            is2 = new FileInputStream(in2);
            parser2 = new PDFParser(is2);
            parser2.parse();
            doc2 = parser2.getDocument();

            setField(doc1, "doc1", new COSString(name1), new COSString(value1));
            setField(doc2, "doc2", new COSString(name2), new COSString(value2));

            appendDocument(doc1, doc2);

            os = new FileOutputStream(out);
            writer = new COSWriter(os);
            writer.write(doc1);
        }
        finally
        {
            is1.close();
            doc1.close();

            is2.close();
            doc2.close();

            os.close();
            writer.close();
        }
    }
View Full Code Here


    }

    private static void writeDocument( PDDocument pdf, String filename ) throws IOException, COSVisitorException
    {
        FileOutputStream output = null;
        COSWriter writer = null;
        try
        {
            output = new FileOutputStream( filename );
            writer = new COSWriter( output );
            writer.write( pdf );
        }
        finally
        {
            if( writer != null )
            {
                writer.close();
            }
            if( output != null )
            {
                output.close();
            }
View Full Code Here

                if( document.isEncrypted() )
                {
                    DecryptDocument decryptor = new DecryptDocument( document );
                    decryptor.decryptDocument( password );

                    COSWriter writer = new COSWriter( new FileOutputStream( outfile ) );
                    writer.write( document );
                    writer.close();
                }
                else
                {
                    System.err.println( "Error: Document is not encrypted." );
                }
View Full Code Here

        FileInputStream pdfStream = null;
        FileInputStream fdfStream = null;
        FileOutputStream output = null;
        PDFParser pdfParser = null;
        PDFParser fdfParser = null;
        COSWriter writer = null;

        try
        {
            if( args.length != 3 )
            {
                usage();
            }
            else
            {
                ImportFDF importer = new ImportFDF();
                pdfStream = new FileInputStream( args[0] );
                fdfStream = new FileInputStream( args[1] );
                output = new FileOutputStream( args[2] );
                pdfParser = new PDFParser( pdfStream );
                fdfParser = new PDFParser( fdfStream );
                pdfParser.parse();
                fdfParser.parse();

                pdf = pdfParser.getPDDocument();
                fdf = fdfParser.getDocument();
                importer.importFDF( pdf, fdf );

                writer = new COSWriter( output );
                writer.write( pdf );
            }
        }
        finally
        {
            close( fdf );
View Full Code Here

     */
    public void create( String file ) throws IOException, COSVisitorException
    {
        PDDocument document = null;
        FileOutputStream output = null;
        COSWriter writer = null;
        try
        {
            document = new PDDocument();
            //Every document requires at least one page, so we will add one
            //blank page.
            PDPage blankPage = new PDPage();
            document.addPage( blankPage );
            output = new FileOutputStream( file );
            writer = new COSWriter( output );
            writer.write( document.getDocument() );
        }
        finally
        {
            if( writer != null )
            {
                writer.close();
            }
            if( output != null )
            {
                output.close();
            }
View Full Code Here

            }
            else
            {
                PDDocument pdf = null;
                FileInputStream pdfStream = null;
                COSWriter writer = null;
                FileOutputStream stream = null;
                SetField example = new SetField();

                //first get the PDF document.
                try
                {
                    pdfStream = new FileInputStream( args[0] );
                    PDFParser pdfParser = new PDFParser( pdfStream );

                    pdfParser.parse();

                    pdf = pdfParser.getPDDocument();
                }
                finally
                {
                    close( pdfStream );
                }

                //then set the field value
                example.setField( pdf, args[1], args[2] );

                //finally write the new pdf document.
                try
                {
                    stream = new FileOutputStream( args[0] );
                    writer = new COSWriter( stream );
                    writer.write( pdf );
                }
                finally
                {
                    close( stream );
                    close( writer );
View Full Code Here

TOP

Related Classes of org.pdfbox.pdfwriter.COSWriter

Copyright © 2018 www.massapicom. 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.