Q: I’ll like to nest several pdf-files into one new pdf file with only
one (large) page.
I’ll like to place, scale and rotate (Matrix2D) each of the input-pfd-
files.
In your sample, you show how to merge PDF files into different pages.
That not my issue. You have a sample of placing several image files on
one page, but I cannot figure how to place a new pfd file.
-----
A: You can tweak ImpositionTest sample project (http://www.pdftron.com/
pdfnet/samplecode.html#ImpositionTest) so that all pages from an input
PDF document are placed on a single PDF page.
To implement this you would move the following code outside of the
loop - i.e. just before the 'for' loop.
Page new_page = new_doc.PageCreate(media_box);
new_doc.PagePushBack(new_page)
writer.Begin(new_page);
You would also need to set the transform on each Form XObject element
so that it first into the corresponding cell of the master page. You
may need to come up with number of columns and row on the target page.
The overall pseudo code may look as follows:
Page new_page = new_doc.PageCreate(media_box);
new_doc.PagePushBack(new_page)
writer.Begin(new_page);
double cell_width = new_page.GetPageWidth()/cols, cell_height =
new_page.GetPageHeight()/rows;
for (int y=0; y<rows; ++y)
for (int x=0; x<cols; ++x) {
Page src_page = (Page)imported_pages[x*y+x];
Element element = builder.CreateForm(src_page);
double sc_x = cel_width / src_page.GetPageWidth();
double sc_y = cel_height / src_page.GetPageHeight();
double scale = Math.Min(sc_x, sc_y);
element.GetGState().SetTransform(scale, 0, 0, scale, cell_width*x,
cell_width*y);
writer.WritePlacedElement(element);
}
writer.End();
If you are dealing with several separate PDF documents, you could
import them into a single 'imported_pages' Array (i.e. call
new_doc.ImportPages() multiple times) before going on the place all
pages on the master page.