Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void btnPdf_Click(object sender, EventArgs e)
        {
            string attachment = "attachment; filename=" + "D:\abc" + ".pdf";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/pdf";
            StringWriter s_tw = new StringWriter();
            HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
            h_textw.AddStyleAttribute("font-size", "7pt");
            h_textw.AddStyleAttribute("color", "Black");
            Panel1.RenderControl(h_textw);//Name of the Panel
            Document doc = new Document();
            doc = new Document(PageSize.A4, 5, 5, 15, 5);
            FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
            PdfWriter.GetInstance(doc, Response.OutputStream);
            doc.Open();
            StringReader s_tr = new StringReader(s_tw.ToString());
            HTMLWorker html_worker = new HTMLWorker(doc);
            html_worker.Parse(s_tr);
            doc.Close();
            Response.Write(doc);
}


I have used following References:

C#
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;


In the above coding, to convert a web page (HTML output) to PDF, I am getting an error at "html_worker.Parse(s_tr);" saying that "The network path was not found."
Kindly help me
Posted
Updated 29-Jun-17 8:44am
v3

1 solution

Escape
C#
string attachment = "attachment; filename=" + "D:\abc" + ".pdf";
to
C#
string attachment = "attachment; filename=" + @"D:\abc" + ".pdf";
or
C#
string attachment = "attachment; filename=" + "D:\\abc" + ".pdf";
   
Comments
ramuluj 2-Mar-15 5:07am
   
Again it is raising the same error:

The network path was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The network path was not found.
StM0n 2-Mar-15 5:49am
   
Could you truncate <<string attachment = "attachment; filename=" + "D:\abc" + ".pdf";>> to <<string attachment = @"D:\abc" + ".pdf";>> and try it again?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900