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

Free Support Forum - aspose.com

Convert doc to pdf and send to browser all at once

I’m trying to take a doc file and convert to pdf and send to browser. I can get it to save to a file, but I don’t want to do it this way.

Can you show me the right way of taking a document and doing this?

This is my sample code. I am getting a Specified method is not supported error on the .Save line. I am using the latest dlls and running this in Chrome.

string path = Request.ServerVariables[“APPL_PHYSICAL_PATH”] + “\test\merge1.doc”;

Document resultDoc = new Document(path);

DocumentBuilder builder = new DocumentBuilder(resultDoc);

builder.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;

builder.PageSetup.PaperSize = PaperSize.Legal;

builder.PageSetup.VerticalAlignment = PageVerticalAlignment.Center;

builder.MoveToMergeField(“merge1”);

builder.InsertHtml(" **" + DateTime.Now.ToString() + “** ”);

[//resultDoc.Save](https://resultdoc.save/)(“d:\temp\newfile.pdf”);

resultDoc.Save(this.Response.OutputStream, SaveFormat.Pdf);

Hi there,

Thanks for your inquiry.

Have you tried using the code from the following article?

Thanks,

Hi Mike,

Thanks for your inquiry. Most likely you are using Aspose.Words .NET 3.5 Client Profile; .NET 3.5 Client Profile excludes System.Web and therefore HttpResponse is not available. This is entirely by design. If you need to use Aspose.Words in ASP.NET application, I would recommend you use .NET 2.0 Client Profile assembly and the following overload of Save method:

Document.Save Method (HttpResponse, String, ContentDisposition, SaveOptions)

I hope, this will help.

Best regards,

awais.hafeez:
Hi Mike,

Thanks for your inquiry. Most likely you are using Aspose.Words .NET 3.5 Client Profile; .NET 3.5 Client Profile excludes System.Web and therefore HttpResponse is not available. This is entirely by design. If you need to use Aspose.Words in ASP.NET application, I would recommend you use .NET 2.0 Client Profile assembly and the following overload of Save method:

Document.Save Method (HttpResponse, String, ContentDisposition, SaveOptions)

I hope, this will help.
Best regards,

Yes, I got it working with this method. Thanks.

what if you are using the .NET 3.5 Client Profile? is there no alternative to download to the browser through Aspose?

When I use the Document.Save method, I always get object reference not set to instance of an object.

Hi Mike,

Thank you for inquiry. You can also use this code snippet with .NET 3.5

Document doc = new Document(fileName);
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Doc);

Response.Clear();

//Specify the document type.

Response.ContentType = “application/doc”;

//Other options:

[//Response.ContentType](https://response.contenttype/) = “text/plain”

[//Response.ContentType](https://response.contenttype/) = “text/html”

//Specify how the document is sent to the browser.

Response.AddHeader(“content-disposition”, “attachment; filename=MyDocument.doc”);

//Another option could be:

[//Response.AddHeader](https://response.addheader/)(“content-disposition”, “inline; filename=out.doc”);

//Get data bytes from the stream and send it to the response.

byte[] bytes = stream.GetBuffer();

Response.BinaryWrite(bytes);

Response.End();

I hope, this will help.