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

Free Support Forum - aspose.com

Html to PDF Image error

I am trying to convert HTML which is stored in a database to PDF. It works fine until I try to convert HTML which has images in it. I get an error "System.ArgumentException: Illegal characters in path."

The problem I think may be related to the images been stored in the database as well and been retrieved by a link similar to

I was wondering if there is anyway to work around this problem or do the images be need to be stored physically instead?


Thanks for using our products.

I have tested the scenario in which I have placed image inside body tag as well as I have used an other image as background of table cell and I am unable to notice any problem. I have tested the scenario with Aspose.Pdf for .NET 6.0.0. I am afraid I don't have HTML/Image contents stored in database. Can you please share the source HTML that you are using or any other sample HTML which can help us in replicating this issue in our environment. We apologize for your inconvenience.


// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
// Read the contents of HTML file into StreamReader object
StreamReader r = File.OpenText(@"D:\pdftest\Resources/source.html");
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
//Add the text paragraphs containing HTML text to the section
//Save the pdf document


<table width='100%' border='0' cellspacing='1' cellpadding='0'>
<tr >
<td style="background-image:url(d:/pdftest/aspose-logo.gif);height:100px;">Hello World</td>|
<img border="0" alt="" src="d:/pdftest/barcode.jpg" />

Thanks for the info.

I have replicated the issue through some simpler code and get the same error. See code
Generating PDF

License license = new License();
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
string strText = " ";
Text txt2 = new Text(sec1, strText);
txt2.IsHtmlTagSupported = true;
pdf1.Save(“HelloWorld.pdf”, SaveType.OpenInBrowser, Response);

As for retrieving the image:

using (OleDbConnection conn = new OleDbConnection())
conn.ConnectionString = “Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=” + ConfigurationManager.AppSettings[“AccessImageFile”];

//conn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + ;

int fileid = int.Parse(Request.QueryString[“fileid”]);

using (OleDbCommand cmd = new OleDbCommand(“select * from fsitems where id=” + fileid, conn))
using (OleDbDataReader reader = cmd.ExecuteReader())
if (!reader.Read())
throw (new HttpException(404, " File Not Found "));

dt = reader.GetDateTime(reader.GetOrdinal(“createdt”));
filename = reader.GetString(reader.GetOrdinal(“filename”));
filesize = reader.GetInt32(reader.GetOrdinal(“filesize”));
filedata = (byte[])reader[“filedata”];

Response.AddHeader(“Content-Length”, filesize.ToString());

I believe that the issue is being caused by the image stored in the database


Thanks for sharing the code snippet.

I have logged this problem as PDFNEWNET-29768 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


Thanks for your patience. I am pleased to share that the issue reported earlier has been fixed and its HotFix will be included in upcoming release version of Aspose.Pdf for .NET 6.5.0 which is expected to be released in few days. Please be patient and spare us little time. Soon you will be updated with the status of correction.

Please note that in order to reference image files during HTML to PDF conversion, please try using Pdf.HtmlInfo.ImgUrl property. Please take a look over the following code snippet for better understanding.

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
string strText = " ";
pdf1.HtmlInfo.ImgUrl = “http://www.google.com.pk”;
Text txt2 = new Text(sec1, strText);
txt2.IsHtmlTagSupported = true;

The issues you have found earlier (filed as 29768) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.