Free Support Forum - aspose.com

Layout problems converting word documents with Autoshapes to PDF

Hello all,

I am having problems converting word 2003 documents with auto shapes to Pdf. Documents convert fine but layout of generated document does not match the original. Please see attached word document “sample.doc” and PDF “sample.pdf” and look at the space in PDF document below first autoshape. This extra space is throwing alignment off when generated PDF is superimposed on another image. I am using Aspose.words for .Net Version 5.1.0.0 and Aspose.PDF for .Net Version 3.6.2.0. Sample code to convert from word to PDF is as follows

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

string wordFileName = “c:\temp\sample.doc”

string pdfFileName = Path.Combine(Path.GetDirectoryName(wordFileName), Path.GetFileNameWithoutExtension(wordFileName) + ".pdf");

if (File.Exists(pdfFileName))

{

File.Delete(pdfFileName);

}

string licenseFileName = @"c:\temp\Aspose.Total.lic";

Aspose.Words.License wordLicense = new Aspose.Words.License();

wordLicense.SetLicense(licenseFileName);

Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();

pdfLicense.SetLicense(licenseFileName);

Aspose.Words.Document wordDocument = new Document(wordFileName);

System.IO.MemoryStream asposePdfXmlStream = new MemoryStream();

wordDocument.Save(asposePdfXmlStream, SaveFormat.AsposePdf);

// Convert from PDF xml format to actual PDF

asposePdfXmlStream.Flush();

asposePdfXmlStream.Seek(0, SeekOrigin.Begin);

Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf();

pdfDocument.CompressionLevel = 0;

pdfDocument.BindXML(asposePdfXmlStream, null);

pdfDocument.IsImagesInXmlDeleteNeeded = true;

pdfDocument.Save(pdfFileName);

MessageBox.Show("Converted Word File " + wordDocument + " to pdf " + pdfFileName);

Help me this is driving me up the wall

Thanks

Rao

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

Thank you for your inquiry.

Your code is okay. I can add two things: when creating a System.IO.MemoryStream it is better to put all related code into using block to guarantee resource deallocation. You don’t need setting IsImagesInXmlDeleteNeeded since it is true by default. But when you set it this should be done before BindXML.

I see the difference in vertical layouting. It is better to avoid floating shapes in this situation. I can suggest using tables with partially invisible borders. The horizontal lines will be represented by visible borders.

Please let us know whether this workaround is suitable for you. If you cannot change the document then we’ll ask Aspose.Pdf Team for their expertise.

Regards,

Thanks for the quick reply. One thing i forgot to add "Word Documents I am trying to convert are generated by a Third Party application i do not have any control over". Is there something that can be done in aspose classes to change the floating shapes to table(s)

Thanks

Rao

Okay, I’ve asked Aspose.Pdf Team to take a look on this document.

Any update on this issue? Also is there a way to change properties on these autoshapes either using Aspose classes or using Word Automation

Thanks

Rao

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

Thank you for your patience.

Aspose.Pdf Team haven’t replied yet. Please try Aspose.Pdf DLL attached in this post:

http://www.aspose.com/community/forums/permalink/128747/128747/showthread.aspx#128747

It gives closer results and can be trusted since it was attached by Aspose.Pdf developers for another customer.

Regards,

Hi Rao,

Thanks for considering aspose products.
I am a developer of aspose pdf team. I tried to convert the attached doc into pdf. In my test, it worked well when using our latest version Aspose.Pdf 3.6.2.10 and Aspose.Words 5.1.0.0. I have attached the dll of Aspose.Pdf 3.6.2.10 and the resulted pdf. Please try it. Thanks.

Best regards.