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

Free Support Forum - aspose.com

Can't open in browser a pdf created out of word doc using a stream constructor

Aspose.Words support suggested I need to contact a Pdf group with the issue described below.
We have a process in place, which does the following:

1. Load a Word doc with a text and image in the page footer into Aspose.Words document

2. Do some in-memory manipulations with Aspose.Words without saning to disk

3. Save Aspose.Words doc to Aspose.Pdf.Pdf (in memory, without saving image or doc to disk)

4. Do something with pdf (also in memory, without saving anything to file system)

5. Display the resulting pdf in browser.

This way worked with Aspose.Words 5.1 + Aspose.Pdf 3.6.
Now we upgraded to Aspose.Words 7, and Aspose.Pdf 4.1, and the same all-in-memory way doesn't seem to work.
Here is a piece of code I'm using, and getting an error
"You are in direct-to-file mode,please use Close() instead of Save()."

Can you, please, let me know, how to show in browser a pdf file created in memory out of Aspose.Words doc.
Is it possible at all with the latest Aspose.Pdf?
If it is - how to change the code below to make it work?

// Doc template has text and image in the footer
Document doc = new Aspose.Words.Document("C:\\Temp\\AlertPrintTemplate.doc");
// .... Do something with Aspose.Words doc
MemoryStream stream = new MemoryStream();
int pagecount = doc.PageCount;
doc.SaveToPdf(0, pagecount, stream, null);
stream.Seek(0, SeekOrigin.Begin);
pdf = new Aspose.Pdf.Pdf(stream);
// ... Do something more with pdf
// show pdf in browser
pdf.Save("Alert.pdf", Aspose.Pdf.SaveType.OpenInBrowser, Response);

Thank you.

Hello Iirna,

I'm not sure what changes in the latest version of Aspose.Words and Aspose.Pdf are causing the problem. And in order for us to investigate the issue, we need to test the scenario at our end. For that reason we would be requiring the documents that are causing issue at your end.

FYI, In recent versions of Aspose.Words for .NET a new method of saving Word file directly into PDF format has been introduced. You can try using that to accomplish your requirement. Please try using the following code snippet and see if it can resolve your problem or not


Document doc = new Document(@"d:/pdftest/newWording.doc");
doc.Save("test.pdf", SaveFormat.Pdf, Aspose.Words.SaveType.OpenInBrowser, Response);

Thank you for yout suggestion, I can't simply use your code to convert a doc tos pdf and display it in the browser, because we are using Aspose.Pdf.Pdf to add a table of contents, and also do some formatting.
I'm attaching a Word doc saved right before conversion to pdf (AlertPrint.doc), the resulting pdf (AlertPrint.pdf), and a source code file.

There are 2 problems so far:
1. Page footer image which exists in a word before conversion is lost when converted to pdf.
2. Table of contents, generated using Aspose.Pdf.Pdf, has all page numbers set to 0.

Please let me know if you need any more info.

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

Thanks for sharing the resource documents.

After thorough investigation, I've figured out the reason regarding both the issues that you have specified in your previous post.

1) The Image is not appearing in Footer section, due to SaveOptions_PdfExportImageSaving() method. For the sake of correction, you can temporarily save the image over system at some location and after the conversion process is completed you can delete the image files.

To specify the location where to save the intermediate image, please try using

doc.SaveOptions.PdfExportImagesFolder = @"D:/pdftest/AlertPrint/temp/";

In order to delete the contents of folder, save during the conversion process, please try using


//retrieve all the files and put them into a string array
String[] names = Directory.GetFiles(@"D:/pdftest/AlertPrint/temp");
//now loop through all the files and delete them
foreach (String file in names)

2) For second issue that TOC items are pointing to page 0, its a defect in our latest version of Aspose.Pdf for .NET For the sake of correction, I've logged it as PDFNET-10969 in our issue tracking system. We will investigate it and will keep you updated with the status of correction.

Beside this, I've noticed that the width of the table in Geographic Regions is not correctly being specified in PDF document. According to my investigation, the issue is occurring at Aspose.Words end as incorrect table width information is being exported into an intermediate XML file. We are in coordination with Aspose.Words team regarding its resolution.

I've manually corrected some information and the resultant PDF that I've generated using Aspose.Pdf for .NET is in attachment. Please take a look.

I like your pdf, but it looks differently from AlertPrint.pdf I included in the previous post.

1. In AlertPrint.pdf some spaces are mising in the page headers, and they are displayed in the word doc before conversion:

www.ecri.org Printed from Health Devices Alerts onMonday, October 05, 2009Page 2

In your pdf headers are displayed correctly. Was this issue fixed?

2. Other spacing issues - there is more spacing in AlertPrint.pdf (using 4.1) than it was in 3.6 version between bulleted list items, between segments "Source", "Comment", "Verification History", etc than when we are using 3.6 version. Are you planning to do anything about it?Thank you.

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

The resultant PDF that I shared in my previous post seems to be more appropriate because I've made some changes in the Intermediate XML before its converted into PDF format.

The spacing issue seems to be resolved in latest version of Aspose.Pdf and also the second issue that you've mentioned seems to be corrected in this release. I've attached the resultant PDF that I've generated when using Aspose.Pdf for .NET (you would notice that page number information over TOC is not correct, as I've mentioned in my previous post that issue has been logged and is under investigation).

In case of any further query, please feel free to contact.

How and when can I get those corrected versions for both Words and Pdf?


The issue has been communicated to Aspose.Words team and I hope they will shortly be updating you with the ETA regarding the resolution of this problem.

Once the issue at Aspose.Words is resolved, Aspose.Pdf will be working over this issue to get it resolved. Your patience and understanding is greatly appreciated in this regard.

Hi <?xml:namespace prefix = st1 ns = "urn:schemas:contacts" />Irina,

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

I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

As a workaround, I can suggest you refactoring of your document. If you need, I can help you with modifying your document.

Best regards.

I have the same issue.

This works:

Stream stream = new FileStream("blah.pdf");

Pdf pdf = new Pdf(stream);


This does not:

Stream stream = new MemoryStream();

Pdf pdf = new Pdf(stream);


When adding a new section to the pdf, it throws an error.

I am using a memory stream. When the stream is a file stream, this works.

Hello Steve,

Thanks for considering Aspose.

I have tested the issue and I’m able to reproduce the same problem. I have logged it in our issue tracking system as PDFNET-12951. We will investigate this issue in detail and will keep you updated on the status of a correction. We apologize for your inconvenience.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The issues you have found earlier (filed as 12951) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.