Print Page | Close Window

Scale all pages in a PDF with CapturePage

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=2012
Printed Date: 22 Nov 24 at 1:13PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Scale all pages in a PDF with CapturePage
Posted By: AndrewC
Subject: Scale all pages in a PDF with CapturePage
Date Posted: 26 Oct 11 at 4:58AM
Here is some C# code I wrote to scale all pages on a PDF by 70% and it shows how to use CapturePage.  It also shows how to construct the loop to process all pages and maintain the original page order. 

  private void button8_Click(object sender, EventArgs e)
  { 
    File.Delete("newpages.pdf");   // Delete the old file just in case.

    double pageWidth, pageHeight, horizBorder, vertBorder;
    double scaleFactor = 0.70;     // 70 % scaling reduction.
    int capturedPageId;
    int ret;

    QP.LoadFromFile("Pages.pdf");
    QP.SetOrigin(1);

    int numPages = QP.PageCount();
    int pageId;

    for (int i = 1; i <= numPages; i++)
    {
       QP.SelectPage(1);                       // Always select page 1 as the pages get deleted.
       pageWidth = QP.PageWidth();
       pageHeight = QP.PageHeight();
       horizBorder = pageWidth * (1.0 - scaleFactor) / 2;
       vertBorder = pageHeight * (1.0 - scaleFactor) / 2;

       capturedPageId = QP.CapturePage(1);     // This deletes the page from the document.

       pageId = QP.NewPage();
       QP.SetPageDimensions(pageWidth, pageHeight);

       ret = QP.DrawCapturedPage(capturedPageId, horizBorder, vertBorder, pageWidth - 2 * horizBorder, pageHeight - 2 * vertBorder);
     }

     QP.SaveToFile("newpages.pdf");
     System.Diagnostics.Process.Start(@"newpages.pdf");
   }




Replies:
Posted By: Carneno
Date Posted: 27 Mar 12 at 1:40PM
Hello,
 
I am using QuickPDF Library 8.11 Active-x in a VB 6.0 program.  It uses LoadFromFile to load PDF documents, overlay the bottom part of the PDF with a box and some text then print them.
 
I would like to reduce the size of the content for each page so that it appears on the top 80% of the page and add the box and text at the bottom so that it does not overlay the original PDF page.
 
Will this sample code allow me to do that?
 
It should not be a problem for me to convert to VB 6.0.
 
Any help would be gratefully appreciated.
 
Thanks,
Tony


-------------
Stop The World, I want To Get Off.


Posted By: AndrewC
Date Posted: 27 Mar 12 at 2:27PM
Yes.  It will work very well.

1. Change   scaleFactor to 0.80  for 80%.

2. You will need to move the image up the page a little as the current implementation centres in on the page.  The following change should do what you need.

  ret = QP.DrawCapturedPage(capturedPageId, horizBorder, vertBorder * 2, pageWidth - 2 * horizBorder, pageHeight);

Also : You are entitled to a free upgrade to 8.14 which has many bug fixes and improvements.  It can be downloaded from   http://www.quickpdflibrary.com/products/quickpdf/updates.php" rel="nofollow - http://www.quickpdflibrary.com/products/quickpdf/updates.php




Posted By: Carneno
Date Posted: 27 Mar 12 at 3:14PM
Excellent Andrew.
 
Thanks very much.
 
Tony


-------------
Stop The World, I want To Get Off.


Posted By: Pulkitsoft
Date Posted: 27 Feb 21 at 9:35AM

Is Anyone can help? Above given page scaling code working very well.

I wants to specify left, top, bottom, right margin in above given code.

Note: Output page not to be stretch.


Posted By: Ingo
Date Posted: 01 Mar 21 at 10:41PM
You can't set it directly.
All related functions are working with top, left, width and height - so you have to do some calculations ;-)



-------------
Cheers,
Ingo




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