本文介绍了使用样式表将html url转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我使用ITextsharp库将html url转换为创建pdf文件。并且我在头部和身体的在线链接上有样式表和java脚本函数。
当我使用下面的代码时,
文件对这些样式表没有任何意义javascript,
解决这个问题的任何想法
hi all,
i'am using ITextsharp library to convert html url to create pdf file. and i have on the head and body online links with style sheets and java script functions.
when i used the below code,
file has no sense with those style sheets and javascript ,
any ideas to solve this problem
public void Text2PDF(string PDFText)
{
//HttpContext context = HttpContext.Current;
StringReader reader = new StringReader(PDFText);
//Create PDF document
Document document = new Document(PageSize.A4);
HTMLWorker parser = new HTMLWorker(document);
string PDF_FileName = Server.MapPath("PDFddddd_File.pdf");
PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.Create));
document.Open();
try
{
parser.Parse(reader);
}
catch (Exception ex)
{
//Display parser errors in PDF.
Paragraph paragraph = new Paragraph("Error!" + ex.Message);
Chunk text = paragraph.Chunks[0] as Chunk;
if (text != null)
{
text.Font.Color = BaseColor.RED;
}
document.Add(paragraph);
}
finally
{
document.Close();
DownLoadPdf(PDF_FileName);
}
}
推荐答案
HttpWebRequest request = HttpWebRequest.Create("http://images.websnapr.com/?size=s&url=http%3A%2F%2Fwww.google.com") as HttpWebRequest;
Bitmap bitmap;
using (Stream stream = request.GetResponse().GetResponseStream())
{
bitmap = new Bitmap(stream);
bitmap.save(imagepath + "/img1.jpg");
}
Image img= Image.GetInstance(imagepath + "/img1.jpg");
doc.Add(img);
谢谢
Siva Rm K
Thanks
Siva Rm K
这篇关于使用样式表将html url转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!