Page 1 of 1

Read Field Values into Excel

Posted: Fri Feb 21, 2020 5:49 pm
by Thayana1977
Hello All,

I am very new to PDF X-Change Editor. I have downloaded the PDF X-Change Editor Type Library and the PDF X-Change PDF Core Library. I am trying to write VBA to read the values of fields in PDF X-Change Editor form and then I'll write those values to Excel. I have added the references in Excel to these libraries. I am confused on how to open the document and get it as a PDFXEdit.IPXC_Document object. Below is my snippet. It fails on the opendocfrompath method. Any help is very much appreciated.

Thank you!

Thayana

Option Explicit


Private mobjPDFCtl As PDFXEdit.PXV_Control
Private mobjPDFInst As PDFXEdit.PXV_Inst
Private mobjPDFDoc As PDFXEdit.IPXC_Document
Private mobjFormField As PDFXEdit.IPXC_FormField
Private mstrText As String
Private Const strPath As String = "2019 Smith, Joan.pdf"
Private strRelPath As String


Sub Init()
Set mobjPDFCtl = New PDFXEdit.PXV_Control
Set mobjPDFInst = mobjPDFCtl.Inst

strRelPath = ThisWorkbook.Path & "\" & strPath

Set mbojPDFDoc = mobjPDFCtl.OpenDocFromPath(strRelPath)

Set mobjFormField = mobjPDFDoc.AcroForm.GetFieldByName("Text1")
mstrText = mobjFormField.GetValueText
End Sub

Re: Read Field Values into Excel

Posted: Sat Feb 22, 2020 12:35 pm
by Sasha - Tracker Dev Team
Hi Thayana,

I think you only will have to open the IPXC_Document vial the Core API level, without the usage of the Editor Level SDK. You can check out the CoreAPIDemo application that comes in the Samples package along with the Core API SDK - it holds practical usage samples that are frequently being updated.

Cheers,
Alex

Re: Read Field Values into Excel

Posted: Sun Feb 23, 2020 6:30 pm
by Thayana1977
Hello Alex,

I tried doing this by looking at the C# code for opening a document and then converting to vb in my Excel document. I have the reference set to the PDF-Xchange PDF Core API Library. I am still getting an error on the line to open the file that an object is needed. I am not sure what I am going wrong. Below is my code. Any help is much appreciated. I am not sure what else to try at this point, but it certainly seems that I should be able to open a document and read a field from the AcroForm according to the documentation.

Thank you!

Thayana


Option Explicit


Private mstrText As String
Private Const strPath As String = "2019 Smith, Joan.pdf"
Private strRelPath As String

Private mobjPDFInst As PDFXCoreAPI.PXC_Inst
Private mobjPDFDoc As PDFXCoreAPI.IPXC_Document
Private mobjFormField As PDFXCoreAPI.IPXC_FormField


Sub Init()
Set mobjPDFInst = New PXC_Inst

strRelPath = ThisWorkbook.Path & "\" & strPath

Set mobjPDFDoc = mobjPDFInst.OpenDocumentFromFile(strRelPath, Null)


Set mobjFormField = mobjPDFDoc.AcroForm.GetFieldByName("Text1")
mstrText = mobjFormField.GetValueText
End Sub

Re: Read Field Values into Excel

Posted: Mon Feb 24, 2020 7:53 am
by Sasha - Tracker Dev Team
Hi Thayana1977,

Make sure that you are looking at the samples very carefully. You will have to initialize the instance first and finalize it at the end of your program. For more info see this link:
https://sdkhelp.tracker-software.com/view/PXV:PXC_Inst

Cheers,
Alex

Re: Read Field Values into Excel

Posted: Mon Feb 24, 2020 10:32 pm
by Thayana1977
Thanks, Alex. I tried again. I tried the Init passing the GUID for the Core API as given in the documentation both with and without the {}. I still get an "Object Not Found" error on the " Set mobjPDFDoc = mobjPDFInst.OpenDocumentFromFile(strRelPath, Null)" line. The documentation online only goes as far as below for VB6. That being said I think I should be able to call the init right after the set in the example. Any other ideas that I should try? Thanks again! Thayana

Dim pdfInst As PDFXCoreAPI.PXC_Inst
...
Set pdfInst = New PDFXCoreAPI.PXC_Inst



My code:

Option Explicit


Private mstrText As String
Private Const strPath As String = "2019 Smith, Joan.pdf"
Private strRelPath As String

Private mobjPDFInst As PDFXCoreAPI.PXC_Inst
Private mobjPDFDoc As PDFXCoreAPI.IPXC_Document
Private mobjFormField As PDFXCoreAPI.IPXC_FormField


Sub Init()
Set mobjPDFInst = New PXC_Inst
mobjPDFInst.Init ("{D37FFAC6-B7ED-441E-B933-19B4E57FCB60}")

strRelPath = ThisWorkbook.Path & "\" & strPath

Set mobjPDFDoc = mobjPDFInst.OpenDocumentFromFile(strRelPath, Null)

Set mobjFormField = mobjPDFDoc.AcroForm.GetFieldByName("Text1")
mstrText = mobjFormField.GetValueText
mobjPDFInst.Finalize
End Sub

Re: Read Field Values into Excel

Posted: Tue Feb 25, 2020 7:51 am
by Sasha - Tracker Dev Team
Hi Thayana1977,

The instance should be initialized with the key that you can buy if everything meets your requirements for proper SDK usage, not the GUID of the interface.
Anyway, what you should do is search the forums for VB topics - there are plenty of answers there and also some sample projects included that should help. The VB can give some unexpected errors that we cannot expect (for example it can be that you are passing the Null value directly or something like that).

Cheers,
Alex

Re: Read Field Values into Excel

Posted: Tue Feb 25, 2020 11:15 am
by Thayana1977
Hi Alex,

Thanks for the info. I did search the forums but didn’t see anything written in VB for what I was trying to do. I will try looking again.

Thank you,

Thayana

Re: Read Field Values into Excel

Posted: Tue Feb 25, 2020 11:53 am
by Sasha - Tracker Dev Team
:)