Okay, you've got this big annot in the background that says "cover me
up". And a bunch of fields in the foreground that cover it up. But in
the flattened PDF, the background annotation is on top. Right?
I know what that is.
The Stamper stores all the fields it flattens in a HashMap. When all is
said an done, it iterates through that hash map to write out the
flattened fields: their order is essentially random. That big
background field just happens to be on top. (or at least in front of
whatever should be covering it).
It's a bug that's been in iText for a Long Time, but very few people
overlap fields like this, so it's rarely an issue. I do. My
bastardized branch of iText has a fix for it, but being a bastardized
branch, it doesn't lend itself to an easy port to the trunk.
It looks like its time to bite the bullet.
--Mark Storer
Senior Software Engineer
Cardiff.com
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
________________________________
From: Jan Nielsen [mailto:[email protected]]
Sent: Wednesday, May 19, 2010 3:54 AM
To: [email protected]
Subject: [iText-questions] PdfStamper makes invisible fields
visible
Hi
I would like to flatten a Reader Extended pdf before exporting
it to an external system.
I have found this code
*************Method 1 *************************
iTextSharp.text.pdf.PdfReader reader = new
iTextSharp.text.pdf.PdfReader(PathToFormToArchive);
PdfStamper stamper = new PdfStamper(reader, new
FileStream("C:\\Flattened.pdf", FileMode.Create, FileAccess.Write));
// stamper.FormFlattening = true; // If I use this line, I'll
get the error "If this message is not eventually replaced by the proper
contents of the document, your PDF viewer may not be able to display
this type of document" when I open the pdf.
stamper.Close(); // Writes the pdf correctly if I make the
.FormFlattening = true a comment. Unfortunately the written pdf has all
fields visible. I want the hidden fields to stay hidden.
****************Method 2 ************************
private void _write()
{
string inFile = PathToFormToArchive;
string outFile = @"c:\out.pdf";
iTextSharp.text.Document document = new
iTextSharp.text.Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document,
new FileStream(outFile, FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfReader reader = new PdfReader(inFile);
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
PdfImportedPage page =
writer.GetImportedPage(reader, i);
int rotation = reader.GetPageRotation(i);
if (rotation == 90)
{
cb.AddTemplate(page, 0, -1, 1, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
else if (rotation == 270)
{
cb.AddTemplate(page, 0, 1, -1, 0,
reader.GetPageSizeWithRotation(i).Width, 0);
}
else
{
cb.AddTemplate(page, 0, 0);
}
document.NewPage();
}
document.Close();
}
Produces the same error when I open the pdf:
"If this message is not eventually replaced by the proper
contents of the document, your PDF viewer may not be able to display
this type of document"
I use C# 2.0
Adobe Reader 9.0
Best regards and thanks for your help
Jan Nielsen
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.819 / Virus Database: 271.1.1/2842 - Release Date:
05/17/10 23:26:00
------------------------------------------------------------------------------
_______________________________________________
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/