Note that there are some explanatory texts on larger screens.

plurals
  1. POError in converting HTML with images to PDF using itextsharp
    text
    copied!<p>In my application first am allowing the user to create html document using CKEDITOR where user can can create html document and can insert image, form fields etc. the generated HTML document is than converted into PDF. If HTML document contains plain text than PDF file gets created successfully but if user inserts image in it than gives error. code for creating PDF document.</p> <pre><code>public ActionResult CreateFile(FormCollection data) { var filename = data["filename"]; var htmlContent = data["content"]; string sFilePath = Server.MapPath(_createdPDF + filename + ".html"); htmlContent = htmlContent.Trim(); if (!System.IO.File.Exists(sFilePath)) { using (FileStream fs = new FileStream(sFilePath, FileMode.Create)) { using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) { w.Write(htmlContent); } } createPDF(sFilePath); } return View(); } private MemoryStream createPDF(string sFilePath) { string filename = Path.GetFileNameWithoutExtension(sFilePath); string name = Server.MapPath(_createdPDF + filename + ".pdf"); MemoryStream ms = new MemoryStream(); TextReader tr = new StringReader(sFilePath); Document document = new Document(PageSize.A4, 30, 30, 30, 30); string urldir = Request.Url.GetLeftPart(UriPartial.Path); urldir = urldir.Substring(0, urldir.LastIndexOf("/") + 1); Response.Write(urldir); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(name, FileMode.Create)); document.Open(); string htmlText = ""; StreamReader sr; sr = System.IO.File.OpenText(sFilePath); htmlText = sr.ReadToEnd(); sr.Close(); WebClient wc = new WebClient(); Response.Write(htmlText); var props = new Dictionary&lt;string, Object&gt;(); props["img_baseurl"] = @"C:\Documents and Settings\shubham\My Documents\visdatemplatemanger\visdatemplatemanger\"; List&lt;IElement&gt; htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null,props); for (int k = 0; k &lt; htmlarraylist.Count; k++) { document.Add((IElement)htmlarraylist[k]); } document.Close(); System.IO.File.Delete(sFilePath); UploadURL(name); return ms; } </code></pre> <p>The error that i get if image is included in HTML document is:</p> <pre><code>Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\PDFimages\rectangle-shape.png'. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload