Optimizing PDF through VB .net application
I am working with a VB .net application which actually saves selected PDF to PS and then using distiller it saves the PS file back to PDF which is "optimized" and smaller in size. Following is the code I am using [running in a loop for all files in a directory]:
''Kill Acrobat Process
''Kill Distiller Process
Dim pdfFilePath As String = "E:/TestPDF/abcd.pdf"
Dim convSplitedPage As Acrobat.AcroPDDoc = New Acrobat.AcroPDDocconvSplitedPage.Open(pdfFilePath)
Dim Converter As New Object
Converter = convSplitedPage.GetJSObject()
Converter.saveAs(System.IO.Path.GetDirectoryName(pdfFilePath) & "\" & System.IO.Path.GetFileNameWithoutExtension(pdfFilePath) & ".ps", "com.adobe.acrobat.ps")
convSplitedPage.Close()
System.IO.File.Delete(System.IO.Path.GetDirectoryName(pdfFilePath) & "\" & System.IO.Path.GetFileNameWithoutExtension(pdfFilePath) & ".pdf")
Dim pdf As PdfDistiller = New PdfDistiller
pdf.FileToPDF(System.IO.Path.GetDirectoryName(pdfFilePath) & "\" & System.IO.Path.GetFileNameWithoutExtension(pdfFilePath) & ".ps", System.IO.Path.GetDirectoryName(pdfFilePath) & "\" & System.IO.Path.GetFileNameWithoutExtension(pdfFilePath) & ".pdf", "Smallest File Size")
System.IO.File.Delete(System.IO.Path.GetDirectoryName(pdfFilePath) & "\" & System.IO.Path.GetFileNameWithoutExtension(pdfFilePath) & ".ps")
When runnning this from the Visual studio I can successfully generate the optimized PDF, But when the application is deployed to "C:\Program Files", I am getting various issues. More over the issues are intermittent and can be replicated from Visual Studio also. The issues are as below:
1. Remote Procedure Call Failed: when executing Converter.SaveAs().
Am I doing anything wrong. Please note the issue is not occuring everytime.
Please suggest.
