Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html到PDF格式的ITextSharp图像_Html_Asp.net_Image_Pdf_Itext - Fatal编程技术网

Html到PDF格式的ITextSharp图像

Html到PDF格式的ITextSharp图像,html,asp.net,image,pdf,itext,Html,Asp.net,Image,Pdf,Itext,我正在使用ITextSharp将Html转换为PDF,当我尝试将图像插入Html页面时出现问题,但当下载PDF时,我看不到其中的图像。我没有看到任何错误,代码工作正常,但我无法在下载的PDF中看到图像。PDF的路径是正确的,因为它在HTML页面中工作,我甚至尝试使用HTML更改图像和画布的尺寸,但这并没有解决问题 将HTML转换为PDF的编码是: public void DownloadAsPDF() { try { string

我正在使用ITextSharp将Html转换为PDF,当我尝试将图像插入Html页面时出现问题,但当下载PDF时,我看不到其中的图像。我没有看到任何错误,代码工作正常,但我无法在下载的PDF中看到图像。PDF的路径是正确的,因为它在HTML页面中工作,我甚至尝试使用HTML更改图像和画布的尺寸,但这并没有解决问题

将HTML转换为PDF的编码是:

public void DownloadAsPDF()
    {
        try
        {
            string case_id = Request.Form["case_id"];
            string strHtml = string.Empty;
            string pdfFileName = Request.PhysicalApplicationPath + "\\files\\" + case_id + ".pdf";


            string template = System.IO.File.ReadAllText(Server.MapPath("~/Incomplete-Pdf-temp.html"));
插入图像的代码开始

插入图像结尾的代码

*插入图像的HMTL编码*

 <p><strong>Faculty Signature: </strong></p>
   <img src='[stusign]' />

 <p><strong>Faculty Signature: </strong></p>
   <img src='[facultysign]' />
教员签名:

教员签名:


pdfptablepdfpcell可以使用代码隐藏来定位PDF中的图像

调整图像大小为我解决了这个问题(即使调整画布大小也能解决问题)。

您使用的是哪个版本的iTextSharp?我还希望在您的代码中看到
XMLWorker
。看起来你是在使用这个页面的代码:但是从该网站的<代码> GeaTePdf.Cs<代码>文件不是ITExcel的一部分。如果你想知道为什么某些内容在你的PDF文档中是(或者不是),考虑使用RUPS(从ITEXT存储库下载)。它允许您查看pdf文档的内部结构。@AmedeeVanGasse是的,我正在使用您提到的网站上的代码,那么我现在该怎么办?@JorisSchellekens我在RUPS中检查了文档。它向我展示了类似的东西。70 obj
            CreatePDFFromHTMLFile(template, pdfFileName);
 }
catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }



    public void CreatePDFFromHTMLFile(string HtmlStream, string FileName)
    {
        try
        {
            object TargetFile = FileName;

            string ModifiedFileName = string.Empty;
            string FinalFileName = string.Empty;

            GeneratePDF.HtmlToPdfBuilder builder = new GeneratePDF.HtmlToPdfBuilder(iTextSharp.text.PageSize.A4);
            GeneratePDF.HtmlPdfPage first = builder.AddPage();
            first.AppendHtml(HtmlStream);
            byte[] file = builder.RenderPdf();
            System.IO.File.WriteAllBytes(TargetFile.ToString(), file);

            iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(TargetFile.ToString());
            ModifiedFileName = TargetFile.ToString();
            ModifiedFileName = ModifiedFileName.Insert(ModifiedFileName.Length - 4, "1");

            iTextSharp.text.pdf.PdfEncryptor.Encrypt(reader, new FileStream(ModifiedFileName, FileMode.Append), iTextSharp.text.pdf.PdfWriter.STRENGTH128BITS, "", "", iTextSharp.text.pdf.PdfWriter.AllowPrinting);
            reader.Close();
            if (System.IO.File.Exists(TargetFile.ToString()))
                System.IO.File.Delete(TargetFile.ToString());
            FinalFileName = ModifiedFileName.Remove(ModifiedFileName.Length - 5, 1);
            System.IO.File.Copy(ModifiedFileName, FinalFileName);
            if (System.IO.File.Exists(ModifiedFileName))
                System.IO.File.Delete(ModifiedFileName);

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
 <p><strong>Faculty Signature: </strong></p>
   <img src='[stusign]' />

 <p><strong>Faculty Signature: </strong></p>
   <img src='[facultysign]' />