Hi guys,
I'm pretty new to iText, so apologies if I'm missing something stupid
here: I've had a look through the FAQ and mailing list archives, and
can't see anything obvious, but it might be that I'm using the wrong
terminology or something.
I'm using iText 5.0.2 to overlay a PDF document over another PDF
document, and running into some problems. The following is the snippet
of code I'm using to achieve this:
PdfReader docReader = new PdfReader(document);
PdfReader firstPageStationaryReader = new
PdfReader(stationaryConfiguration.getFirstPageStationary());
PdfReader evenPageStationaryReader = new
PdfReader(stationaryConfiguration.getEvenPageStationary());
PdfReader oddPageStationaryReader = new
PdfReader(stationaryConfiguration.getOddPageStationary());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(docReader,baos);
PdfImportedPage firstPageStationary =
stamper.getImportedPage(firstPageStationaryReader, 1);
PdfImportedPage evenPageStationary =
stamper.getImportedPage(evenPageStationaryReader, 1);
PdfImportedPage oddPageStationary =
stamper.getImportedPage(oddPageStationaryReader, 1);
int numberOfPages = docReader.getNumberOfPages();
for ( int i = 1; i <= numberOfPages; i++ ) {
PdfContentByte background = stamper.getUnderContent(i);
if ( i == 1 ) {
background.addTemplate(firstPageStationary, 0,
0);
} else if ( (i % 2) == 0 ) {
background.addTemplate(evenPageStationary, 0,
0);
} else {
background.addTemplate(oddPageStationary, 0, 0);
}
}
stamper.close();
(inputs and outputs are all byte arrays for the time being)
On the face of it, this process looks to be working:
* There are no exceptions, errors or warnings (that I can see) coming
out of the code.
* If I extract the text from the PDF (using PDFBox), then it looks
like it contains both text from the PDF itself, as well as its headed
note paper (which means my unit tests are passing).
However, if I actually /look/ at the resulting PDF, then I can't see
the headed notepaper - only the letter itself.
Interestingly, I /was/ using PDFBox to do the same thing, and was
getting a similar result (although that code put the stationary on
top, so I could only see the stationary instead of the letter).
My working hypothesis is that both PDF files have a white background
embedded in them, which is obscuring the underlay.
Both documents were printed as PDFs from Apple's Pages on a Mac.
So, questions:
* Is this something you guys have come across before? Does my working
hypothesis seem like a likely cause? Is there an easy diagnostic I can
do do prove this?
* Above all: Is there something I can do in iText to remove these
white backgrounds before I start the underlay operation?
The PDFs I'm going to be processing are likely to be produced more or
less as I have created these test files (hence me doing it this way),
so I'm loathed to have to say to users 'please avoid using any
software that creates a white background on the PDF', because they
won't understand what this means...
Thanks very much,
Paul
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/