Free Support Forum - aspose.com

PdfContentEditor save

While using aspose.cell i try to save an excel file as a pdf and used the following format

excel.Save(HttpContext.Current.Response, “Xls2Pdf.pdf”, Aspose.Cells.ContentDisposition.Attachment, new XlsSaveOptions(Aspose.Cells.SaveFormat.Pdf));

I use to get an option on the browser “Do you want to save Xls2Pdf.pdf from the localhost?” which would let me open or save the file.

I need the save functionality on my aspose.pdf edited by the PdfContentEditor. But when i save it, it directly saves on the disk. How do i get the same functionlity as the excel save?


Hi Pooja,


Thanks for using our products.

PdfContentEditor does not have any save overload method which supports the feature to save the output in Response object. However in order to accomplish your requirement, you may save the updated document into Stream object and then parse these contents in user browser, as specified below.

[C#]

editor.Save(outStream);

// specify the duration of time before a page,cached on a browser expires

Response.Expires = 0;

// Specify the property to buffer the output page

Response.Buffer = true;

// Erase any buffered HTML output

Response.ClearContent();

//Add a new HTML header and value to the Response sent to the client

Response.AddHeader("content-disposition", "inline; filename=" + "output.pdf");

// Specify the HTTP content type for Response as Pdf

Response.ContentType = "application/pdf";

// Write specified information of current HTTP output to Byte array

Response.BinaryWrite(outStream.ToArray());

// close the output stream

outStream.Close();

//end the processing of the current page to ensure that no other HTML content is sent

Response.End();



Besides this, you may consider using an approach where you can save the output of PdfContentEditor to stream object, instantiate a new Document object from Stream and then try using an overload save method of Document class to render the contents in browser.

[C#]

PdfContentEditor editor = new
PdfContentEditor();<o:p></o:p>

///

///.... some operation ....

///

MemoryStream ms = new System.IO.MemoryStream();

editor.Save(ms);

Document doc = new Document(ms);

doc.Save(HttpContext.Current.Response, "test.pdf", ContentDisposition.Attachment, new PdfSaveOptions());

ms.Close();

Go it. Its working fine. Thank you.

Hi Pooja,


I am glad to hear that your requirement can be accomplished with earlier stated description. In the event of any further query, please feel free to contact.