Drawing page to bitmap seems to be frozen  SOLVED

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

DDi
User
Posts: 4
Joined: Wed Jan 28, 2015 11:24 am

Drawing page to bitmap seems to be frozen

Post by DDi »

I have a PDF file with one page. I would like to draw this page to a bitmap and use it as a input parameter.

Before calling PXCV_DrawpageToDC I get the page dimensions via PXCV_GetPageDimensions.

This results in a width of 7017 points and a height of 9933 points. Drawing it to a bitmap and using it as a input parameter for PXCV_DrawPageToDC results in a 'frozen' state. The function will not give a result.

Code sample in Delphi (2010), used DPI is 300:

Code: Select all

PXCV_GetPageDimensions(aPXCVDocument, 0, lPagePointsWidth, lPagePointsHeight);

lBitMap := TBitmap.Create;
try
  lBitmap.Canvas.Lock;
  try
    lRect := Rect(0, 0, Round((lPagePointsWidth / 72) * DPI), Round((lPagePointsHeight / 72) * DPI));
    lBitMap.Height := lRect.Bottom;
    lBitMap.Width := lRect.Right;
    lPXVParams.WholePageRect := @lRect;
    lPXVParams.DrawRect := nil;
    lPXVParams.Flags := 0;
    lPXVParams.RenderTarget := 0;
    
    PXCV_DrawPageToDC(aPXCVDocument, idx, lBitmap.Canvas.Handle, lPXVParams);
  finally
    lBitmap.Canvas.UnLock;
  end;
finally
  lBitMap.Free;
end;
The line "PXCV_DrawPageToDC" does not give a result, it seems to be frozen. I stopped the program after 48 hours without results.

OS: windows 8.1
Memory: 16 GB
Processor: Intel Xeon W3565 Quad Core @ 3.20 GHz
Programming language: Delphi (2010)

Is there a maximum size for a bitmap to get a result of PXCV_DrawpageToDC?

Any help is appreciated.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Drawing page to bitmap seems to be frozen

Post by Stefan - PDF-XChange »

Hello DDi,

Welcome to our forums.
You are trying to render in one go an almost 100 x 140 inch page at 300DPI - the resulting bitmap will be huge!
I had a quick chat with a colleague from the dev team and he is not sure if this can be handled by a 64 Bit OS at all.
32 bit will certainly not be able to as you will need about 4.5GB of RAM. If you try to create this with 32 bit code - we can not predict what the results would be. 64 bit code run on 64 bit OS should be able to render bitmaps so large - it will be slow but it certainly should not take 48 hours.

The proper solution would be to split the page into much smaller chunks and render them separately.
You can see a reply to a similar case by that same colleague I consulted here:
https://forum.pdf-xchange.com/ ... 820#p48820

Regards,
Stefan
DDi
User
Posts: 4
Joined: Wed Jan 28, 2015 11:24 am

Re: Drawing page to bitmap seems to be frozen

Post by DDi »

Hello Stefan,

I am sorry, but I made a mistake. The height in points is 2384 and the width in points is 1684. In pixels the height is 7017 and the width 9933. Is that still a problem or should it be possible to draw it to a bitmap with the function PXCV_DrawpageToDC?

Regards,

Dennis
Last edited by DDi on Thu Jan 29, 2015 9:03 am, edited 1 time in total.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Drawing page to bitmap seems to be frozen

Post by Stefan - PDF-XChange »

Hi Dennis,

That is still close to 70 million pixels that you need to render. and the memory required will be 280-300MB and as per the other topic I linked - Victor (LazyCat) explains that anything larger than 128 MB will be also using some temp file on disk.

Make a test with your file and 100 DPI - this should require less than 128 MB of RAM and minimal code changes to test.
If it works - and to make sure rendering is kept in memory only - I would recommend you to consider optimizing your code so that it splits the rendering to smaller blocks (e.g. 2000 x 2000 px)

Regards,
Stefan
DDi
User
Posts: 4
Joined: Wed Jan 28, 2015 11:24 am

Re: Drawing page to bitmap seems to be frozen

Post by DDi »

Hi Stefan,

tests with 100 and 200 dpi works, I still need the 300 dpi in my case. I will test the solution mentioned in the other topic. I will let you the results.

Regards,

Dennis
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Drawing page to bitmap seems to be frozen

Post by Stefan - PDF-XChange »

:)
DDi
User
Posts: 4
Joined: Wed Jan 28, 2015 11:24 am

Re: Drawing page to bitmap seems to be frozen

Post by DDi »

Hi Stefan,

splitting up the page in parts works, thanks for your help.

Regards,

Dennis
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19868
Joined: Mon Jan 12, 2009 8:07 am

Re: Drawing page to bitmap seems to be frozen

Post by Stefan - PDF-XChange »

:)