Q: I have a document where I want to have two copies of the same page
and want to add different information on each of them.
My problem is that the information is put on the two pages instead of
each one.
I guess I need to copy the data to a new page but I haven’t found a
way yet.
Can you point me in the right direction?
---
A: When duplicating pages within the same document, PDFNet keeps the
reference to the same content stream and resources to keep the file
size down. In case you would like to fully replicate all information
when duplicating page you can use the following technique:
In C#/VB/JAVA:
{
PDFDoc tmp_doc = new PDFDoc();
tmp_doc.PagePushBack(my_page);
mydoc.PagePushBack(tmp_doc.GetPage(1));
tmp_doc.Close();
}
In C/C++
{
PDFDoc tmp_doc;
tmp_doc.PagePushBack(my_page);
mydoc.PagePushBack(tmp_doc.GetPage(1));
}
This way you can stamp replicated pages with different content.
Q: Thank you for taking the time to help me.
I have successfully duplicated a page using the following code
snippet:
Page oNewPage = oDocument.PageCreate (oPageToCopy.GetMediaBox ());
ElementReader oReader = new ElementReader ();
ElementWriter oWriter = new ElementWriter ();
Element oElement;
oReader.Begin (oPageToCopy);
oWriter.Begin (oNewPage);
while ((oElement = oReader.Next ()) != null)
oWriter.WriteElement (oElement);
oWriter.End ();
oReader.End ();
oDocument.PagePushBack (oNewPage);
Using this way I don't have to copy from one document to another and
hence having maximum efficiency since only a small fraction of the
pages need to be duplicated.
What do you think of this method? It seems to do the job as I get the
result I want.
Can you confirm this is a good way to do it?
-----
A: The only problem is that you may lose existing page annotations
(since you are only copying page content element and not annotations).
Also a possibly better (more efficient) approach would be to copy the
page content using builder.CreateForm(src_page, new_doc) as shown in
Imposition sample project (http://www.pdftron.com/net/
samplecode.html#Imposition).