Updating PDF Producer throws an exception

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, 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
mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Updating PDF Producer throws an exception

Post by mmasood » Thu May 18, 2017 9:11 pm

Hi,

I am having an issue while updating the Producer of a PDF file. I am using Core Api and VB6 and this is happening for a particular set of files.

Following is the code that I am using for this:

Code: Select all

Public Function updateProducer(ByRef oCoreApi As clsCoreApi, ByRef pInst As PXC_Inst, sFileName As String, sProducer As String) As Boolean
    Dim pDoc As IPXC_Document
    
    On Error GoTo errorOccured
    
    ' load pdf file
    If Not oCoreApi.loadPdfFile(sFileName, pDoc, pInst) Then
        GoTo errorOccured
    End If
    
    ' update the pdf producer
    pDoc.Info.InfoStr(DocInfo_Producer) = sProducer
    
    ' save the pdf file
    oCoreApi.savePdfFile sFileName, pDoc
    
    Set pDoc = Nothing
    
    updateProducer = True
    Exit Function
    
errorOccured:
    If Not pDoc Is Nothing Then
        pDoc.Close
        Set pDoc = Nothing
    End If
    
    updateProducer = False
End Function
The line

Code: Select all

pDoc.Info.InfoStr(DocInfo_Producer) = sProducer
fails and goes to the error handler. The Err object shows the error description to be "Automation Error" and the error number is "-2112221168". I close out the document in the error handler block as you can see above.

The issue is that when that happens, my application throws a StackHeap exception after some time randomly. My questions are:

1. Is there a better way to do what I am trying to do here? If yes, can you share some VB6 code that I can use?
2. Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?
3. Is there a way that I can cleanup after the exception so that my application does not throw run time heap exceptions after this exception is thrown?

Looking forward to your response.

Regards,
M

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

Re: Updating PDF Producer throws an exception

Post by Sasha - Tracker Dev Team » Fri May 19, 2017 7:53 am

Hello mmasood,

I've updated the Forum Rules window for the Editor SDK and Core API forums - there is a link that might help you there.

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Updating PDF Producer throws an exception

Post by mmasood » Fri May 19, 2017 2:10 pm

Hi Alex,

I tried to implement the FormatHRESULT method that you suggested but I am getting the an error when i try to compile the code. I have attached a snapshot of the code and error.

1. Is there any other way to get the information that you asked for?
2. Can you look into the issue without the error code?

and the questions from the first post still remain:

1. Is there a better way to do what I am trying to do here? If yes, can you share some VB6 code that I can use?
2. Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?
3. Is there a way that I can cleanup after the exception so that my application does not throw run time heap exceptions after this exception is thrown?

Regards,
M
Attachments
HRESULT error.jpg

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

Re: Updating PDF Producer throws an exception

Post by Sasha - Tracker Dev Team » Fri May 19, 2017 2:25 pm

Hello mmasood,

Well it works here in our VB6 sample. The error itself means "Operation not permitted for the document.", that's why I asked you to look it up in the first place. This means that the document is protected and you cannot modify it unless you specify it's owner's password (or a valid certificate if it's the certificate security type).

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Updating PDF Producer throws an exception

Post by mmasood » Fri May 19, 2017 3:46 pm

Hi Alex,

This brings me back to my original question that I asked in the first post:

Is there a way the Core Api can tell me without throwing an exception that I cannot update the producer for a particular file? Any particular property/method that I can call before actually updating the producer?

What steps should i perform before changing the producer in order to know if the document is:

1. Password Protected
2. Invalid Certificate

Regards,
M

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

Re: Updating PDF Producer throws an exception

Post by Sasha - Tracker Dev Team » Mon May 22, 2017 1:42 pm

Hello mmasood,

Having an opened IPXC_Document you can use http://sdkhelp.tracker-software.com/vie ... Permission method to see whether the needed operation is permitted. In your case, you should check Perm_ObjDoc for Perm_OperModify.

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Updating PDF Producer throws an exception

Post by mmasood » Thu Aug 10, 2017 1:48 pm

Hi Alex,

I am trying to move the updating producer code to C# now. Following is a snippet of my code:

Code: Select all

    IPXS_Inst loPxsInst = pInst.GetExtension("PXS");
    IPXS_PDFVariant loVariant = loPxsInst.NewVar_String("Temp");
    // update the pdf producer
    loDoc.Info.SetInfoVar("DocInfo_Producer", loVariant);
The code above compiles correctly and even runs without any exception but does not update the Producer of the document. Can you take a look and let me know if there is anything wrong with the code?

Regards,
M

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

Re: Updating PDF Producer throws an exception

Post by Sasha - Tracker Dev Team » Thu Aug 10, 2017 3:03 pm

Hello mmasood,

Try changing the DocInfo_Producer to Producer and see whether it helps.

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

mmasood
User
Posts: 99
Joined: Fri Sep 18, 2015 9:49 pm

Re: Updating PDF Producer throws an exception

Post by mmasood » Thu Aug 10, 2017 3:35 pm

Hi Alex,

That did it. Thanks a lot. :)

Regards,
M

User avatar
Will - Tracker Supp
Site Admin
Posts: 6819
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

Re: Updating PDF Producer throws an exception

Post by Will - Tracker Supp » Thu Aug 10, 2017 3:45 pm

:D
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

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com

Post Reply