Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
C# 无法使用Evopdf将图像加载到pdf中_C#_Image_Html To Pdf_Evopdf - Fatal编程技术网

C# 无法使用Evopdf将图像加载到pdf中

C# 无法使用Evopdf将图像加载到pdf中,c#,image,html-to-pdf,evopdf,C#,Image,Html To Pdf,Evopdf,我试着用evopdf将html转换成pdf,在我的html中有一个带有绝对路径的图像,但图像无法加载到pdf中。这里的“sb”是字符串生成器,我在其中附加html字符串 PdfConverter pdf = new PdfConverter(); byte[] outPdfBuffer = pdf.GetPdfBytesFromHtmlString(sb.ToString()); HttpContext.Current.Response.BinaryWrite(outPdfBuff

我试着用evopdf将html转换成pdf,在我的html中有一个带有绝对路径的图像,但图像无法加载到pdf中。这里的“sb”是字符串生成器,我在其中附加html字符串

  PdfConverter pdf = new PdfConverter();
  byte[] outPdfBuffer = pdf.GetPdfBytesFromHtmlString(sb.ToString());

  HttpContext.Current.Response.BinaryWrite(outPdfBuffer);

  HttpContext.Current.Response.End();
由于我已经给出了完整路径,而没有给出基本url,下面是我的html图像:

<img src="C:/Users/ingyadav/Desktop/icons/icons/logo_160.png" alt="Symphony Summit"/>


有人能帮我吗?

这很简单,你的图像源需要来自http,如果你有一个控制台应用程序,并且想修复,你可以将图像转换为base64

public string GetImage(string path)
{
  using (Image image = Image.FromFile(path))
    {                 
        using (MemoryStream m = new MemoryStream())
        {
            image.Save(m, image.RawFormat);
            byte[] imageBytes = m.ToArray();

            // Convert byte[] to Base64 String
            return Convert.ToBase64String(imageBytes);                
        }                  
    }
}

sb.追加(“”);
如果您有一个webapp,我强烈建议您使用相对路径或CDN路径

<img alt="Image with Full URL" src="http://www.domain.com/Images/Logo.jpg" />


对于本地资源,您必须使用前缀为的完全限定URLfile:///. 在您的HTML中,图像标记应为:

<img src="file:///C:/Users/ingyadav/Desktop/icons/icons/logo_160.png" alt="Symphony Summit"/>


给我们一些代码抱歉,添加了代码@code Joy你能展示一下html中图像源的外观吗?从string builder中拿出一个图像案例,你需要处理一些东西是的,添加了html图像标签@SilentTremora实际上,我正在将html转换为pdf并将pdf作为邮件附件发送。我在你的实时演示中尝试过,但是,但它仍然没有加载图像。实时演示在EvoPdf服务器上运行,无法从您的计算机访问本地文件。您必须从下载库软件包,然后在计算机上尝试演示。让我知道这对你是如何起作用的
<img alt="Image with Relative path" src="/Images/Logo.jpg" />
<img src="file:///C:/Users/ingyadav/Desktop/icons/icons/logo_160.png" alt="Symphony Summit"/>