DrawToIXCPage

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
jeffp
User
Posts: 857
Joined: Wed Sep 30, 2009 6:53 pm

DrawToIXCPage

Post by jeffp » Tue Sep 06, 2016 5:16 pm

I'm using the code below to draw an IPXC_Page to an IIXC_Page.

Itthen convert the IIXC_Page into a TBitmap in Delphi followed by a TBitmap.SaveTo File and then TBitmap.Free;

So I'm freeing the TBitmap before a go to the next page.

However, looping through the code below for each page in the PDF starts to Bloat my application. It appears that DrawToIXPage is the culprit. The only thing that seems to free all the memory bloat is when I close the IPXC_Document document from which I got the IPXC_Page.

Is there anything that can be done about the memory bloat when using DrawToIXPage?

Code: Select all

function PDF_CreateIXCPageFromPage(APage: IPXC_Page; ASize: Integer; var ADPI: Integer): IIXC_Page;
var
  AWidth, AHeight: Double;
  W, H: Cardinal;
  ADestRect: tagRECT;
  APageMatrix: PXC_Matrix;
  AFlags: Integer;
  ARenderParams: IPXC_PageRenderParams;
  AOCContext: IPXC_OCContext;
begin
  //Get Page dimensions in Points
  APage.GetDimension(AWidth, AHeight);

  //Make Sure the Image is not Too Big
  if (AHeight > AWidth) then
  begin
    if (P2X(AHeight, 100) > 4400) or (P2X(AWidth, 100) > 3400) then ADPI := 100;
  end else
  begin
    if (P2X(AWidth, 100) > 4400) or (P2X(AHeight, 100) > 3400) then ADPI := 100;
  end;

  //Convert to Pixes
  ADPI := Max(100, ADPI);
  W := Round(P2X(AWidth, ADPI));
  H := Round(P2X(AHeight, ADPI));

  if (ASize <= 0) then ASize := Max(H, W);

  if (H > W) then
  begin
    W := Ceil(ASize * (W / H));
    H := ASize;
  end else
  begin
    H := Ceil(ASize * (H / W));
    W := ASize;
  end;

  with ADestRect do
  begin
    Left := 0;
    Top := 0;
    Right := W;
    Bottom := H;
  end;

  //Defaults
  AFlags := DDF_AsVector;
  ARenderParams := nil;
  AOCContext := nil;
  APageMatrix := PDF_GetPageMatrix(APage, ADestRect);

  INST_IXC.Page_CreateEmpty(W, H, PageFormat_8RGB, 255, Result);   //PageFormat_8RGB, PageFormat_1Indexed
  APage.DrawToIXCPage(Result, ADestRect, APageMatrix, ARenderParams, AOCContext, nil);
end;


User avatar
Sasha - Tracker Dev Team
User
Posts: 4326
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToIXCPage

Post by Sasha - Tracker Dev Team » Wed Sep 07, 2016 11:27 am

Hello Jeff,

This happens because you don't release the IIXC_Page pointer thus the problem occurs. Please provide us with a small working project so we can see how are you using it and how to release it properly.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 857
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage

Post by jeffp » Wed Sep 07, 2016 4:25 pm

I do set the IIXC_Page object to nil when I'm done with it. Is there a better way to release it?

APage := nil;

--Jeff

User avatar
Sasha - Tracker Dev Team
User
Posts: 4326
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToIXCPage

Post by Sasha - Tracker Dev Team » Wed Sep 07, 2016 4:31 pm

Hello Jeff,

The thing is that Delphi does not have such a good memory management as C++ thus sometimes it may not be that simple. That's why I am asking for a small working project so that we can debug it and find a solution for this case.

Cheers,
ALex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jeffp
User
Posts: 857
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage

Post by jeffp » Wed Sep 07, 2016 6:30 pm

It looks like I have it working pretty good now. The memory seems to increase only to a certain point. After about 80 pages or so it seems to level out so I'm good with that.

By the way, any word on when the next official build will be out. That last one I'm on now was way back in April.

--Jeff

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: DrawToIXCPage

Post by John - Tracker Supp » Thu Sep 08, 2016 8:04 am

Hi Jeff,

Its being tested now - so 7-10 days approx.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply