Kofax power PDF VBA dll reference - vba

Just wanted to add information on the below post (but seems I cant).
https://safeweb.hsbcpb.com/https://stackoverflow.com/questions/39269911/nuance-power-pdf-automation-using-excel-vba-macro
The reference is now:
"C:\Program Files (x86)\Kofax\Power PDF 31\bin\PDFCore8_x64.dll"
even if called powerPDF and the documentation said so to create the with "powerdpdf.app", the following code work fine for me (just in case someone was looking for a solution like I did).
Function copy_pdf_values_wiht_nuance(path As String) As String
Dim PDFApp As Object
Dim dvOpenDoc As Object
Dim ddDoc As Object
Set PDFApp = CreateObject("nuancePDF.App")
Set dvOpenDoc = CreateObject("nuancePDF.DVDoc")
If dvOpenDoc.Open(path) = False Then
PDFApp.Exit
Exit Function
End If
Set ddDoc = dvOpenDoc.GetDDDoc()
PDFApp.MenuItemExecute ("SelectAll")
PDFApp.MenuItemExecute ("Copy")
PDFApp.Exit
'Set ddPage = ddDoc.AcquirePage(0)
'Set hl = CreateObject("NuancePDF.HiliteList")
'hr = hl.Add(12, 1)
'hr = hl.Add(52, 2)
'Set ts = ddPage.CreatePageHilite(hl)
'hr = dvOpenDoc.SetTextSelection(ts)
'dvOpenDoc.ShowTextSelect
Dim clipboard As MSForms.DataObject
Dim strContents As String
Set clipboard = New MSForms.DataObject
clipboard.GetFromClipboard
strContents = clipboard.GetText
copy_pdf_values_wiht_nuance = strContents
End Function
Copy and paste content of a PDF, having had the wrong reference.

Related

vbCFBitmap Variable Not defined

I am using MS-Access 2007 VBA.
I am attempting to convert a pdf to an image. I found this chunk of code online, but they failed to provide all the references. My compile is failing on vbCFBitmap. Does anyone know where this reference comes from?
Dim MyAcro As New AcroApp
Dim MyPDF As New AcroPDDoc
Dim MyPage As AcroPDPage
Dim MyPt As acrobat.AcroPoint
Dim MyRect As AcroRect
Dim MyData As DataObject
Dim strPathString As String
Dim MyPath As String
Dim SaveToPath As String
Dim mysavepath As String
MyPath = "\\spfs1\stone\Long Term Share\gentex_ppaps\gentex_ppaps_raw\Supplier Request Number 3034910, Gentex Part Number 345-2120-000 Revision (003).pdf"
mysavepath = "C:\out"
' open the PDF
MyPDF.Open (MyPath)
Set MyPage = MyPDF.AcquirePage(0)
' Convert Point to Twips for document
Set MyPt = New AcroPoint
'Define the rectangle that contains the PDF form
Set MyRect = New acrobat.AcroRect
MyRect.Top = 0
MyRect.Left = 0
MyRect.Right = MyPt.x
MyRect.bottom = MyPt.y
' Copy the PDF image to the clip board
Call MyPage.CopyToClipboard(MyRect, MyRect.Left, MyRect.Top, 100)
' Capture image from clip board to data object
Set MyData = Clipboard.GetData(vbCFBitmap)
'Save the data object
SavePicture MyData, mysavepath
' Clean up
Set MyAcro = Nothing
Set MyPDF = Nothing
Set MyPage = Nothing
Set MyPt = Nothing
Set MyRect = Nothing
Set MyData = Nothing
That's likely VB6 code, not VBA.
vbCFBitmap is a system global, and thus not imported using any references.
However, that's just a copy of the Windows Standard Clipboard Formats, thus vbCFBitmap is equal to 2. You can use 2 instead.

Populate PDF Combo Box Via VBA

I have the below code to populate a combobox in a PDF document. As far as I can tell, the code is correct, according to the Acrobat Forms API Reference
However the code fails on the PopulateListOrComboBox call with this error:
Method 'PopulateListOrComboBox' of object 'IField' failed
Dim acroApp As Acrobat.acroApp
Set acroApp = New Acrobat.acroApp
Dim myForm As Acrobat.AcroAVDoc
Set myForm = New Acrobat.AcroAVDoc
Dim bOK As Boolean
bOK = myForm.Open("C:\Users\sholtzman\downloads\wordFormTest.pdf", "temp")
Dim theRealForm As AFORMAUTLib.AFormApp
Set theRealForm = New AFORMAUTLib.AFormApp
Dim pdField As AFORMAUTLib.Field
Set pdField = theRealForm.Fields.Add("triaCoverage", "combobox", 0, 10, 20, 100, 200)
Dim items(2) As String
items(0) = " "
items(1) = "Accept"
items(2) = "Reject"
pdField.PopulateListOrComboBox items
Furthermore, I tested this piece of code as well to try to fill it, but it also failed with the error:
Automation error Unspecified error
Dim myPDForm As Acrobat.AcroPDDoc
Set myPDForm = myForm.GetPDDoc
Dim jso As Object
Set jso = myPDForm.GetJSObject
jso.getField("triaCoverage").setItems(1) = " "
Lastly, when I save and close the document after adding the combobox, I can go in
and set list values manually. Any ideas how I can get this to work through code?
I did some more research and have found one answer just now by replacing the line:
jso.getField("triaCoverage").setItems(1) = " "
with
jso.getField("triaCoverage").setItems(items)
However, I prefer to use the PopulateListOrComboBox method if at all possible, so i will leave this unanswered for some time.

