Memory problems using PDF XChange from a Delphi program

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics.

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Support Staff, moderators

Post Reply
kenbla
User
Posts: 64
Joined: Wed Jun 21, 2006 1:29 pm

Memory problems using PDF XChange from a Delphi program

Post by kenbla » Tue Sep 05, 2006 11:53 am

Hello,
I'm currently testing a Delphi batch program (version 6) that is using PDF XChange for the following:
1. Read an existing PDF document
2. Extract certain pages from it
3. Create a new PDF document with the selected page range
4. Add a watermark to it
5. Release the documents.

The program loops through a database and processes a lot of rows in a database and for each row it performs the functionality in items 1-5.
Everything works fine except for one thing! The program uses a lot of memory and I think it is because of the way I create my PDF documents. I'm using PXCp_delete when I'm done with the process of the new PDF documents and I also delete my source PDF document in each iteration.

At the bottom of this mail you will find my PDF XChange code that I have used in my program.
I have tested different ways to create my PDF documents, using PXCp_Write_Release and PXCp_Write_NoRelease in the parameter list to the PXCp_WriteDocumentW function. When I used the PXCp_Write_NoRelease parameter I also ran the PXCp_Delete function, but I still had the same memory problems!

I would appreciate if you could assist me with this problem!

Best regards,
Kenbla

pxRC := PXCp_Init(@hSourcePDFDocument, pxLicense, pxDevcode);
.
.
.
pxRC := PXCp_ReadDocumentW(hSourcePDFDocument, PWChar(WideString(sTempPath + '\PDFSource.pdf')), 0); //Read the Source PDF document

pxRC := PXCp_Init(@hNewPDFDocument, pxLicense, pxDevcode);
.
Code to select start/end page from the source document
.
pxRange.StartPage := iPageFrom - 1 ;
pxRange.EndPage := iPageTo - 1;
pxRange.InsertBefore := -1;
pxRC := PXCp_InsertPagesTo(hSourcePDFDocument, hNewPDFDocument, @pxRange, 1, 0);
.
.
.
pxRC := PXCp_Delete(hSourcePDFDocument); //Release the source PDF file

//Settings for the creation of a watermark for the new PDF document
pxWatermark.m_Size := sizeof(PXC_Watermark);
pxWatermark.m_PlaceOrder := PlaceOrder_Background;
pxWatermark.m_PlaceType := PlaceType_AllPages;
pxWatermark.m_Align := TextAlign_Bottom;
pxWatermark.m_FontSize := 10;
pxWatermark.m_Type := WaterType_Text;
pxWatermark.m_Opacity := 128;
pxWatermark.m_bKeepAspect := FALSE;
pxWatermark.m_Width := 0.0;
pxWatermark.m_Height := 0.0;
pxWatermark.m_Angle := 0.0;
pxWatermark.m_bItalic := false;
pxWatermark.m_SColor := RGB(255, 0, 0);
pxWatermark.m_FColor := RGB(0, 255, 0);
pxWatermark.m_Mode := TextRenderingMode_FillStroke;
StringToWideChar(sWatermark, pxWatermark.m_Text, 255);
pxRC := PXCp_AddWatermark(hNewPDFDocument, @pxWatermark);
pxRC := PXCp_WriteDocumentW(hNewPDFDocument, PWChar(WideString(sFilNamn)), PXCp_CreationDisposition_Overwrite, PXCp_Write_NoRelease);
pxRC := PXCp_Delete(hNewPDFDocument); //Release the created PDF file from memory
Regards,
Kenbla

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

Post by John - Tracker Supp » Tue Sep 05, 2006 4:11 pm

Hi,

I have passed this to our Delphi project dev and as soon as I have his feedback I will reply - I suspect it will be tomorrow however now as it is already past closing in our Ukraine Dev office, where he is based.

Thanks for your patience.
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

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

Post by John - Tracker Supp » Thu Sep 07, 2006 6:09 pm

Hi,

Please see the attached project - this must be extracted to the delphi project folder in your PDF-XChange SDK install, to ensure that all the required and required project files are available.

Our Delphi dev in house says :
This test project in batch mode (working with approx 1000 files) did not use significant amounts of memory

Maybe the clients application has some error in his code or a specific problem PDF, if so we would need to see a complete sample project - both compiled and with the project source and the PDF in question to advise further.

Also he could perhaps test by commenting all calls to our SDK and try to run his application program in batch mode and check the resources used etc.
HTH
Attachments
SDKExamples.zip
Delphi Example
(9.57 KiB) Downloaded 151 times
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

kenbla
User
Posts: 64
Joined: Wed Jun 21, 2006 1:29 pm

Post by kenbla » Fri Sep 08, 2006 7:12 am

