//--------------------------------------------------------------------------------------- // Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved. // Consult legal.txt regarding legal and license information. //--------------------------------------------------------------------------------------- using System; using System.IO; using System.Collections; using pdftron; using pdftron.Common; using pdftron.SDF; using pdftron.PDF; //----------------------------------------------------------------------------------- // The sample illustrates how multiple pages can be combined/imposed // using PDFNet. Page imposition can be used to arrange/order pages // prior to printing or to assemble a 'master' page from several 'source' // pages. Using PDFNet API it is possible to write applications that can // re-order the pages such that they will display in the correct order // when the hard copy pages are compiled and folded correctly. //----------------------------------------------------------------------------------- namespace ImpositionTestCS { class Class1 { static void Main(string[] args) { PDFNet.Initialize(); PDFNet.SetResourcesPath("../../../../../resources"); // Relative path to the folder containing test files. string input_path = "../../../../TestFiles/"; string output_path = "../../../../TestFiles/Output/"; try { Console.WriteLine("_______________________________________________"); Console.WriteLine("Opening the input pdf..."); PDFDoc in_doc = new PDFDoc(input_path + "newsletter.pdf"); in_doc.InitSecurityHandler(); PDFDoc new_doc = new PDFDoc(); // Paper dimension for A3 format in points. Because one inch has // 72 points, 11.69 inch 72 = 841.69 points Rect media_box= new Rect(0, 0, 1190.88, 841.69); double mid_point = media_box.Width()/2; ElementBuilder builder = new ElementBuilder(); ElementWriter writer = new ElementWriter(); PageIterator itr = in_doc.GetPageIterator(); while (itr.HasNext()) { // Create a blank new A3 page and place on it two pages from the input document. Page new_page = new_doc.PageCreate(media_box); writer.Begin(new_page); // Place the first page Page src_page = itr.Current(); Element element = builder.CreateForm(src_page, new_doc); double sc_x = mid_point / src_page.GetPageWidth(); double sc_y = media_box.Height() / src_page.GetPageHeight(); double scale = Math.Min(sc_x, sc_y); element.GetGState().SetTransform(scale, 0, 0, scale, 0, 0); writer.WritePlacedElement(element); // Place the second page itr.Next(); if (itr.HasNext()) { src_page = itr.Current(); element = builder.CreateForm(src_page, new_doc); sc_x = mid_point / src_page.GetPageWidth(); sc_y = media_box.Height() / src_page.GetPageHeight(); scale = Math.Min(sc_x, sc_y); element.GetGState().SetTransform(scale, 0, 0, scale, mid_point, 0); writer.WritePlacedElement(element); itr.Next(); } writer.End(); new_doc.PagePushBack(new_page); } new_doc.Save(output_path + "newsletter_booklet.pdf", SDFDoc.SaveOptions.e_linearized); new_doc.Close(); in_doc.Close(); Console.WriteLine("Done."); } catch (Exception e) { Console.WriteLine("Exception caught:\n{0}", e); } PDFNet.Terminate(); } } }