How to read the content of an online PDF file into a string variable using VBA?

I am wondering if anyone has dealt with this before. I have a spreadsheet with links to thousands of pdf files. I would like to load the content of each pdf into a string variable and run a few RegEx to extract useful data. I have the function shown below which loads the content of a pdf file into a string, however this function only works for local files. However in my case I am opening the pdf file using IE.Navigate2 "https://www.example.com/mypdf.pdf" this will open the pdf in the browser, how can I load the content of that file into a string. The extreme solution would be to download the file and open it with the function below and then delete it. Please let me know your thoughts. Please note that the function below will only work if you have Acrobat installed (not the reader) you will also will need to add the reference in the VBA project to Adobe Acrobat Type Library
Public Function ReadAcrobatDocument(strFileName As String) As String
Dim AcroApp As CAcroApp, AcroAVDoc As CAcroAVDoc, AcroPDDoc As CAcroPDDoc
Dim AcroHiliteList As CAcroHiliteList, AcroTextSelect As CAcroPDTextSelect
Dim PageNumber, PageContent, Content, i, j
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open(strFileName, vbNull) <> True Then Exit Function
' The following While-Wend loop shouldn't be necessary but timing issues may occur.
While AcroAVDoc Is Nothing
Set AcroAVDoc = AcroApp.GetActiveDoc
Wend
Set AcroPDDoc = AcroAVDoc.GetPDDoc
For i = 0 To AcroPDDoc.GetNumPages - 1
Set PageNumber = AcroPDDoc.AcquirePage(i)
Set PageContent = CreateObject("AcroExch.HiliteList")
If PageContent.Add(0, 9000) <> True Then Exit Function
Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
' The next line is needed to avoid errors with protected PDFs that can't be read
On Error Resume Next
For j = 0 To AcroTextSelect.GetNumText - 1
Content = Content & AcroTextSelect.GetText(j)
Next j
Next i
ReadAcrobatDocument = Content
AcroAVDoc.Close True
AcroApp.Exit
Set AcroAVDoc = Nothing: Set AcroApp = Nothing
End Function

Export single CATIA body from CATPart as stl using VBA macro

Is it possible to export a single CATIA body as STL without creating a separate part with it?
For the time being, I have coded a script which loops through the CATParts present in a folder, fetches the contained bodies and create a single CATPart with each of them and export into stl format.
Dim output_stl_path_HD As String
Dim output_stl_path_MD As String
Dim output_stl_path_SD As String
Dim output_stl_path_via_points As String
Dim output_transformations_path As String
Dim input_path As String
Sub CATMain()
'Path for output file
input_path = CATIA.ActiveDocument.path + "\"
Dim it As Integer
Dim prod As Product
Dim t_p_ref(11)
'List of part names to export
Dim list As Collection
Set list = New Collection
'GET LIST OF CATPART IN FOLDER
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder(input_path)
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
If (InStr(objFile.path, ".CATPart")) Then
list.Add (objFile.name)
' Set objDocument = CATIA.Documents.Open(objFile.path)
Dim srcDoc As PartDocument
Set srcDoc = CATIA.Documents.Open(objFile.path)
Dim srcPart As Part
Set srcPart = srcDoc.Part
Dim oSel As Selection
Dim bodies1 As Bodies
Dim body1 As body
'
Set bodies1 = srcPart.Bodies
For Each single_body In srcPart.Bodies
A = exportStl(single_body)
Next
Set body1 = srcPart.Bodies.Item(i)
'Dim BoxProduct
'BoxProduct = MsgBox("Quantity of the bodies found:" & srcDoc.Part.Bodies.Count & "", 64)
End If
Next
End Sub
Public Function exportStl(ByVal myBody As body)
Dim oSrc As Part
Dim oTgt As Part
Dim oSrcDoc As PartDocument
Dim oTgtDoc As PartDocument
Dim oBod As body
Dim oSel As Selection
'Sets documents for Source and Target files
Set oSrcDoc = CATIA.ActiveDocument
Set oTgtDoc = CATIA.Documents.Add("Part")
oTgtDoc.Product.PartNumber = myBody.name
'Gets Body to copy
Set oSrc = oSrcDoc.Part
Set oTgt = oTgtDoc.Part
Set oBod = myBody
Set oSel = oSrcDoc.Selection
'Copies Body
oSel.Add oBod
oSel.Copy
Set oSel = oTgtDoc.Selection
'Sets and Pastes in Target file as result with link
oSel.Clear
oSel.Add oTgt.Bodies.Item(1)
oSel.Paste
oSrcDoc.Selection.Clear
CATIA.ActiveDocument.ExportData input_path + myBody.name, "stl"
CATIA.ActiveDocument.Close
End Function
Catia V5 is capable of creating STL files from parts (CatiaPART files), but not from assemblies (CatiaPRODUCT files) or geometrical representations (car files). Therefore, source files, including those saved in a neutral format (STEP or IGES, for example), must be saved as parts. If the source design was saved as an assembly, it is imported to Catia as a product. -
Source : http://www.stratasys.com/customer-support/cad-to-stl/catia
I tried exporting CATBody but was unsuccessful. We must have a CATPart to generate STL

