问题是CSS没有应用,图像没有在PDF中呈现。这仅发生在暂存和生产环境中。无法在我的开发环境中重新创建问题。
两者都在https下,图像和CSS文件的链接是http。所以,我改变了我的开发环境以使用https来查看这是否是问题。它没有任何区别。
这是我用于从HTML呈现PDF的代码(我没有写它,它的代码很旧):
Doc theDoc = new Doc();
theDoc.HtmlOptions.Engine = EngineType.Gecko;
theDoc.HtmlOptions.UseScript = true;
theDoc.HtmlOptions.Media = MediaType.Screen;
theDoc.HtmlOptions.AutoTruncate = true;
XHtmlOptions.GeckoSubsetType options = theDoc.HtmlOptions.GeckoSubset;
options.AddLinks = true;
//Write the CSS to PDF
StringBuilder coreCssBuilder = new StringBuilder();
StringWriter coreCssWriter = new StringWriter(coreCssBuilder);
HtmlTextWriter coreCssHtmlWriter = new HtmlTextWriter(coreCssWriter);
lnkCoreCss.RenderControl(coreCssHtmlWriter);
String coreCssHtml = coreCssBuilder.ToString().Replace("href=\"..", "href=\"http://example.com");
StringBuilder testTranscriptCssBuilder = new StringBuilder();
StringWriter testTranscriptCssWriter = new StringWriter(testTranscriptCssBuilder);
HtmlTextWriter testTranscriptCssHtmlWriter = new HtmlTextWriter(testTranscriptCssWriter);
lnkTestTranscriptCss.RenderControl(testTranscriptCssHtmlWriter);
String testTranscriptCssHtml = testTranscriptCssBuilder.ToString().Replace("href=\"..", "href=\"http://example.com");
StringBuilder templateTableCssBuilder = new StringBuilder();
StringWriter templateTableCssWriter = new StringWriter(templateTableCssBuilder);
HtmlTextWriter templateTableCssHtmlWriter = new HtmlTextWriter(templateTableCssWriter);
lnkTemplateTableCss.RenderControl(templateTableCssHtmlWriter);
String templateTableCssHtml = templateTableCssBuilder.ToString().Replace("href=\"..", "href=\"http://example.com");
StringBuilder extraCssBuilder = new StringBuilder();
StringWriter extraCssWriter = new StringWriter(extraCssBuilder);
HtmlTextWriter extraCssHtmlWriter = new HtmlTextWriter(extraCssWriter);
styleExtraCss.RenderControl(extraCssHtmlWriter);
String extraCssHtml = extraCssBuilder.ToString().Replace("</style>", ".BorderCell {border: none;}</style>");
StringBuilder transcriptBuilder = new StringBuilder();
StringWriter transcriptWriter = new StringWriter(transcriptBuilder);
HtmlTextWriter transcriptHtmlWriter = new HtmlTextWriter(transcriptWriter);
pnlTranscript.RenderControl(transcriptHtmlWriter);
//Add the transcript html to the PDF
String transcriptHtml = transcriptBuilder.ToString()
.Replace("src=\"/", "src=\"http://example.com/")
.Replace("src=\"../", "src=\"http://example.com/");
//Add the page CSS to the PDF
transcriptHtml = coreCssHtml + testTranscriptCssHtml + templateTableCssHtml + extraCssHtml + transcriptHtml;
int pageId = theDoc.AddImageHtml(transcriptHtml);
while (true)
{
if (!theDoc.Chainable(pageId))
break;
theDoc.Page = theDoc.AddPage();
pageId = theDoc.AddImageToChain(pageId);
}
//Flatten pages
for (int i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
return theDoc;
更多信息
任何人都可以帮忙吗?
答案 0 :(得分:0)
事实证明,存储CSS和图像的网站没有正确的DNS设置,以便我的登台和制作环境可以访问它。
调整了DNS设置,现在可以使用了。