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

Free Support Forum - aspose.com

Doc to PDF with Macros

I have a word document generated by aspose which have an startup macro to rebuild the index.When I open it, the macro runs and the index table of the document is correctly rebuilt.

I have to convert that document to PDF. I do it using aspose with this code:
---------------------------------------------------
Stream streamFichero = new MemoryStream(byteArray);
Document doc = new Document(streamFichero);

//Save the document in Aspose.Pdf.Xml format.
doc.Save(strOutputDirectory + strPDFName + “.xml”, SaveFormat.AsposePdf);

//Read the document in Aspose.Pdf.Xml format into Aspose.Pdf.
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(strOutputDirectory + strPDFName + “.xml”, null);

//Instruct to delete temporary image files.
pdf.IsImagesInXmlDeleteNeeded = true;

//Produce the PDF file.
pdf.Save(strOutputDirectory + strPDFName);
-------------------------------------------------
The problem I have is that the PDF is created without running the macro. Is there any way to solve this?

Thanks in advance

Edited. I have the latest version of aspose.pdf for .NET

Hello

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

Thanks for your inquiry. There is no way to add or run macro programmatically using Aspose.Words. Aspose.Words just preserves macros (VBA project) existing in a Word document without changes.

In additional: as I can see you use old method of PDF conversion. Currently the latest version of Aspose.Words supports direct way of PDF conversion (without using Aspose.Pdf). Old legacy method was excluded from the latest version.

Please see the following code:

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

doc.Save("out.pdf");

Best regards,

Thanks for the answer. I’ll try the conversion method you say.

About the question I made, is there another way to update the document index without macros?

Hello

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

Thanks for your request. I suppose by “index” you mean Table of Content. If so when you call the Document.UpdateFields method, Aspose.Words updates (entirely rebuilds) the TOC field, but does not insert page numbers into the TOC field yet. Aspose.Words calculates correct page numbers and inserts into the TOC when the document layout is built e.g. when you save to PDF or print. So to update page numbers in TOC, you should call Document.UpdatePageLayout or just save document in PDF or XPS.

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

doc.UpdateFields();

doc.UpdatePageLayout();

doc.Save("out.doc");

Please let me know in case of any issues, I will be glad to help you.

Best regards,

I have tried to call the 2 methods (doc.UpdateFields() and doc.UpdatePageLayout()) before save it, but the result is the same (the TOC is not correct).

My aspose.word version is the 7.0. I have tried to upgrade to the latest version (9.3) but I need a lot of changes on the code, so I gave up.

In which version did it start to update the TOC?

Hello

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

Thanks for your request. Updating TOC is supported starting from 9.0.0 version of Aspose.Words for NET.

There were a few breaking changes to the API in version 9.2/9.3 You can find full details of these changes in the migration article:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-migrate-to-aspose-words-9-2-or-higher.html

Best regards,