Puppeteer Sharp PDFStreamAsync 不会抓取页面的整个布局css,但它可以与 Screenshot async 一起使用

问题描述

我正在尝试通过 PDFStreamAsync 使用 puppeteer Sharp 抓取 URL 并将其转换为 PDF。但是,转换后的 pdf 没有页面的整个布局(css)。尝试使用 ScreenshotAsync 时,下载的 pdf 具有完整的布局屏幕截图。我提取了整个 HTML(string html = await page.GetContentAsync();) 来检查我的布局 css URL 和 HTML 是否存在,我可以看到 html 很好,它只是 PDFStreamAsync 由于某种原因不是在下载的 pdf 中渲染布局 css。

            PdfOptions opt = new PdfOptions();
            opt.Format = PaperFormat.A4;
            opt.displayheaderfooter = true;
            opt.PreferCsspageSize = true;
            opt.PrintBackground = true;

            var pdf = await page.PdfStreamAsync(opt);
            await pdf.copyToAsync(memoryStream);
            doc = new Document(memoryStream,$"{Guid.NewGuid().ToString()}.pdf");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)