1. I have a PDF which has two Pages.
2. The content on page 1 is only till half of the page leaving the
remaining page with whitespace. Second page has some content on it as
well.
3. I want to create a new PDF which will combine/merge the content of
two pages with no white spaces in between. I want to have the content
on page 2 start right after content on page 1 finishes.
Hello Hrishi,
You could use a technique similar to the ElementEdit sample to write the first page content into a new document. Then use the same technique to write the second page content into that page. For example the code might look something like this:
ElementReader reader1, reader2;
reader1.Begin(page1);
reader2.Begin(page2);
PDFDoc newdoc;
Page newpage=newdoc.PageCreate();
ElementWriter writer;
writer.Begin(newpage);
ElementBuilder builder;
// write the first page content
writer.writeElement(builder.CreateGroupBegin());
ProcessElements(writer,reader1);
writer.writeElement(builder.CreateGroupEnd());
// write the second page content
Element elem=builder.CreateGroupBegin();
// translate the page by half of the page
elem.GetGState().SetTransform(Matrix2D(1,0,0,1,0,-page1.GetPageHeight()/2));
writer.writeElement(elem);
ProcessElements(writer,reader2);
writer.writeElement(builder.CreateGroupEnd());
Of course, this assumes that the second page content will fit in the whitespace on the first page.
Alternatively you could use approach shown in the Imposition sample project: