You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Woude, Alexander van der" <al...@capgemini.com> on 2011/12/21 13:31:11 UTC

Setting the version of pdf with PDFMergerUtility

Hello all,

I am facing a problem.

I retrieve documents from Oracle's UCM (content manager). I receive the doc=
uments  - all pdfs - from UCM as a stream.=20
A ByteArrayOutputStream to be precise.

My problems is that some docuemtns I retrieve are scanned, and stored as PD=
F1.2 format.
After I merge all the documents the generated PDF is 1.2. In that version a=
 fonttype is not available and cause that some docs in the concatenated pdf=
 is unreadable.
So I want to set the merged version to 1.4.

I tried to reuse the code from the PDFMergerUtility. mergeDocuments(), inco=
rporated it in my own code and alter it. See below.
Can someone suggest me what I do wrong or point me to a better way of doing=
 this?

Regards, Alexander

private void mergeDocuments(PDFMergerUtility mergeUtil) throws IOException,=
 COSVisitorException
    {
            =09
        PDDocument destination =3D null;
        InputStream sourceFile;
        PDDocument source;
       =20
        if (streamOfPDFFiles !=3D null && streamOfPDFFiles.size() > 0)
        {
         java.util.Vector<PDDocument> tobeclosed =3D new java.util.Vector<P=
DDocument>();
        =09
            try
            {
                Iterator<InputStream> sit =3D streamOfPDFFiles.iterator();
                sourceFile =3D sit.next();
                destination =3D PDDocument.load(sourceFile);
                destination.getDocument().setVersion(1.4f);
              =20
                while (sit.hasNext())
                {
                    sourceFile =3D sit.next();
                    source =3D PDDocument.load(sourceFile);
                    tobeclosed.add(source);
                    mergeUtil.appendDocument(destination, source);
                }
                destination.save(outputStream);
            }
            finally
            {
                if (destination !=3D null)
                {
                    destination.close();
                }
                 for(PDDocument doc : tobeclosed){
                         doc.close();
                 }=20
            }
        }
    }






This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is 
intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to 
read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message 
in error, please notify the sender immediately and delete all copies of this message.


Re: Setting the version of pdf with PDFMergerUtility

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

Am 21.12.2011 13:31, schrieb Woude, Alexander van der:
> Hello all,
>
> I am facing a problem.
>
> I retrieve documents from Oracle's UCM (content manager). I receive the doc=
> uments  - all pdfs - from UCM as a stream.=20
> A ByteArrayOutputStream to be precise.
>
> My problems is that some docuemtns I retrieve are scanned, and stored as PD=
> F1.2 format.
> After I merge all the documents the generated PDF is 1.2. In that version a=
>   fonttype is not available and cause that some docs in the concatenated pdf=
>   is unreadable.
> So I want to set the merged version to 1.4.
>
> I tried to reuse the code from the PDFMergerUtility. mergeDocuments(), inco=
> rporated it in my own code and alter it. See below.
> Can someone suggest me what I do wrong or point me to a better way of doing=
>   this?

Should be solved with PDFBOX-879 [1]

> Regards, Alexander
<SNIP>

BR
Andreas Lehmkühler

[1] https://issues.apache.org/jira/browse/PDFBOX-879