How to Set Image Quality When Converting Word to PDF with C#/VB.NET

If one Word document has several images, the size of PDF document will be very large which converting from this Word document. Sometimes, uses will be troubled because of the large size PDF document. In this post, I will introduce a method to make document size smaller through changing image quality when converting Word to PDF by using C#/VB.NET.

At the beginning, we need to learn something about image quality. Image quality is a characteristic of an image that measures perceived image degradation. That means image will be compared to an ideal or perfect status.

In my example, I use a component, Spire.Doc in this method. So, I add its dll file as reference in my project.

Detailed Steps Shown as Following:           

Step 1, Load Document

Declare a document and load document which I want to set image quality and convert to PDF by using document.LoadFromFile() method.

C#

            Document document = new Document();

            document.LoadFromFile(@”E:\work\Documents\welcome.docx”);

VB.NET

            Dim document As New Document()

            document.LoadFromFile(“E:\work\Documents\welcome.docx”)

Step 2, Set Image Quality

Assign value for document.JPEGQuality. The default quality is percentage 80. If you want to have smaller size, you can set the percentage to be lower than 80.

C#

            document.JPEGQuality= 50;

VB.NET

            document.JPEGQuality = 50

Step 3, Convert Word to PDF

Save document as PDF by using document.SaveToFile() method and then launch this converted file.

C#

            document.SaveToFile(“ImageQuantity.PDF”, FileFormat.PDF);

            System.Diagnostics.Process.Start(“ImageQuantity.PDF”);

VB.NET

            document.SaveToFile(“ImageQuality.PDF”, FileFormat.PDF)

            System.Diagnostics.Process.Start(“ImageQuality.PDF”)

Note: if original document has several images, this sentence: document.JPEGQuality= 50; is used to set all image quality.

Result Shown as Following:

Comparing with the original Word document, PDF which is converted with MS Word and PDF document which converted with setting quality, we can find ImageQuality.PDF has smaller size.

____________________________________________________________________________________________

Click Here to LEARN MORE about Spire.Doc

Click Here to DOWNLOAD Spire.Doc

 Spire.Office also can be used to realize this function.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s