i'm seeing some strange behavior with concatenation.

i have individual PDF files (1-2 pages each) that have a pantone-colored box
in the header of the page.  these individual PDF files look great.

i then use iText (java) to concatenate them into a single PDF via the
prescribed concatenate technique (adapted from the
Concatenate.javaexample.)  this works well except for one problem:
all of the pages' header
boxes "inherit" the color of the box on whatever is the first page in the
sequence.

so, if i have 3 single-page PDF files with pantone-colored rectangles in the
header:

   1. blue box
   2. orange box
   3. brown box

those 3 PDF files look perfect.  after concatenation, one would obviously
expect the same sequence, but all 3 would be blue.  (or whatever the color
is of PDF #1).  everything else about the pages (text, fonts, layout,
EVERYTHING) is perfect.  only that rectangular pantone box has the wrong
color -- a valid color, not a random one or not-quite-the-right-shade color,
just the one belonging to page #1 for all pages.

i haven't been able to find any documentation that describes anything
different that needs to be done to handle concatenation when pantone colors
are involved.  i've tried some variations (with/without smart-copy, etc) to
no avail.

any ideas?

thanks much!

=====================

    public int concatenatePdf(List<File> pdfList, File destPdfFile, boolean
makeEven) {
        int pageCount = 0;
        if (pdfList == null) {
            return pageCount;
        }

        // concatenate into single PDF
        Document document = null;
        PdfCopy writer = null;
        for (File srcFile : pdfList) {
            // open the source for reading
            PdfReader reader = getPdfReader(srcFile);
            if (reader != null) {

                // prepare the destination for writing
                if (document == null) {
                    document = new Document(reader.getPageSizeWithRotation
(1));
                    try {
                        writer = new PdfSmartCopy(document, new
FileOutputStream(destPdfFile));
                    } catch (Throwable e) {
                        log.error("unable to write to output pdf: " +
destPdfFile.getPath() + ":", e);
                        return 0;
                    }
                    document.open();
                }

                // concatenate pages, ignore form fields and bookmarks if
any
                pageCount += importPages(reader, writer, srcFile);
            }
        }

        if (makeEven && pageCount > 0 && (pageCount % 2) == 1) {
            File srcFile = PdfAssembler.getBlankPageFile();
            // open the source for reading
            PdfReader reader = getPdfReader(srcFile);
            if (reader != null) {

                assert (document != null);

                // concatenate pages, ignore form fields and bookmarks if
any
                pageCount += importPages(reader, writer, srcFile);
            }
        }

        if (document != null) {
            document.close();
        }
        return pageCount;
    }

    protected PdfReader getPdfReader(File srcFile) {
        PdfReader reader = null;
        try {
            reader = new PdfReader(srcFile.getPath());
            reader.consolidateNamedDestinations();
        } catch (IOException e) {
            log.error("unable to read src pdf: " + srcFile.getPath() + ":",
e);
        }
        return reader;
    }

    protected int importPages(PdfReader reader, PdfCopy writer, File
srcFile) {
        int pageCount = 0;
        PdfImportedPage page;
        int n = reader.getNumberOfPages();
        for (int i = 1; i <= n; i++) {
            page = writer.getImportedPage(reader, i);
            try {
                writer.addPage(page);
                pageCount++;
            } catch (Throwable e) {
                log.error("unable to add pdf page " + i + ": " +
srcFile.getPath() + ":", e);
            }
        }
        return pageCount;
    }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to