Add Footer after updating from SaveFormat.AsposePdf to SaveFormat.Pdf

We have recently upgraded to Aspose.Words version 9.2.0.0 and are having difficulty obtaining functionlity we had previously. We don’t want to have to also use Aspose.Pdf.Kit
Previous code converted our Word Document to PDF,
Called BindXML on a new Aspose.Pdf.Pdf object, then added a footer before saving:

dstDoc.Save(memStream, SaveFormat.AsposePdf)
Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
pdf.BindXML(memStream, Nothing)
AddFooterToPDF(pdf)

Current code converts our Word Document directly to (Word) PDF

dstDoc.Save(memStream, SaveFormat.Pdf)

Binding to a pdf object is apparently no longer required. An attempt to do so raises an error.
In order to perform further manipulation, creating a pdf object using the memStream in the constructor is possible:

Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf(memStream)

And we seem to be able to add a footer to the pdf object.

HOWEVER, the problem is that the pdf object is in Direct-To-File mode and therefore we can’t call pdf.Save(outStream). If we call pdf.Close() then display the pdf, added sections are not visible. I’m not sure if they are even persisted.

Without using BindXML, there appears no other way to load the content into the pdf object. Direct-To-Stream mode is only available with an empty pdf object:

Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()

I have even tried creating an xmlDocument to pass to BindXML, but this fails also.

Since the pdf currently exists in a MemoryStream, it seems reasonable that it should be able to be manipulated prior to displaying or actually saving to a FileStream. However this does not seem to be the case. I have spent several hours trying to find an answer without success. We should not have to use Aspose.pdf.kit which is designed to manipulate existing pdf files.

To summarise, I want to:

  1. Convert a Word document to PDF and hold in a MemoryStream object
  2. Add Footer content
  3. Write to the Response to enable open/save

Any comments or assistance appreciated!
CMH

Hi

Thanks for your inquiry. Why do not you add footer before converting to PDF? In this case you do not need to use neither Aspose.Pdf nor Aspose.Pdf.Kit at all. So here what you should do:

  1. Open Word document.
  2. Add footer using Aspose.Words.
  3. Save document as PDF and send to client’s browser.

Please follow the link to learn how to create headers/footers using Aspose.Words:
https://docs.aspose.com/words/net/working-with-headers-and-footers/
Best regards,

Thanks. That’s what I suspected I would have to do.
Translating functionality of my AddFooterToPdf into AddFooterToDoc required very different code, but it seems to work.

Please feel free to ask if you need more assistance, I will be glad to help you.

Best regards,