Print Page | Close Window

Change PageSize Midway?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1528
Printed Date: 04 Jul 25 at 9:55AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Change PageSize Midway?
Posted By: waynefulcher
Subject: Change PageSize Midway?
Date Posted: 04 Aug 10 at 10:33PM
I have some data that will be passed to my function which will generate a PDF. The problem is I have no way "ahead of time" to know if this data will fit on letter or require legal.
The idea here is I need the document to be on letter if it will all fit and if not switch to legal as a preference to having 2 letter pages.
It will be a tremendous amount of work to "preprocess" the entire document with all the data being passed in to calculate the total height of all the data since there are many different headings which use different fonts and text sizes. Also I tried initializing my page size to letter and then draw the text to the page until I could see that the text would not fit then I tried to just switch the pagesize to legal mid-stream. That did not work as all the text drawn before switching the page size seemed to be centered vertically on the legal page. I also tried initializing it to legal, drawing my text and when done if it used less than was needed for letter then I switched the page size to letter but then about half the text was off the top of the page. Does anyone know if this can be done reliably or do I just have to process all the data twice, once for the math of it to decide the total height and then once to actually print?
Thanks for your help.



Replies:
Posted By: waynefulcher
Date Posted: 05 Aug 10 at 4:15PM
For future readers I figured out how to change the pagesize after drawing to a page has already occured and be able to keep the data. Now if you switch from legal down to letter then obviously what was draw below the bottom  of a letter size page will get cut off. But switching from Letter to Legal appears to work just fine.
 
procedure ChangePageSize(PDF: TQuickPDF0719; NewPageSize: String) ;
var
  i, pc: Integer ;
  aCapPageID: array of Integer ;
  OrigPageWidth: Double ;
  OrigPageHeight: Double ;
begin
  pc := PDF.PageCount ;
  OrigPageWidth := PDF.PageWidth ;
  OrigPageHeight := PDF.PageHeight ;
  SetLength(aCapPageID, pc) ;
  for i := 1 to pc do begin
    PDF.NewPage ;
    aCapPageID[i-1] := PDF.CapturePage(1) ;
  end ;

  PDF.SetOrigin(1) ; // Top-Left
  PDF.SetPageSize(NewPageSize) ;

  for i := 1 to pc do begin
    PDF.SelectPage(i) ;
    PDF.DrawCapturedPage(aCapPageID[i-1], 0, 0, OrigPageWidth, OrigPageHeight) ;
  end ;
end ;




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