I finally got it working with some minor tweaks in the code I originally posted.
The whole idea is the same, but i made some changes after finding a post from Bruno Lowagie at eclipse forums, in 2005-04-16, subject "changing the codeline addProducer() license problem?". So my code becomes:
PdfReader documentoPDF = new PdfReader(nomeArquivo);
PdfStamper stamper = new PdfStamper(documentoPDF, new FileOutputStream(nomeArquivoTemporario));
HashMap info = documentoPDF.getInfo();
if (!info.contains(KEY_CONTEM_CARIMBO)) {
...
(some code)
...
info.put(KEY_CONTEM_CARIMBO, "yes");
stamper.setMoreInfo(info);
}
stamper.close();
And voila! It worked.
Thank you all.
Filipe Fedalto
On 08/05/06, Filipe Fedalto <[EMAIL PROTECTED]> wrote:
Hi Paulo,
Thanks for your imediate answer.
I tried this
PdfReader documentoPDF = new PdfReader(nomeArquivo);
PdfStamper stamper = new PdfStamper(documentoPDF, new FileOutputStream(nomeArquivoTemporario));
PdfDictionary infoDictionary = stamper.getWriter().getInfo();
infoDictionary.put(new PdfName("CARIMBO"), new PdfBoolean(true));
stamper.close();
However, when I open the document again, the "CARIMBO" info field isn't there. The javadoc on method "getInfo()" says "Gets the info dictionary for changing." I couldn't find any method to "set" the info dictionary into the stamper or into the writer. So I assume the PdfWriter uses the same object instance I obtained at getInfo() and saves it into the new document.
I must be missing something or I must even be completely wrong. Anyways, when you said "The simplest way is to introduce one or two tags in the info." I thought it could be something like this code I posted.
Can someone please enlighten this question?
Thanks,
Filipe Fedalto
On 08/05/06, Paulo Soares <[EMAIL PROTECTED] > wrote:The simplest way is to introduce one or two tags in the info.
Paulo
----- Original Message -----
From: "Filipe Fedalto" < [EMAIL PROTECTED]>
To: < [email protected]>
Sent: Monday, May 08, 2006 7:23 PM
Subject: [iText-questions] Analyzing PDF content
Hi all,
Since this is my first mail to this list, I wish my best congratulations and
regards to Bruno Lowagie and Paulo Soares for their impressive work.
Now to the question:
I am developing a program to ensure that all my PDF documents have the same
basic format. This format is very simple and it is consited of a Generic
Cover-Page and a Generic Watermark. The Cover-Page and Watermark are both
PDF files themselves. The Cover-Page is a one-page PDF document with some
general instructions. It is appended to the very beginning of the document.
The Watermark is a one-page PDF file with an image embedded. It is appended
to the top-left corner of each page of the document. This Watermark PDF file
has a small page size equal to the image itself.
Thanks to the fabulous iText API my program is already working and both
addCoverPage and addWaterMark methods are fully-functional. That is,
whenever I input some PDF file, my program correctly appends the Cover-Page
and correctly inserts the Watermark in the over content of every subsequent
page.
However, I with to add some intelligence to my program so that it is able to
recognize whether some input document already has a Cover-Page or already
has the Watermark. If it already has the Cover-Page, my program is only to
insert the watermark. On the other hand, if all pages already have the
watermark, my program is only to insert the cover-page. Finally, if the
document has neither the cover-page nor any watermark, my program is to
insert both contents.
How can I use iText to analyze any input document to check whether it
already has some content? I don't want to end up with documents having more
than one cover-pages. Also, if I added the watermark more than once, i know
it would be placed over the same place, thus not being visible. However i'm
sure the final object size would be larger than necessary.
I was thinking about having the methods addWatermark and addCoverPage insert
some sort of invisible mark into the documents. This way, if i processed the
document again this invisible mark could be retrieved and checked as a means
to recognize this document were already processed.
Can any of you help me doing that using iText?
Thanks a lot!
Filipe Fedalto
Cansado dos disparates e despautérios da República?
Quer um basta nas desventuras de nossos governantes?
Acesse http://www.monarquia.org.br e http://www.brasilimperial.org.br
e saiba mais a respeito.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
