DrawToIXCPage

PDF-XChange Editor SDK for Developers

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

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: 914
Joined: Wed Sep 30, 2009 6:53 pm

DrawToIXCPage

Post by jeffp »

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;

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

Re: DrawToIXCPage

Post by Sasha - Tracker Dev Team »

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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage

Post by jeffp »

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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: DrawToIXCPage

Post by Sasha - Tracker Dev Team »

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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DrawToIXCPage

Post by jeffp »

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
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom
Contact:

Re: DrawToIXCPage

Post by John - Tracker Supp »

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