Thanks for your reply but I didn't quite understand it!

I simply want to know if the PDF XChange code in my Delphi program seems to be OK from your point of view. The program reads the PDF file correctly and creates hundreds of files correctly but it uses an increasing amount of memory for each iteration and that is a big concern to me! It seems as if memory is not released after each iteration as it should, probably because of some bad code in my program but I can't find the problem!
This is what the program does:
1. Read an existing PDF document
2. Extract certain pages from it
3. Create a new PDF document with the selected page range
4. Add a watermark to it
5. Release the documents (or at least try to!).

The program loops through a database and processes a lot of rows in a database and for each row it performs the functionality in items 1-5.

Here are some of my questions to you:
- Should my program perform a PXCp_init for the two PDF files (source and target) in each iteration? or can that be done once at the beginning of the program?
- In the PXCp_WriteDocumentW function should I use PXCp_Write_Release or PXCp_Write_NoRelease parameter?
- When do I need to run the PXCp_Delete function?
- How do I release memory used by PDF XChange in my program?

I have tested a lot of different ways but I would appreciate your guidance.
Best regards,
Kenbla
Regards,
Kenbla

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

Post by John - Tracker Supp » Fri Sep 08, 2006 3:26 pm

Hi,

1:
It seems as if memory is not released after each iteration as it should, probably because of some bad code in my program but I can't find the problem!
Please check your code - because in the code you provide all calls to PXCp functions appear to be correct and in the correct sequence.

It would appear the problem is in code that does not relate to PXCp functions.

It is a simple task to check this as I detailed previously - you should comment out all the PXCp function call's and make some small changes in your code to accomodate this so the program can flow as usual.

If memory usage grows - the problem is not in code related to our libraries - if the memory appears stable - in a methodical manner uncomment PXCp functions step by step and try again, and so on until the problem is isolated.

2:
- Should my program perform a PXCp_init for the two PDF files (source and target) in each iteration? or can that be done once at the beginning of the program?
You must call the PXCp_Init function twice - because the PXCp_ReadDocumentW function requires the handle of an empty PXCp docment and you need to copy some pages into this empty document also.

3:
- In the PXCp_WriteDocumentW function should I use PXCp_Write_Release or PXCp_Write_NoRelease parameter?
It may be used with both of these parameters. the recomended way is to use it with the PXCp_Write_NoRelease paramter (the pdf document will not be released if used in this way) and afterwards call the PXCp_Delete function.

If you are using the PXCp_WriteDocumentW function with the PXCp_Write_Release parameter it will release the document when the writing operation is successful and NOT release if it fais - so in the case of a failure you must release the document using the PXCp_Delete function.

4:
When do I need to run the PXCp_Delete function?


For each document created using the PXCp_init function, except in this specific instance - when you have called the PXCp_WriteDocumentW function with the PXCp_Write_Release flag and it was successful (in this case it will release the specific document before exiting).

5:
How do I release memory used by PDF XChange in my program?
You do not need to release this memory (and you are not able to do this). The xcpro35 library uses memory only for document data and automatically free's it when you release the document (using the PXCp_Delete function, or after a successful call to the PXCp_WriteDocumentW function with the PXCp_Write_Release flag).

So if you always release documents created by the PXCp_init function xcpro35 will tidy up and free on your behalf.

+++++++++++++

Should you still have problems - it is essential you prepare a demo app showing these problems (as small and compact as possible) and supply this for us to check and debug as necessary - otherwise it is going to be impossible for us to help you resolve comprehensivley in a mutually acceptable manner.

We would need both the project source and a compiled application with all required supporting files and some simple step by step instructions to allow us to reproduce.

HTH
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

kenbla
User
Posts: 64
Joined: Wed Jun 21, 2006 1:29 pm

Post by kenbla » Tue Sep 12, 2006 11:47 am

Hello,
Thanks for your excellent comments!

I have now run some additional test of my batchprogram and it appears as if it is more efficient, when it comes to memory usage, to use the PXCp_Write_NoRelease parameter in the PXCp_WriteDocumentW function followed by an explicit PXCp_Delete.

During my tests I have found out that when the explicit PXCp_Delete function is called memory usage drops a bit, but when I use the PXCp_WriteDocumentW with the PXCp_Write_Release parameter (without the explicit PXCp_Delete) memory usage is actually increased!! at least in my application.

Best regards,
Kenbla
:D
Regards,
Kenbla

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

Post by John - Tracker Supp » Tue Sep 12, 2006 11:55 am

Hi,

Pleased you made some progress.

Would be happy to look at this and advise further if you could provide a sample project (source and compiled) with any supporting files and some simple instructions

Please zip any files posted - and please do not inlcude your license info in any source files uploaded.

thanks
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