I am able to export the text elements to PDF but Image, glyphicons, buttons not displaying. My major concern for this question is exporting the Image, but if you assist me with the glyphicons and buttons not displaying, I will be most grateful.
Error I get is:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
which points at code:
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageURL);
Please help.
What I have tried:
This is the code for selecting the image from the database
string queryimg = "Select `picture` from image where frpid=" + Session["app_id"].ToString();
command = new MySqlCommand(queryimg, con);
byte[] bytes = (byte[])command.ExecuteScalar();
string strBase64 = Convert.ToBase64String(bytes);
if (strBase64 != null)
{
prvimage.ImageUrl = "data:Image/png;base64," + strBase64;
}
else
{
Response.Write("Must upload an Image");
}
This is the code for exporting the webform to PDF
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
form1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
string imageURL = prvimage.ImageUrl;
iTextSharp.text.Image picture = iTextSharp.text.Image.GetInstance(imageURL);
picture.ScaleToFit(105F, 120F);
pdfDoc.Add(picture);
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=DigiCV.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
}