Skip to main content
parthasarathi_adhikary
Participant
January 30, 2017
Question

Optimizing PDF through VB .net application

  • January 30, 2017
  • 1 reply
  • 2837 views

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.AcroPDDoc

            convSplitedPage.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.

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
January 30, 2017

What you are doing (PDF->PS->PDF - something usually referred to as "refrying" the PDF) is not optimizing a PDF document. Yes, you may end up with a smaller file, that that is not because it's optimized, it's because you've eliminated information that should be part of a well made PDF file. You end up with a lower quality PDF file. Take a look here for some background information about what you are doing by refrying the PDF: http://www.gwg.org/wp-content/uploads/RefryingPDF.pdf

Regarding your problems, the first thing I would check is to see if the files that are causing problems are protected. If they are, you will not be able to refry them.

parthasarathi_adhikary
Participant
January 31, 2017

Firstly thank you very much for your valuable input and the article on "Refrying".

Actually we are building a dot net application that splits pdf pages and store them into a specific disk path. Now for some PDF files the extracted pages [saved as PDF] are of very large size which actually reduces our disk space and also affecting user experience when showing them through a viewer. When these PDF files are optimized as stated in my previous post, the extracted pages size get reduced. Also the quality is not heavily compromised.

However I can see that "Refrying" is not the best practice and somehow I need to get rid of it. Thanks for your input. Can you please let me know How I can optimize PDF using Javascript API? Also I need to determine the PDFs which are not optimized one, can I detect that from Javascript API? The process need to run on background.

Legend
January 31, 2017

"Optimzed" isn't an on/off state you can test for.