I have a requirement to print the front page of a document (The address) and then print a contract page twice. Is it possible to do this? Can I say something like print pages 1,2,2 to print page 2 twice?
Hi Craig,
Thanks for your interest in our products.
In order to accomplish your requirement, you may try loading the source PDF file twice. From the second Document
object, get the second page and add it to the pages collection of the first Document
object. Please take a look at the following code snippet to accomplish your requirement.
[C#]
//open document
Document pdfDocument = new Document("c:/pdftest/1916 Nokia.pdf");
// create another document object
Document pdfDocument2 = new Document("c//pdftest/1916 Nokia.pdf");
// add the second page of second document object to pages collection of first document
pdfDocument.Pages.Add(pdfDocument2.Pages[2]);
//save updated PDF file
pdfDocument.Save("c//pdftest/output_2page.pdf");
Hmmm… Might actually be an idea to do it the other way round - create a PDF with 2 copies of page 2, print it out, then create another PDF with only page 2 and this is the one that gets saved… Will give it some thought!
Hi Craig,
There can be various approaches to fulfill your requirement. One of them can be to load the document and get only the second page of the document and save the output file in a Stream object. Finally, add the page of the newly created document object (with the second page) and add it to the original document.
//open document
Document pdfDocument = new Document("c:/pdftest/HTML_PDF_Sample.pdf");
//get particular page
Page pdfPage = pdfDocument.Pages[2];
// create a new document object to hold
// second page of PDF
Document newDocument = new Document();
newDocument.Pages.Add(pdfPage);
// Temporary steam object
MemoryStream temp_stream = new System.IO.MemoryStream();
// save the document object holding 2nd
// page
newDocument.Save(temp_stream);
// add the page of newly created
// Document object to original PDF document
pdfDocument.Pages.Add(newDocument.Pages[1]);
// save the final output document with
// 3 pages
pdfDocument.Save("c:/pdftest/Document_3_Pages.pdf");
// close the stream object
temp_stream.Close();