'hiqpdf, how to save file to server instead of attachment?
I am trying to save a PDF file to a server path rather than downloading it as an attachment, which I have made with the "hiqpdf" tool. :
protected void btnPrint_Click(object sender, EventArgs e)
{
// create the HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// set browser width
htmlToPdfConverter.BrowserWidth = int.Parse("805");
// set browser height if specified, otherwise use the default
//if (textBoxBrowserHeight.Text.Length > 0)
// htmlToPdfConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text);
// set HTML Load timeout
htmlToPdfConverter.HtmlLoadedTimeout = int.Parse("180");
// set PDF page size and orientation
htmlToPdfConverter.Document.PageSize = PdfPageSize.A4;
htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait;
// set PDF page margins
htmlToPdfConverter.Document.Margins = new PdfMargins(0);
// set a wait time before starting the conversion
htmlToPdfConverter.WaitBeforeConvert = int.Parse("5");
// convert HTML to PDF
byte[] pdfBuffer = null;
//if (radioButtonConvertUrl.Checked)
//{
// convert URL to a PDF memory buffer
string url = System.Configuration.ConfigurationManager.AppSettings["SiteURL"] + "PrintFullApplicantProfile.aspx?MaidID=" + Request.QueryString["aid"].ToString();
pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
// inform the browser about the binary data format
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
// let the browser know how to open the PDF document, attachment or inline, and the file name
//HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=HtmlToPdf.pdf; size={1}",
// checkBoxOpenInline.Checked ? "inline" : "attachment", pdfBuffer.Length.ToString()));
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=Applicant-" + Request.QueryString["aid"].ToString() + ".pdf; size={1}", "attachment", pdfBuffer.Length.ToString()));
// write the PDF buffer to HTTP response
HttpContext.Current.Response.BinaryWrite(pdfBuffer);
// call End() method of HTTP response to stop ASP.NET page processing
HttpContext.Current.Response.End();
}
Any suggestion to save the file to the server path? Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
