PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDFs generated by library not opening in Acrobat
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3675
Page 1 of 1

Author:  cameronroe [ Mon Oct 16, 2017 4:18 pm ]
Post subject:  PDFs generated by library not opening in Acrobat

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);
        }

Author:  cameronroe [ Mon Oct 16, 2017 4:44 pm ]
Post subject:  Re: PDFs generated by library not opening in Acrobat

Sorry, I just got back from a conference and I haven't looked at this application in like a month, I forgot to mention PdfSharp is being used behind another library. Specifically, this library here: https://www.nuget.org/packages/HtmlRenderer.PdfSharp

I'm not sure if this is an issue with that library calling PdfSharp wrong or if PdfSharp has a bug. Has anybody else here used PdfSharp through this library and had this issue?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/