使用Pechkin.Synchronized可以方便导出html为pdf,但是对于https路径的图片并不支持,仅支持http路径下的图片
解决方案:图片使用本地绝对路径(相对于服务器)
以下是我获取本地绝对路径的方法
#region 获得当前绝对路径
/// <summary>
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath">指定的路径</param>
/// <returns>绝对路径</returns>
public static string GetMapPath(string strPath)
{
if (strPath.ToLower().StartsWith("http://")|| strPath.ToLower().StartsWith("https://"))
{
return strPath;
}
if (HttpContext.Current != null)
{
return HttpContext.Current.Server.MapPath(strPath);
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\") || strPath.StartsWith("~"))
{
strPath = strPath.Substring(strPath.IndexOf(‘\\‘, 1)).TrimStart(‘\\‘);
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
#endregion
原文:https://www.cnblogs.com/q251458060/p/13276825.html