Spire.Doc

You may be curious why we set quality of image when convert Doc to PDF. After we convert Word document, especially with a lot of images in the document, the size of output PDF document is obviously larger than the original Doc file. Now, the new feature of Spire.Doc new version can help us reduce the output PDF size by setting quality of image.

How to Set Image Quality during Doc to PDF Conversion

Download Spire.Doc (or Spire.Office) with .NET framework 2.0 (or above) together.

Step 1: Create a project in visual studio and add Spire.Doc dll as reference.

[C#]
using System;
using Spire.Doc;

namespace DocToPdf
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace DocToPdf
	Class Program
		Private Shared Sub Main(args As String())
		End Sub
	End Class
End Namespace

Step 2: Put the word document into the project file folder and use the following code to load it into the project.

[C#]
Document doc = new Document();
            doc.LoadFromFile(@"..\..\Test.doc",FileFormat.Doc);
[VB.NET]
Dim doc As New Document()
doc.LoadFromFile("..\..\Test.doc", FileFormat.Doc)

Step 3: The new version (4.2) of Spire.Doc enables developer to set image quality by using the code below. The code below means the output image quality is 40% of the original image. If we don’t use the code, the default set is 80% of the original.

[C#]
doc.JPEGQuality = 40;
[VB.NET]
doc.JPEGQuality = 40

Step 4: Save and Preview

[C#]
doc.SaveToFile(@"..\..\Test.pdf",FileFormat.PDF);
System.Diagnostics.Process.Start(@"..\..\Test.pdf");
[VB.NET]
doc.SaveToFile("..\..\Test.pdf", FileFormat.PDF)
System.Diagnostics.Process.Start("..\..\Test.pdf")

Original Image files in Word Document:

Doc to PDF

40% Image quality in output PDF file:

Doc to PDF

Output Size:

Doc to PDF

The original Word doc file size is 124KB and after converting to PDF file, the PDF file is 138KB. But if we set the image quality as 40% of original, the output PDF file size will be 78KB.

Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight.

Tuesday, 21 February 2012 06:26

Insert Image into Word in Silverlight

Written by support iceblue

The sample demonstrates how to Insert Image into Word in Silverlight.

Friday, 10 February 2012 06:46

Word Footer in Silverlight

Written by support iceblue

The sample demonstrates how to create Word Footer in Silverlight via Spire.Doc.