We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF Size and PDF Output issues

When we convert the attached word document to PDF using Aspose Words old way of converting to PDF and new way of converting to PDF, the size of the PDF as well as the output of the PDF are different.

First Issue: SaveToPDF generates twice the size of using Aspose PDF

Second Issue: Aspose PDF merges few words into one eating few spaces between words. You will see that in the first paragraph of the outcome.

OLD CODE:

MemoryStream msDocument = null;

//Create Document instance

var docWord = new Document(@"c:\a1.doc");

docWord.Range.UpdateFields();

//Opening the Memory Stream

msDocument = new MemoryStream();

docWord.SaveOptions.PdfExportImagesFolder = @"c:\";

docWord.SaveOptions.HtmlExportImagesFolderAlias = @"c:\";

docWord.Save(msDocument, SaveFormat.AsposePdf);

//Seek to the beginning so it can be read by XmlDocument.

msDocument.Seek(0, SeekOrigin.Begin);

//Creating the XML Document using Memory Stream

var xmlDoc = new XmlDocument();

xmlDoc.Load(msDocument);

var generatedPdf = new Pdf();

generatedPdf.BindXML(xmlDoc, null);

generatedPdf.IsImagesInXmlDeleteNeeded = true;

generatedPdf.IsTruetypeFontMapCached = true;

generatedPdf.TruetypeFontMapPath = Path.GetTempPath();

generatedPdf.PageSetup.PageHeight = PageSize.A4Height;

generatedPdf.PageSetup.PageWidth = PageSize.A4Width;

//Adding privileges to PDF Document

generatedPdf.Security = new Security

{

IsAnnotationsModifyingAllowed = false,

IsContentsModifyingAllowed = false,

IsCopyingAllowed = false,

IsPrintingAllowed = true,

IsFormFillingAllowed = false

};

generatedPdf.Save(@"c:\hb23.pdf");

NEW CODE

// Open the document.

var doc = new Document(@"c:\a1.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 raster image.

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

{

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

{

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

{

using (var rasterImageStream = new MemoryStream())

{

image.Save(rasterImageStream, ImageFormat.Jpeg);

shape.ImageData.SetImage(rasterImageStream);

}

}

}

}

}

var opt = new PdfOptions {JpegQuality = 75};

doc.SaveToPdf(0, doc.PageCount, @"c:\newway.pdf", opt);

var fileSecurity = new Aspose.Pdf.Kit.PdfFileSecurity(@"c:\newway.pdf", @"c:\newwaysecured.pdf");

fileSecurity.SetPrivilege(Aspose.Pdf.Kit.PdfPrivilege.Assembly | Aspose.Pdf.Kit.PdfPrivilege.ScreenReaders);

doc = null;

Hi Balaji,

Thanks for your inquiry.

I was unable to reproduce any issue when rendering your document to PDF using the direct method of rendering. The size increased to around 73kb but that seems to be in the expected region, as the nature of a rendered document will result in a larger file size.

Could you please attach your output documents that you produce using the Aspose.Pdf and the direct PDF rendered methods? I will take a closer look and provide some further feedback.

Please note your attached document contained no images, so the code to convert image types is not being used.

Thanks,

Please refer this word document. I have sent a wrong document in my previous email.

Hi Balaji,

Thanks for this additional information. This document appear identical to the first one you attached. This one also renders to an appropriate size. Did you by chance attach the wrong document again?

Thanks,

I have attached the correct document now. In the generated PDF, please check the first paragraph where it says “Test to”. This will merged into one word when we use “old way” of generating PDF.

Hi

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

Thanks for your inquiry. I cannot reproduce the problem on my side using the latest version of Aspose.Words. Also you should note, old legacy method of PDF conversion was excluded from the latest version of Aspose.Words. Please try using the following code:

Document doc = new Document("in.doc");

doc.Save("out.pdf");

Best regards,