Converting .doc blob to pdf

Hello all, I’m sure this is possible but I’ve just discovered your product and have a rapidly approaching deadline, so I don’t have time to play.



I’ve got a database with blobs holding .doc files, I want to convert those to PDFs, concatenate on some metadata and spit the resulting PDF out to the client’s web browser. Can this be done without the .docs being buffered to the file system? If so, how?

Hi,

Thanks for your interest in our component.

The sample code for loading the document from a blob can be found in the following thread:

<A href="</A></P> <P>The code to convert the document to PDF looks like this:</P><FONT size=2> <BLOCKQUOTE dir=ltr> <P></FONT><FONT color=#0000ff size=2>internal</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>static</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>void</FONT><FONT size=2> SaveToPdf(Document doc, </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> filename)</P> <P>{</P> <P>MemoryStream stream = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> MemoryStream();</P> <P>doc.Save(stream, SaveFormat.AsposePdf);</P> <P>doc.Save(Path.ChangeExtension(BuildTestFileName(filename), ".xml"), SaveFormat.AsposePdf);

stream.Seek(0, SeekOrigin.Begin);

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(stream);

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

pdf.IsImagesInXmlDeleteNeeded = true;

pdf.BindXML(xmlDoc, null);

// pdf.IsTruetypeFontMapCached = true;

// pdf.TruetypeFontMapPath = Path.GetTempPath();

pdf.Save(filename);

As you can see all of these operations can be done via memory streams, without saving to files.

I am not sure about concatenating the data to PDF though. I can advise on feeding the data into the DOC files but on PDF it is better to consult Aspose.Pdf team on their forum.

Hope this helps. Please let me know if you need any further assistance.

Best regards,

Thanks for the tip. As for concatenation the trick was to use Pdf.Kit. I converted the doc to a pdf similarly to how your code does it, then I created a new pdf with the meta data in it, converted both pdfs to memory streams then used Aspose.Pdf.Kit.PdfFileEditor.Concatenate .



<br /> <br /> MemoryStream metaInfoStream = new MemoryStream(metaInfo.GetBuffer()); <br /> MemoryStream bodyStream = new MemoryStream(body.GetBuffer()); <br /> MemoryStream outputStream = new MemoryStream(); <br /> <br /> PdfFileEditor editor = new PdfFileEditor(); <br /> editor.Concatenate(metaInfoStream, bodyStream, outputStream); <br /> entirePdf = outputStream.GetBuffer(); <br /> <br /> metaInfoStream.Close(); <br /> bodyStream.Close(); <br /> outputStream.Close(); <br /> <br /> <br />