Copying from Internet Explorer text area (box) but into more than a single cell

I'm currently trying to control/automate a postcode looking website from postcodes stored and updated in Excel, and my code works perfectly up to the point it has to copy the data once it's finished. For the life of me I can't figure out how to copy the data from the text box / area into Excel without it just putting it ALL into one cell (Text to Columns doesn't really work either).
The website is : http://www.doogal.co.uk/DrivingDistances.php
Sub Geo2()
Dim sht As Worksheet
Dim IE As Object
'Dim ieDoc As HTMLDocument
Dim Item As Variant
Dim objElement As Object
Dim startLoc As String
Dim endLoc As String
Dim x As Integer
Dim objNotes As Object
Dim strNotes As String
Dim str As String
'Dim SignInButton As HTMLInputButtonElement
Set sht = ThisWorkbook.Sheets("Postcode")
Set IE = CreateObject("InternetExplorer.Application")
'Open IE
IE.Visible = True
IE.Navigate "http://www.doogal.co.uk/DrivingDistances.php"
'Wait until site is loaded
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
DoEvents
Loop
IE.Document.getElementbyID("startLocs").Value = "dn1 5pq" 'random postcode
IE.Document.getElementbyID("endLocs").Value = "wf12 2fd" 'random postcode
IE.Document.getElementsByName("calculateFor").Item(1).Checked = True
IE.Document.getElementsByName("units").Item(1).Checked = True
IE.Document.getElementsByClassName("btn btn-primary").Item(0).Click
------
'Ive tried without having it as a object and using .value but it either comes with only the first line or the entire thing rammed into a string and is unusable
----Code here is the problem-----
***Set objNotes = IE.Document.getElementbyID("distances")
str = objNotes.Value***
---------
Do While IE.ReadyState <> 4 'READYSTATE_COMPLETE
DoEvents
Loop
End Sub
The following VBA function uses the Google Maps Directions API to calculate the driving distance in meters between two locations. The code is modified from a version submitted by barrowc on this similar question.
Make sure to add a reference in Excel to Microsoft XML, v6.0.
Function getDistance(origin As String, destination As String) As String
Dim xhrRequest As XMLHTTP60
Dim domDoc As DOMDocument60
Dim ixnlDistanceNode As IXMLDOMNode
Dim RequestString As String
Dim API_Key As String
' Insert your own Google Maps Directions API key here
API_Key = "XXXXXX"
' Read the data from the website
Set xhrRequest = New XMLHTTP60
RequestString = "https://maps.googleapis.com/maps/api/directions/xml?origin=" _
& origin & "&destination=" & destination & "&sensor=false&key=" & API_Key
xhrRequest.Open "GET", RequestString, False
xhrRequest.send
' Copy the results into a format we can manipulate with XPath
Set domDoc = New DOMDocument60
domDoc.LoadXML xhrRequest.responseText
' Select the node called value underneath the leg and distance parents.
' The distance returned is the driving distance in meters.
Set ixnlDistanceNode = domDoc.SelectSingleNode("//leg/distance/value")
getDistance = ixnlDistanceNode.Text
Set ixnlDistanceNode = Nothing
Set domDoc = Nothing
Set xhrRequest = Nothing
End Function
Please note that this code by itself violates the Terms of Use of Google's API. "The Google Maps Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited."1
Instead of putting the data all in one string, Split the string into an array, then loop through the array like this:
Set objNotes = IE.Document.getElementbyID("distances")
Dim x as Integer
Dim aDist() as Variant
aDist = Split(objNotes.Value, vbNewLine) 'May need to be vbCr or vbLf or vbCrLf
For x = 0 to Ubound(aDist) - 1
debug.print aDist(x)
Next x