PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 3:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Oct 16, 2017 4:18 pm 
Offline

Joined: Mon Oct 16, 2017 3:51 pm
Posts: 2
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);
        }


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 16, 2017 4:44 pm 
Offline

Joined: Mon Oct 16, 2017 3:51 pm
Posts: 2
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 106 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group