Free Support Forum - aspose.com

Word document to PDF - Generated PDF File Size

Hi,

Here is the code we currently use to convert word document to pdf. We are not able to compress the document size and converted PDF document size is close to the original word document size. If we open the same document using Word 2007 and save it as PDF manually, Word generates the PDF way smaller than what Aspose generates.

Question: Is there any way we could compress the document, close to what MS Word generates? I have attached the original document, pdf converted using MS Word and pdf converted using Aspose.

Thanks

-Balaji

CODE:

Aspose.Words.Document docWord = new Aspose.Words.Document(sourceFilePath);

docWord.Range.UpdateFields();

PdfOptions options = new PdfOptions();

options.JpegQuality = 50;

options.IsPreserveFormFields = false;

options.TextCompression = PdfTextCompression.None;

options.IsEmbedTrueTypeFontsForAsciiChars = false;

string tempPath = @"c:\" + Guid.NewGuid().ToString() +".PDF";

docWord.SaveToPdf(0, docWord.PageCount, tempPath, options);

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You observe this difference because the original document contains a large vector image. On one hand MS Word converts this vector image to raster that is why size of the output PDF is smaller, but on other hand Aspose.Words outputs vector image as vector image into PDF.

You can try converting vector images to raster using the following code and you will see that size of the output PDF is smaller.

// Open the document.

Document doc = new Document(@"Test001\a.doc");

// Get all shapes in the document.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

// Loop through all shapes.

foreach (Shape shape in shapes)

{

// If shape contains a vector image, convert it to rester image.

if (shape.HasImage && (shape.ImageData.ImageType == ImageType.Wmf || shape.ImageData.ImageType == ImageType.Emf))

{

using (MemoryStream vectorImageStream = new MemoryStream(shape.ImageData.ImageBytes))

using (Image image = Image.FromStream(vectorImageStream))

using (MemoryStream resterImageStream = new MemoryStream())

{

image.Save(resterImageStream, ImageFormat.Jpeg);

shape.ImageData.SetImage(resterImageStream);

}

}

}

PdfSaveOptions opt = new PdfSaveOptions();

opt.JpegQuality = 80;

// Save output docuemnt to PDF.

doc.Save(@"Test001\out.pdf", opt);

Hope this helps.

Best regards,

The issues you have found earlier (filed as WORDSNET-2007) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan