Print Page | Close Window

RenderPageToString and page size question

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=1621
Printed Date: 02 Jul 25 at 8:17AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: RenderPageToString and page size question
Posted By: wjbons
Subject: RenderPageToString and page size question
Date Posted: 01 Nov 10 at 8:43AM
Hi,
 
I use the RenderPageToString to get a bitmap from the pdf content.
But default it has a certain size.
 
I want to create a bitmap in a different size of let's say page 1.
If I use the SetPageDimensions function it crops the bitmap to a part of the page content and does not resize the content (clipped). I tried using the setpagebox, but did not get the right solution out.
 
Qs:
How can I create a smaller output bitmap than the original size which contains the full page content?
( I am able to create the original bitmap and afterwards resize this one, but that is more time consuming)



Replies:
Posted By: Dimitry
Date Posted: 01 Nov 10 at 7:08PM
Actually there are two ways to render page to bitmap of certain size:
 
1. The first way is to define DPI for RenderPageToString().
Unlike output bitmap size, actual page size isn't affected by rendering with various DPI.
So PageWidth() and PageHeight() will be same until being changed via SetPageDimensions().
 
2. The second way is just to resize output Bitmap using Canvas.CopyRect().
Here is code sample:
 
// Image1: TImage;  - destination for resized Bitmap
// Bitmap: TBitmap; - our source Bitmap
var
  s, d: TRect;
begin
  s.Left := 0;
  s.Top := 0;
  s.Right := Bitmap.Width;
  s.Bottom := Bitmap.Height;
  d.Left := 0;
  d.Top := 0;
  d.Right := Round(Bitmap.Width/2);  // width and height are resized by 50% 
  d.Bottom := Round(Bitmap.Width/2);
  Image1.Canvas.CopyRect(d, Bitmap.Canvas, s);
end;
 
The first way gives definitely highest output quality, but the second is much faster because it uses StretchBlt() API inside.


-------------
Regards,
Dmitry


Posted By: wjbons
Date Posted: 02 Nov 10 at 10:30AM
thanks for your help.



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