Print Page | Close Window

N-Up pages, 2-Up Booklet

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1220
Printed Date: 22 Nov 24 at 6:26PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: N-Up pages, 2-Up Booklet
Posted By: Rowan
Subject: N-Up pages, 2-Up Booklet
Date Posted: 21 Sep 09 at 5:05AM
N-Up is shorthand for 2-up, 3-up, 4-up etc, or basically: combining more than one different page together on the same sheet. The snippet of code below shows you how to combine two pages from a document onto one sheet in a new document. The sample doesn't include much error handling and has not been optimized as it is intended as a starting point only.

-------------
private void btnBooklet_Click(object sender, EventArgs e)
{
QuickPDFAX0716.PDFLibrary QP = new QuickPDFAX0716.PDFLibrary();
int result = QP.UnlockKey("...Insert_License_Key_Here...");

if (result == 1)
{
// First, load the original document that you wish to use for this imposition test:
QP.LoadFromFile(@"C:\Program Files\Quick PDF Library\Quick PDF Library 7.16 Reference Guide.pdf");

// Then we get the number of pages in the original document:
int originalPageCount = QP.PageCount();

// Store the width and height of the pages from the original document:
double w = QP.PageWidth();
double h = QP.PageHeight();

// Use the CapturePage function to capture every page in the original document.
// Each captured page will be given a unique ID which can be used with the
// DrawCapturedPage function. Temporarily store these ID's in an array:
int[] capture = new int[originalPageCount];
int indexArray = 0;

for (int pageTest = 1; pageTest <= originalPageCount; pageTest++) 
{
capture[indexArray] = QP.CapturePage(1);
indexArray++;

if (QP.PageCount() == 1)
{
// After a page has been captured it's removed from the document in memory,
// but we can't have a document with no pages, so a temporary page must be
// created until the imposed pages have been added to the document.
QP.NewPage();
}
}

int requiredPages = 0;

// Now calculate the required number of pages for the 2-up booklet:
if (originalPageCount == 1)
{
requiredPages = 1;
}
else
{
requiredPages = originalPageCount / 2;
}

// Add the required number of pages to the end of the document, using the NewPages function:
QP.NewPages(requiredPages);

int captureIndex = 0;

// Now loop through each new page in the document and draw the captured pages. Two captured
// pages will be drawn on each new page. The first captured page is drawn on the left, the
// second on the right, and then it moves on to the next new page and repeats the process:
for (int page = 1; page <= requiredPages + 1; page++)
{
QP.SelectPage(page);
QP.SetPageDimensions(w * 2, h);

for (int i = 0; i <= 0; i++)
{
if (i <= 1)
{
// Draw left
if (captureIndex != capture.Length)
{
QP.DrawCapturedPage(capture[captureIndex], 0, h, w, h);
QP.DrawText(100, 25, "Page: " + captureIndex);
captureIndex++;
}
// Draw right
if (captureIndex != capture.Length)
{
QP.DrawCapturedPage(capture[captureIndex], 560, h, w, h);
QP.DrawText(w, 25, "Page: " + captureIndex);
captureIndex++;
}
}
}
}
// Delete the extra page that was created when the original pages were captured
QP.DeletePages(QP.PageCount(), 1);

// Save the new 2-up booklet
QP.SaveToFile(@"C:\temp\Manual_Booklet.pdf");
}
else
{
MessageBox.Show("Sorry, but the license key you provided could not be validated.");
}
}
-------------



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk