Convert PDF to string using acrobat dlls - vb.net

I am working on a vb.net project. I am trying to convert the content of a pdf file to string using acrobat dlls (cannot use other 3 rd party dlls). Below is my code, when I run the program I am getting the following error: "Retrieving the COM class factory for component with CLSID, failed due to the following error: 80040154 Class not registered". I did some research and found out that I have to install the full version of acrobat standard or professional version. Not only that the full version of acrobat must also be installed in all the user machines that the program runs.
Can anyone tell me if this is true and suggest how to fix the class not registered error?
Sub Main()
Dim s As String
Dim sSourceFile As String
sSourceFile = "P:\Report images\DevReports\New Folder\UM-STD-Approval_154.pdf"
Dim oSourceFileInfo As New System.IO.FileInfo(sSourceFile)
Dim st As New AcroPDDoc
st.Open(sSourceFile)
s = GetText(st)
Dim oAcroApp As Acrobat.CAcroApp = New Acrobat.AcroApp
Dim oAcroAvDoc As Acrobat.CAcroAVDoc = New Acrobat.AcroAVDoc
Dim oAcroPDDoc As Object = Nothing
If oAcroAvDoc.Open(sSourceFile, "") Then
'Set PDDoc object and save the file.
oAcroPDDoc = oAcroAvDoc.GetPDDoc()
' oAcroPDDoc.Save(1, sOutputFile)
Else ' Document FAILED to open.
MsgBox("Cannot open ")
End If
oSourceFileInfo = Nothing
oAcroApp.CloseAllDocs()
oAcroPDDoc = Nothing
oAcroAvDoc = Nothing
oAcroApp.Exit()
oAcroApp = Nothing
End Sub

Apologies for the obvious answer but you've kind of answered your own question already.
Adobe Reader is a free application with a very limited interface allowing automation; in practice it's limited to the point where you can display a PDF file and navigate through it (to some extent).
For full features automation (like what I think you are looking for) you will need to install the full Adobe Acrobat. And yes, any system you run this on will also need to have Adobe Acrobat installed.
Now, there are probably libraries out there (including libraries from Adobe or containing Adobe technology inside) that will allow you to embed the functionality you are looking for in your application, but those too will not be free...

Related

Printing a PDF using vb.net and adobe Reader DC not working windows cannot find the application

I have a program that has been working for a while, it basically prints a pdf file to default printer, i had to put this application on a newer pc with the win version 20h2 and now windows returns an error saying it can not find the application. not sure if its a microsoft thing or if my code can be modified to work with it. One constant has to stay in place, Adobe Reader DC has to remain the default PDF reader. below is the code snippet that does the printing , it has worked since january. now will not work with newer windows version.
Private Sub PrintDocument(src As String)
Dim psi As New Process()
psi.StartInfo.UseShellExecute = True
psi.StartInfo.Verb = "print"
psi.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
psi.StartInfo.FileName = src
psi.StartInfo.CreateNoWindow = True
psi.Start()
psi.WaitForInputIdle()
psi.CloseMainWindow()
psi.Close()
Thread.Sleep(10000)
CheckAndCloseAdobeProcess()
End Sub
The Windows update had probably change your default PDF reader, I guess edge is your new PDF reader.

Sage200c SDK crashing in webforms

We are having a problem with the Sage 200c Extra 2018 SDK when used in Web Forms.
We have created solution with library, win forms and web forms project. We have noticed that when using the 'Win Forms project' it works, but the same example in 'Web Forms project' crashes. Sage 200c SDK documentation does not exclusively talk about Win or Web forms and what configuration each may need.
Could you please help us to get this working in web forms? We have an older version of the SDK working on an older version of Sage 200 v8.
We have upgraded Sage 200 v8 to Sage 200c Extra 2018 Summer Enhancements and tested it with the new client and all is working.
I have noticed on sage City similar questions but no answer.
Here
Here is our code sample:
Private Shared Sub FindCore200()
' get registry info for Sage 200 server path
Dim path As String = String.Empty
Dim root As RegistryKey = Registry.CurrentUser
Dim key As RegistryKey = root.OpenSubKey(REG_PATH)
If key IsNot Nothing Then
Dim value As Object = key.GetValue(REGKEY_VALUE)
If value IsNot Nothing Then
path = TryCast(value, String)
End If
End If
' refer to all installed assemblies based on location of default one
If String.IsNullOrEmpty(path) = False Then
Dim commonDllAssemblyName As String = System.IO.Path.Combine(path, DEFAULT_ASSEMBLY)
If (System.IO.File.Exists(commonDllAssemblyName)) Then
Dim defaultAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(commonDllAssemblyName)
Dim type As Type = defaultAssembly.[GetType](ASSEMBLY_RESOLVER)
Dim method As MethodInfo = type.GetMethod(RESOLVER_METHOD)
Dim x = method.Invoke(Nothing, Nothing)
Dim ok = 1
End If
End If
End Sub
when running the application, it always crashes on
application = New Sage.Accounting.Application
Exception Type: System.TypeInitializationException
Message: The type initializer for 'Sage.Accounting.Application' threw an exception.
Inner Exception:
Exception Type: System.IO.FileNotFoundException
Message: Could not load file or assembly 'Sage.MMSAdmin.Util, Version=19.0.0.0, Culture=neutral, PublicKeyToken=b2daa66d74953d11' or one of its dependencies. The system cannot find the file specified.
Are your application pools targeted to the correct version of .net and bit architecture?
If you can physically see the assembly in the path but the app can't, it's usually down to having the wrong version of .net configured. Going from such an old version to a new one, likely requires a .net version change (2.0 to 4.5 for example). It may just be that your winforms solution is targeted to the correct config and it's definitely worth comparing your build and application settings. Check that your targeting the correct CPU architecture in your build too.

Check if Adobe Reader is installed before using it

I want to be able to have my app check if Adobe Reader is installed.
If it is, I want my program to use it to display the PDF, if not I want to use my free (limited) reader control to display the PDF.
Any suggestions
Edit:
my question seems to be little to broad
So basicly i'm trying to do the following
Try
Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF
AcroDisplay.Left = 50
AcroDisplay.Top = 50
AcroDisplay.Width = 200
AcroDisplay.Height = 500
me.Controls.Add(AcroDisplay)
MsgBox("Acro Added")
Catch ex As Exception
MsgBox("Acro Not installed")
''Load Alternate PDF viewer (Spire.pdf Free)
End Try
However when Acrobat Isn't installed instead of going to the catch statement it just shows an error "Could not load assembly" and then exits the sub
What i want is that if acrobat control isn't installed, that it wont display and error and instead just load the alternate pdf viewer
is there a way to check for AxAcroPDFLib.AxAcroPDF before attempting to load?
Hopefully this makes things clearer
Edit 2:
After Searching and screwing around i found 2 possible ways i might be able to do this
however both i can't find how to do it in VB.net
First
Look for AxAcroPDFLib.AxAcroPDF in available namespaces
found C# example but i don't know how to change it to Vb.net
C# - How to check if namespace, class or method exists in C#??
Second
Add Unhandled Exception Handler
also found a few examples but none seem to work
Any Chance anyone could direct me to a working example for either (or both) of these options
Manged to fin a working solution, doesn't work how i was originally thinking but it doe work just fine
i used the following code
Dim AdobeSoftwares As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ADOBE")
If AdobeSoftwares Is Nothing Then
'MessageBox.Show("No Adobe Software")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
Else
If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
'MessageBox.Show("Adobe Reader Installed")
Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
PDFControl = "Acrobat"
Else
'MessageBox.Show("Adobe Reader Not Installed")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
End If
End If
Then in my display code i just look to see what "PDFControl" is in use and run the relevant code to display in that display
So now if adobe reader is installed, I'll be using its control, and if it isn't I'll be using the free (but less featured) control to display PDF files
So hopefully if anyone else is looking at doing similar to me then they can

ItextSharp will not render a PDF that was created in Adobe Experience manager

I am working in an application that creates PDFs for new hires (direct deposit,emergency contact etc.). I used Adobe Livecycle Designer to add and tag fields on the PDFs and then I set the value of the fields with ItextSharp/vb.net. For example: pdfFormFields.SetField("lastName", employee.lastName).
This has worked fine since 2013. Now I have to update the PDfs with new versions and I am using the newer version of Designer that ships with AEM. Now when my application creates a PDF I get this message:
The document you are trying to load requires Adobe Reader 8 or higher. You may not have the Adobe Reader installed or your viewing environment may not be properly configured to use Adobe Reader.
For information on how to install Adobe Reader and configure your viewing environment please see http://www.adobe.com/go/pdf_forms_configure.
This happens even if I take a working PDF , open it in Designer and save it without changing anything. All existing PDFs in the application display correctly/as expected.
I did install the latest version of ItextSharp to see if that would fix it.Same error. I notice that on the working PDFs XFA/AcroShort2LongName has a count, whereas on my bad PDFs the count is 0. Also on the bad PDFs something called TemplateSom does list all of my form fields.
Any assistance would be greatly appreciated, I have been scouring the internet for 12 hours and have found nothing similar or even close to helpful.
Code:
Dim outDirectory As String = Server.MapPath("Files\\")
Dim temploc As String= "Templates\\" + FormName.Trim
Dim pdfTemplate As String = HttpContext.Current.Server.MapPath(temploc)
Dim newFile As String = outDirectory + FormName.Trim
Dim pdfReader As New PdfReader(pdfTemplate)
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream( _
newFile, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
pdfFormFields.SetField("empFirst", firstname)
pdfFormFields.SetField("empLast", lastname)
pdfFormFields.SetField("empMiddle", middlename)
pdfStamper.FormFlattening = True
pdfStamper.Close()

.NET read word/excel documents without Microsoft.Office.Interop

I'm trying to open a doc file under VB.NET, I found a very simple way to do it using word:
For example:
Dim doc As Word.Document
Dim wordApp As New Word.Application
Dim allText As String
Try
doc = wordApp.Documents.Open("C:\marti.doc")
allText = doc.Range.Text()
doc.Close()
RichTextBox1.Text = allText
Catch
'error
End Try
(More detailed info: http://support.microsoft.com/kb/316383)
This could work, but it need to open Microsoft Word window to handle it. I need to use it without Word installed. So I need a Library which can open doc/excel files.
Do you know a good Library that can do this?
I found this library:
http://bytescout.com/download/trial/documentsdk.html
Have you tried this?
The recommended way of interacting with Office files is through the Office OpenXML library. You can get it here.
If you are using Microsoft Office 2003, you can load and save documents in Open XML if you have installed the Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats. You can download the compatibility pack and find more info here.
This is an example method to gather the content of the document:
Private Shared Function GetWordDocContent(strDoc As String) As String
Dim stream As Stream = File.Open(strDoc, FileMode.Open)
Dim wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(stream, True)
Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
Dim content As String = body.InnerText
wordprocessingDocument__1.Close()
Return content
End Function
Another example here.
for handling docx file you can try NPOI or DocX
for the old word format (.doc) I've tried Syncfusion DocIO components, but i prefer to use word automation with NetOffice, much better than the interop