What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 54147 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > Set Image Qaulity in Word to PDF Conversion with C#, VB.NET ...
Lacy

Set Image Qaulity in Word to PDF Conversion with C#, VB.NET

 Blog author: Lacy | Posted on: 5/29/2012 | Category: C# Blogs | Views: 1081 | Status: [Member] | Points: 75 | Alert Moderator   


When we convert Word to PDF, we can easily manage the format of word document text in different ways. But for many images contained word files, we cannot control it very well since the size of the output PDF file is always larger than it of the original word document, which, sometimes, can bring inconvenience. Thus, in order to meet people's need, I would like to share a simple method to set the image quality when we convert word to PDF 

Setting the image quality, to a large extent, is to manage the size of the images in output PDF document. New version Spire.Doc 4.2.8 helps me set the image quality when convert word to PDF in a quick way with C#, VB.NET.


How to set image quality in word to PDF conversion with C#,VB.NET

I am not sure whether other .net word component can realize this function, so please install Spire.Doc first in your system.


Step1. Create a project

1.
     Create a new project in Visual Studio.

2.     Add Spire.Doc Dll as reference. and then, add using at the top of the method. Please see below:

         C# 
         using System;
         using System.Collections.Generic;
         using System.Linq;
         using System.Text;
         using Spire.Doc;
         namespace image_quality
         {
             class Program
             {
                 static void Main(string[] args)
                 {
                     .
                  }                         
             }
         }
             VB.NET 

                Imports Collections.Generic
             Imports System.Linq
             Imports System.Text
             Imports Spire.Doc
             Namespace image_quality
                        Class Program
                                   Private Shared Sub Main(args As String())
                                 .
                                   End Sub
                        End Class
              End Namespace

Step2. Load a Word file from system

C# Code:
Document doc = new Document();
doc.LoadFromFile(@"C:\Program Files\Spire.Doc\image quality.doc", FileFormat.Doc);

VB.NET Code:
Dim doc As New Document()
doc.LoadFromFile(@"C:\Program Files\Spire.Doc\image quality.doc", FileFormat.Doc);

Step3. Set image quality.
There are six images in the first page of my doc document,  I set the size of images all to be "20".  If I have only one image, the size of the image is also"20", so you can set it as your own need.

C# Code:
doc.JPEGQuality = 20;

VB.NET Code:
doc.JPEGQuality = 20;

Step4. Save and launch the file

C# Code:
          doc.SaveToFile("Image.pdf", FileFormat.PDF);
          System.Diagnostics.Process.Start("Image.pdf");

VB.NET Code:
          doc.SaveToFile("Image.pdf", FileFormat.PDF);
          System.Diagnostics.Process.Start("Image.pdf");


Preview
                      
                                                         Word Images
                                
                                                               PDF Images

The original word document size is 63KB. If I convert the word file directly to PDF, it is 80.5 KB. After I set the image quality, it changes to 58 KB. That is the clear difference.



Found interesting? Add this to:


About Keating Arly

Experience:1 year(s)
Home page:http://www.e-iceblue.com
Member since:Tuesday, March 27, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 1:26:23 PM