file handle

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
dansch
User
Posts: 3
Joined: Wed May 17, 2006 11:55 am

file handle

Post by dansch » Mon Jun 12, 2006 2:41 pm

hi,

i use the pdf-tools mainly for adding watermarks to existing pdf documents. in this context my problem is occurred. If i have opened a pdf for instance with Acrobat Reader and add a watermark to it i can not delete the file anymore, even if i close the acrobat reader afterwards. But when i close the application which added the watermark i can delete the file.

Is there any chance to bypass this phenomenon?

thank you!

best regards
Daniel Schmidt

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 » Mon Jun 12, 2006 3:00 pm

Hi,

This is a strange problem - can you please advise step by step your process and perhaps include the code snippet where you actually write the revised PDF please ?

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

dansch
User
Posts: 3
Joined: Wed May 17, 2006 11:55 am

Post by dansch » Mon Jun 12, 2006 3:20 pm

thank you for your absolutely fast answer!

here is a code snippet (without error handling) which raises the problem:

Code: Select all

 'Open the Doc
 lngRes = PXCp_Init(lngPdf, xxx,xxx)
 lngRes = PXCp_ReadDocumentW(lngPdf, StrConv(strFile, vbUnicode), 0)

 'Adjust the Type
 typWzTxt.m_Type = 0
 typWzTxt.m_Align = &H1 + &H10
 typWzTxt.m_Size = 1280
 typWzTxt.m_Angle = 45
 typWzTxt.m_PlaceType = 0
 typWzTxt.m_PlaceOrder = 1
 typWzTxt.m_Opacity = bytOpacity
 typWzTxt.m_FontSize = 72
 typWzTxt.m_Mode = &H0
 typWzTxt.m_LineWidth = 1
 typWzTxt.m_FColor = 0
 Call fctStr2IntArray(strWzText, typWzTxt.m_Text, True)

 'Add the watermark
 lngErgebnis = PXCp_AddWatermark(lngPdf, typWzTxt)

 'Rewrite the doc
 lngRes = PXCp_WriteDocumentW(lngPdf, StrConv(strFile, vbUnicode), 2, 0)
 
I tried the same with your vb-demo. Open the pdf in the Acrobat Reader, add the watermark with you app (same in- and output-file), close the Reader and .... there it is!

greetings
Daniel Schmidt

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 » Mon Jun 12, 2006 3:27 pm

Thanks Daniel,

I have put this to the project manager for the xcpro35 library to investigate and will respond as soon as I have his reply.

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 » Tue Jun 13, 2006 8:35 am

Hi Daniel,

The Problem is caused because errors are not correctly handled in the the specified code, especially after the call to the PXCp_WriteDocumentW function:

When the function PXCp_WriteDocumentW successfully write's the resulting document and no PXCp_Write_NoRelease flag is specified it attempts to release the pdf document handle (lngPdf in your sample).

This attempts to automatically release the source pdf file, so it can be deleted. But if it fails - however it doesnt release the pdf document handle, so the pdf file remains locked!

Because the source pdf file is also open in Acrobat Reader by the user, it cannot be overwritten so PXCp_WriteDocumentW return's an error that the pdf document handle is not released.

Also, not only does the file remain locked, but a memory leak also occurs.

To correct this you will need to handle errors more appropriately, especially add a check after opening a file and writing and in the event a PXCp_WriteDocumentW function fails (or PXCp_Write_NoRelease flags is specified) you must release the handle of the pdf document using the PXCp_Delete function.

I have also asked our VB developer to add this to our sample as soon as time allows.

Hope that helps.
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