pdf 上的所有文本都呈现为 squares/blocks □
all the text on the pdf is rendering as squares/blocks □
为什么我的输出只有正方形?
我正在尝试将 html 转换为 pdf,但我得到了一个奇怪的输出,其中所有字符都是方块,如下所示:
我的函数如下:
public static class ConstructPDFHttpTriggered
{
[FunctionName("ConstructPDFHttpTriggered")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("Processing PDF Request");
string dataDetails = string.Empty;
bool isError = false;
try
{
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}
//Constrcut PDF object
var pdf = Pdf
.From(name)
.WithObjectSetting("web.printMediaType", "true")
.Content();
log.Info($"PDF Generated. Length={pdf.Length}");
//Convert PDF stream to base64 string
dataDetails = Convert.ToBase64String(pdf);
}
catch (Exception ex)
{
isError = true;
dataDetails = ex.Message;
}
return isError
? req.CreateResponse(HttpStatusCode.BadRequest, dataDetails)
: req.CreateResponse(HttpStatusCode.OK, dataDetails);
}
}
为什么我的输出只有正方形?我做错了什么?
原来我们无法在 consumption plan. The OpenHtmlToPdf library uses fonts, which requires an OS to be present within that environment. After switching the function to an App Sevice plan 上 运行 这个问题,这个问题已经简单地解决了。
为什么我的输出只有正方形?
我正在尝试将 html 转换为 pdf,但我得到了一个奇怪的输出,其中所有字符都是方块,如下所示:
我的函数如下:
public static class ConstructPDFHttpTriggered
{
[FunctionName("ConstructPDFHttpTriggered")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("Processing PDF Request");
string dataDetails = string.Empty;
bool isError = false;
try
{
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}
//Constrcut PDF object
var pdf = Pdf
.From(name)
.WithObjectSetting("web.printMediaType", "true")
.Content();
log.Info($"PDF Generated. Length={pdf.Length}");
//Convert PDF stream to base64 string
dataDetails = Convert.ToBase64String(pdf);
}
catch (Exception ex)
{
isError = true;
dataDetails = ex.Message;
}
return isError
? req.CreateResponse(HttpStatusCode.BadRequest, dataDetails)
: req.CreateResponse(HttpStatusCode.OK, dataDetails);
}
}
为什么我的输出只有正方形?我做错了什么?
原来我们无法在 consumption plan. The OpenHtmlToPdf library uses fonts, which requires an OS to be present within that environment. After switching the function to an App Sevice plan 上 运行 这个问题,这个问题已经简单地解决了。