What I'm doing is cropping a list of PDDocuments down to small rectangles.

Then I want to combine all the new cropped PDDocuments into one new PDDocument 
but I want them in specific locations.

Here’s an example of what I’m trying to do.



[cid:[email protected]]





I am currently doing something similar but I'm only using the original 
PDDocument.



private void drawSixUp(PDDocument document, PDPage page) throws IOException {

        final float rectangle_width = 2.25f * PDFx;

        final float rectangle_x_separation = 9.0f / 16.0f * PDFx;



        LayerUtility layerUtility = new LayerUtility(document);

        PDXObjectForm mountable = layerUtility.importPageAsForm(document, 0);

        mountable.getPDStream().addCompression();

        PDPageContentStream contentStream = new PDPageContentStream(document, 
page, true, true);

        contentStream.appendRawCommands("q\n".getBytes("ISO-8859-1"));



  //draw additional rectangles

        AffineTransform transform = new AffineTransform();

        transform.translate(rectangle_width + rectangle_x_separation, 0);

        contentStream.drawXObject(mountable, transform);



        transform = new AffineTransform();

        transform.translate(rectangle_width * 2 + rectangle_x_separation * 2, 
0);

        contentStream.drawXObject(mountable, transform);



        contentStream.appendRawCommands("Q\n".getBytes("ISO-8859-1"));

        contentStream.close();



    }



I’ve tried doing the same thing but for some reason it’s not working.

Here is what I’m trying:
public void drawMealDealStore(List<PDDocument> pdfImagesList) throws 
IOException {

    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream contentStream;
    AffineTransform transform;

    float couponGap = 0;
    int i = 1;
    for (PDDocument pdDocument : pdfImagesList) {
        LayerUtility layerUtility = new LayerUtility(document);
        PDXObjectForm mountable = layerUtility.importPageAsForm(pdDocument, 0);
        mountable.getPDStream().addCompression();
        contentStream = new PDPageContentStream(document, page, true, true);
        contentStream.appendRawCommands("q\n".getBytes("ISO-8859-1"));
        boolean topRow;
        if (i != 1 && i % SIX == 1) {
            page = new PDPage();
            document.addPage(page);
            contentStream = newPDPageContentStream(document, page);
            couponGap = 0;
            topRow = true;
        } else if (i == 1) {
            couponGap = 0;
            topRow = true;
        } else if (i % SIX == TWO || i % SIX == THREE) {
            couponGap += COUPONGAP;
            topRow = true;
        } else if (i % SIX == FOUR) {
            couponGap = 0;
            topRow = false;
        } else {
            couponGap += COUPONGAP;
            topRow = false;
        }
        transform = new AffineTransform();

        if (topRow) {
            transform.translate((X_INDENT*2) + couponGap, BOTTM_OF_TOP_REC);
        } else {
            transform.translate((X_INDENT * 2) + couponGap, BOTTM_OF_TOP_REC - 
(REC_Y_GAP + REC_HEIGHT));
        }
        contentStream.drawXObject(mountable, transform);

        // restore former graphics state
        contentStream.appendRawCommands("Q\n".getBytes("ISO-8859-1"));
        contentStream.close();
        pdDocument.close();
        i++;
    }

    try {
        document.save("mealDealStore.pdf");
    } catch (COSVisitorException e) {
        e.printStackTrace();
    }
    document.close();
}



This should work but all I’m getting is an empty page and the following error:

[cid:[email protected]]



Any ideas of what I’m doing wrong?



Thanks,

Lucy

-----Original Message-----
From: Gilad Denneboom [mailto:[email protected]]
Sent: Thursday, February 12, 2015 5:28 AM
To: [email protected]
Subject: Re: Overlay PDF Docs



Are you basically trying to combine multiple PDF files into a single one?

If so, use the PDFMergerUtility

<https://urldefense.proofpoint.com/v2/url?u=https-3A__pdfbox.apache.org_apidocs_org_apache_pdfbox_util_PDFMergerUtility.html&d=AwIBaQ&c=RI9dKKMRNVHr9NFa7OQiQw&r=46g1Q9l2ygNJoVl15Feuc2oj-eK5kwz0sL2OtXB9UQA&m=jftZpb6dXxgFhrFo9NoLhae2NQ6p3wKsyO5XQ6E2aS4&s=bmtD8HX65vDYwnzDBlDS_QCzRD6dNpgNnvrvgS3dvNU&e=
 
<https://urldefense.proofpoint.com/v2/url?u=https-3A__pdfbox.apache.org_apidocs_org_apache_pdfbox_util_PDFMergerUtility.html&d=AwIBaQ&c=RI9dKKMRNVHr9NFa7OQiQw&r=46g1Q9l2ygNJoVl15Feuc2oj-eK5kwz0sL2OtXB9UQA&m=jftZpb6dXxgFhrFo9NoLhae2NQ6p3wKsyO5XQ6E2aS4&s=bmtD8HX65vDYwnzDBlDS_QCzRD6dNpgNnvrvgS3dvNU&e=%20>
 > class.



On Thu, Feb 12, 2015 at 12:11 AM, Vorpahl,Lucinda 
<[email protected]<mailto:[email protected]>>

wrote:



> I am hoping someone can help me.

>

> I have a list of PDDocuments that I want to combine and draw onto 1

> PDDocument.

> I was able to do this by converting the individual documents to images

> then drawing the image on the new document but I lost image quality.

> I was looking at the Overlay option but I'm getting the following error:

>         "java.lang.UnsupportedOperationException: Layout pages with

> COSArray currently not supported."

>

> I also tried this but nothing was happening.

>

>         PDPageContentStream contentStream;

>          PDDocument document = new PDDocument();

>          PDPage page = new PDPage();

>          document.addPage(page);

>          AffineTransform transform;

> for (PDDocument pdDocument : pdfDocList) {

>             LayerUtility layerUtility = new LayerUtility(document);

>             PDXObjectForm mountable =

> layerUtility.importPageAsForm(pdDocument, 0);

>             mountable.getPDStream().addCompression();

>             contentStream = new PDPageContentStream(document, page);

>

> contentStream.appendRawCommands("q\n".getBytes("ISO-8859-1"));

>

>             transform = new AffineTransform();

>             transform.translate(18.0f, 18.0f);

>             contentStream.drawXObject(mountable, transform);

>

>             contentStream.appendRawCommands("Q\n".getBytes("ISO-8859-1"));

>             contentStream.close();

>         pdDocument.close();

> }

>

> Any help would be appreciated.

>

>

> Thanks,

> Lucy

>

Reply via email to