realshyfox Posted July 7, 2011 Share Posted July 7, 2011 (edited) Hy, I have a litle prob. with my code. I try to transform a normal PDF into 2UP booklet format but ... somewhere I seem to miss something.Please help me.The original code:N-Up pages, 2-Up Booklet -Rowan-expandcollapse popupprivate 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."); } }AutoIt Code: expandcollapse popup$QP = ObjCreate("QuickPDFAX0725.PDFLibrary") Global $MyPDF, $MyPDFnUP $MyPDF = "something.pdf" $MyPDFnUP = "something_nup.pdf" _PDFnUP($MyPDF, $MyPDFnUP) Func _PDFnUP($MyPDF, $MyPDFnUP) If $QP.UnlockKey("...Insert_License_Key_Here...") = 1 Then $QP.LoadFromFile($MyPDF) $PgCount = $QP.PageCount() Dim $CaptureArray[$PgCount] $w = $QP.PageWidth() $h = $QP.PageHeight() For $n = 0 To $PgCount - 1 Step 1 $CaptureArray[$n] = $QP.CapturePage(1) If $QP.PageCount() = 1 Then $QP.NewPage() Next $RequiredPages = 0 If $PgCount = 1 Then $RequiredPages = 1 Else $RequiredPages = $PgCount/2 EndIf $QP.NewPages($RequiredPages) $CaptureIndex = 0 For $m = 1 To $RequiredPages Step 1 $QP.SelectPage($m) $QP.SetPageDimensions($w * 2, $h) For $i = 0 To 0 Step 1 If $i <= 1 Then If $CaptureIndex <> UBound($CaptureArray) Then $QP.DrawCapturedPage($CaptureArray[$CaptureIndex], 0, $h, $w, $h) ; $QP.DrawCapturedPage($CaptureArray[$CaptureIndex], [s]2500[/s], $h, $w, $h) ;$QP.DrawCapturedPage($CaptureArray[$CaptureIndex], 500, $h, $w, $h) $CaptureIndex = $CaptureIndex + 1 EndIf If $CaptureIndex <> UBound($CaptureArray) Then ; $QP.DrawCapturedPage($CaptureArray[$CaptureIndex], 0, $h, $w, $h) ;$QP.DrawCapturedPage($CaptureArray[$CaptureIndex], [s]2500[/s], $h, $w, $h) $QP.DrawCapturedPage($CaptureArray[$CaptureIndex], 500, $h, $w, $h) $CaptureIndex = $CaptureIndex + 1 EndIf EndIf Next Next $QP.DeletePages($QP.PageCount(), 1) $QP.SaveToFile($MyPDFnUP) $QP.LoadFromFile($MyPDFnUP) $PgCount = $QP.PageCount() $QP.ExtractPages(1, $PgCount - 1) $QP.SaveToFile("New_" &$MyPDFnUP) EndIf EndFunc ;==> _PDFnUPThe error is that it doesn´t write two pages up but one page up.Thanks.Sorry. I should´ve looked better. Tired Edited January 6, 2015 by Melba23 Removed valid licence key mLipok 1 Learn, learn and ... learn Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now