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

Free Support Forum - aspose.com

PDF documents from words merge them in to one doc and stream it out


I have webform that can generate invoices in word format with aspose words. It uses a template word document wich it performs mailmerge on.

Looks like this:

foreach (Invoice f in invoices)
Document doc = new Document("C:\\mall.doc");
string[] fieldNames = { "CompanyName", "Fakturanr", "CompanyAddress", "ZipCode", "CITY", "BetReference" };
object[] fieldValues = { f.Betalare.Namn, f.Fakturanr.ToString(), f.Betalare.Postadr, f.Betalare.Postnr, f.Betalare.Postort, "" };
doc.MailMerge.Execute(fieldNames, fieldValues);

doc.Save("C:\\invoices\\" + f.Fakturanr + ".docx");


I dont't want to save each document I just want to convert it to pdf in memory and then add the document pages to a master pdf file with all the invoices. That file is then going to be streamed out to the user.

Is this possible?


You can easily achieve this using MemoryStream. Just create a MemoryStream object and use it in place of FileStream or file name.


Could you give me an example? Wich product should I use? Aspose.PDF or Aspose.PDF.Kit or maybe both?

I know how to do it with one document but how do ad the second document?

MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.AsposePdf);
XmlDocument xmlDoc = new XmlDocument();
Load the XML document into Aspose.Pdf
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
Make sure the images that were saved by Aspose.Words into Windows temporary
pdf.IsImagesInXmlDeleteNeeded = true;
pdf.BindXML(xmlDoc, null);

Solved bbut my solution requires both pdf end pdf.kit ist that nessecary?


If you convert your doc to pdf and then merge them then you will need Aspose.Words, Aspose.Pdf and Aspose.Pdf.Kit.

You can also first merge all doc into one (http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/append-one-document-to-another.html) and then convert to pdf. This way you only need Aspose.Words and Aspose.Pdf.