So, I am using this library to generate PDFs based off basic HTML pages. The PDFs look great in every single viewer, except Acrobat/Acrobat Reader. They are showing up as blank. From what I see, there is nothing wrong with my code. Here is the snippet of my application generating the PDF.
Code:
private string RetrieveAllCss(string html, string serverHost) {
Regex cssPathRegex = new Regex("<link href=\"(.*\\.css)\".*\\/>");
MatchCollection cssUrls = cssPathRegex.Matches(html);
string fullCss = "";
foreach(Match cssUrl in cssUrls) {
if (cssUrl.Groups.Count > 0) {
string fullUrl = String.Format("{0}{1}", serverHost, cssUrl.Groups[1]);
WebRequest cssRequest = WebRequest.Create(fullUrl);
Stream cssStream = cssRequest.GetResponse().GetResponseStream();
StreamReader cssReader = new StreamReader(cssStream);
fullCss += cssReader.ReadToEnd() + "\n";
}
}
return fullCss;
}
void GeneratePdf() {
string PdfFileName = "foobar.pdf";
string pdfAsHtml = htmlRetriever.PostAsync(RequestUrl, pdfContent).GetAwaiter().GetResult().Content.ReadAsStringAsync().GetAwaiter().GetResult();
string currentHost = String.Format("{0}://{1}", RequestUrl.Scheme, RequestUrl.Host);
PdfDocument RenderedPdf = PdfGenerator.GeneratePdf(pdfAsHtml, PageSize.Letter, 20, PdfGenerator.ParseStyleSheet(RetrieveAllCss(pdfAsHtml, currentHost)));
RenderedPdf.Save(PdfFileName);
}