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?
Hi,
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.
[C#]
// 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
section.Paragraphs.Add(text2);
//Save the pdf document
pdf.Save(@"D:\pdftest\Resources/HTML2pdf_conversion.pdf");
[HTML]
<HTML>
<BODY>
<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>|
</table>
<img border="0" alt="" src="d:/pdftest/barcode.jpg" />
</BODY>
</HTML>
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();
license.SetLicense(“Aspose.Total.Lic”);
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
string strText = " ";
Text txt2 = new Text(sec1, strText);
txt2.IsHtmlTagSupported = true;
sec1.Paragraphs.Add(txt2);
pdf1.Save(“HelloWorld.pdf”, SaveType.OpenInBrowser, Response);
As for retrieving the image:
using (OleDbConnection conn = new OleDbConnection())
{
//Provider=Microsoft.ACE.OLEDB.12.0;
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=” + ;
conn.Open();
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.ClearHeaders();
//Response.ContentType=“image/gif”;
Response.AddHeader(“Content-Length”, filesize.ToString());
Response.BinaryWrite(filedata);
Response.End();
I believe that the issue is being caused by the image stored in the database
Hi,
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.
Hi,
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.