Rendering large pdf
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=2184
Printed Date: 22 Nov 24 at 2:26PM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
Topic: Rendering large pdf
Posted By: ADev
Subject: Rendering large pdf
Date Posted: 08 Mar 12 at 3:17PM
Welcome,
I'm trying to render large pdf to bmp, 72 (or 36) dpi by RenderPageToFile, DARenderPageToFile or other render method (also stream).
Functions always return 1 (all ok), but result bmp file has only white pixels (bmp page is white). Size (pixels) of bmp is correct, filesize is also ok. Other test: CapturePage and DrawCapturedPage works ok.
I prepared sample pdf file (from tif to pdf conversion -
http://ge.tt/1xKLujE/v/0?c - test2 2MB ).
Sometimes there are large area documents (scanned engineering documentation, for example 900x2000mm 300 dpi).
Any idea how to convert this large pdf to bmp file by QPL library?
I'm trying QPL Delphi dcu v8.13, Windows7x32, 4GB RAM.
Adam
Edit1:
Test with QPL 8.14b3
after DARenderPageToFile, DARenderPageToStream
Delphi5 say error: "Out of memory while expanding memory Stream"
Edit2
Delphi2006 say: in clas EOutOfMemory: "Out of memory"
Why? Other viewers and libraries can rasterize this file, slow, but rasterize.
Im know, this is only user-user forum, and library has only 3MB.
QPL is look good, composition (DrawCapturedPage) is very, very fast.
Only rendering.. Rendering for smaller area pdf (e.g, A1 format) is good, but greater has some problems.
Regards
|
Replies:
Posted By: ADev
Date Posted: 09 Mar 12 at 7:13PM
Sorry for post under post,
but there is hope, my workaround idea,
After some experiments on this (and another) sample, I got one of the idea:
QPL has functions for separate bitmap from pdf file (in my example this image is only one graphical object in pdf file)
My idea is functions GetPageImageList, SaveImageListItemDataToFile use, works ok).
This function extract image (jpg) from this pdf file, but this jpg also big image for pixel analyse.
I have to deal with large format scan and print (A0+ 300dpi)
Does anyone have experience with the analyse of large jpg files in Delphi (scan jpg format and analyze pixels?)
Only what I want, its detect "inked area" (for crop white margins on pdf file).
Im sorry for my poor english,
Regards,
Adam
|
Posted By: edvoigt
Date Posted: 11 Mar 12 at 3:02PM
Hi,
I think you need for analyzing a bitmap. In Delphi it is easy to convert a JPG to BMP:
var jpg: TJPEGimage; bmp: TBitmap; begin jpg := TJPEGimage.Create; jpg.LoadFromFile('E:\Projekt7\PDF_Investigator\test2.jpg'); bmp := TBitmap.Create; bmp.Assign(jpg); jpg.Free;
The Assign does the job, but it takes in your case on my PC 20 sec.
For analize you have to walk over the scanlines:
type TRGBTriple = packed record // short the names b: byte; g: byte; r: byte; end; TRGBArray = array[0..0] OF TRGBTriple; // for easier access var i, j, Row: ^TRGBArray; begin for j:=0 to BMP.Height-1 do begin // from top to bottom of BMP Row := bmp.Scanline[j]; for i:=0 to BMP.Width-1 // every pixel in line is a TRGBTriple do begin if (Row[ i].r<255) or (Row[ i].g<255) or (Row[ i].b<255) then begin // Pixel[ i,j] is not white // here you are outside of white borders end; end; end;
The code snippets are working but free of errorhandling!
On big images you'll get memory-problems. One idea against is to try to handle only part of the images. But I see no way to get for example only a top bar of a image, which is a little more than the assumed top border. All I tested in this background was running out of memory on other places. The jpg is as such in the PDF, so QPL makes no conversion.
Only two small steps, but in the right direction?
Werner
|
Posted By: ADev
Date Posted: 12 Mar 12 at 8:14AM
Thanks Werner,
yes, the right direction :)
After further experiments, I came to satisfactory results:
pseudocode:
if RenderPageToFile=False then
if (pdf_page has only one img) and (img.size=pdf_page.size [points]) then
begin
extract img (SaveImageListItemDataToFile)
LoadBigImg to TBitmap with resize to 72 dpi (without resizing is memory problem)
Analyze TBitmap
end
To load jpg with resize I'm found function:
function ResizeImage(sInImage, sOutImage: string; iHeight, iWidth: integer): boolean;
var JpgImg : TJpegImage;
BmpImg : TBitmap;
Rectangle: TRect;
begin
try
JpgImg := TJpegImage.Create;
BmpImg := TBitmap.Create;
JpgImg.LoadFromFile(sInImage);
Rectangle := Rect(0, 0, iWidth, iHeight);
with BmpImg do
begin
Width := iWidth;
Height := iHeight;
Canvas.StretchDraw(Rectangle, JpgImg);
>> Analyze TBitmap here or BmpImg.SaveToFile <<
end;
finally
// JpgImg.Assign(BmpImg);
// JpgImg.SaveToFile(sOutImage);
JpgImg.Free;
BmpImg.Free;
end;
Result := True;
end;
Yes, I used scanline method to analyze TBitmap.
If extracted image is jpeg image, for scanline important is also TBitmap.PixelFormat:=pf24bit; (oryginally assigned jpg has 32bit and white color has (255,0,255) r,g,b values )
I think that the problem is already solved, a little round,
partially pdf page rendering/rasterizing would be better.
Thank you for your interest, Werner
Regards,
Adam
|
Posted By: AndrewC
Date Posted: 12 Mar 12 at 12:43PM
10600 x 23600 pixels is a very large PDF file and QPL initially tries to render this at 24 bpp which requires 868MB. A 32bit EXE cannot safely handle this amount of memory.
The 64bit version of Quick PDF Library would be much better suited to this type of processing.
Andrew.
|
|