Paulo Soares <psoares <at> consiste.pt> writes:
>
>
> > -----Original Message-----
> > From: itext-questions-bounces <at> lists.sourceforge.net
> > [mailto:itext-questions-bounces <at> lists.sourceforge.net] On
> > Behalf Of ???
> > Sent: Friday, October 27, 2006 8:32 AM
> > To: itext-questions <at> lists.sourceforge.net
> > Subject: [iText-questions] How to add anchors in an existing
> > pdf file usingPdfStamper?
> >
> > If i add anchors in an existing pdf file using PdfWriter, the
> > bookmarks is lost!
> >
>
> Yes.
>
> > When using PdfCopy, I find the pdf file's size changed!
> >
>
> So?
>
> > It is possible to add anchors in existing pdf files using PdfStamper ?
> >
>
> Yes.
>
> PS: You won't get better answers whithout elaborating a bit more on the
> questions.
>
> Paulo
>
> Aviso Legal:
> Esta mensagem
My question is simple, possibly I don't describe it clearly. I'm not good at
English.
I want to add an anchor to every page in an existing PDF file, at the same
time, all bookmarks must not be lost.
I have finished this work, but I feel it is not simple.
Look the snippet of code(C#):
//1. First, using PdfWriter to add anchor.
String inFileName, outFileName, outFileTempName
PdfReader reader = new PdfReader(inFileName);
reader.ConsolidateNamedDestinations();
//Get all bookmarks of existing pdf file
bookmarks = SimpleBookmark.GetBookmark(reader);
Document document = new Document(reader.GetPageSizeWithRotation(1));
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream
(outFileTempName, System.IO.FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int totalPageNum = reader.NumberOfPages;
for (int i = 1; i <= totalPageNum; i++)
{
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
page = writer.GetImportedPage(reader, i);
cb.AddTemplate(page, x, y);
Anchor anchor1 = new Anchor("Please visit", linkfont);
anchor1.Reference = "http://www.lowagie.com/iText/";
anchor1.Name = "top";
document.Add(anchor1);
}
//Close document
writer.FreeReader(reader);
document.Close();
//2. Second, using PdfCopy to add bookmarks to the temporay file
// (The file created by PdfWriter, saved in "outFileTempName", the file has
not bookmarks)
PdfReader reader2 = new PdfReader(outFileTempName);
Document document2 = new Document(reader2.GetPageSizeWithRotation(1));
pdfcopy = new PdfCopy(document2, new System.IO.FileStream(outFileName,
System.IO.FileMode.Create));
document2.Open();
PdfImportedPage page2=null;
for (int i = 1; i <= totalPageNum; i++)
{
page2 = pdfcopy.GetImportedPage(reader2, i);
pdfcopy.AddPage(page2);
}
//Add the bookmarks
if (bookmarks.Count > 0)
{
pdfcopy.SetOutlines(bookmarks);
}
//Close document2
pdfcopy.FreeReader(reader2);
document2.Close();
Now, I get the result file saved in "outFileName". The result file is correct,
but you see, the process is not simple.
I find PdfStamper can keep all feature in an existing PDF file, but i can't
find any simple solution to add anchors. Can you show me how to do that using
PdfStamper?
Thanks a lot!
cxf
>
> -------------------------------------------------------------------------
> 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
> iText-questions <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
-------------------------------------------------------------------------
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