question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDF Gets bigger and bigger with each new generation

See original GitHub issue

Description

I am generating a pdf from HTML. If I load the page in my browser and SaveAs, all pictures, html, css & js is less than 5MB. However, when I generate a PDF, huge files get generated and they grow in size: 70MB, 90MB, 101MB, 115MB…

Complete minimal example reproducing the issue

Complete means the code snippet can be copied into a unit test method in a fresh C# project and run. Minimal means it is stripped from code not related to reproducing the issue.

E.g.

        [HttpPost("PdfByHtml")]
        public async Task<IActionResult> PdfByHtml(PdfByHtml request)
        {
            await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
            var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = true
            });
            var page = await browser.NewPageAsync();
            await page.EmulateMediaTypeAsync(MediaType.Screen);
            await page.SetContentAsync(request.Html);

            if (request.PdfOptions == null)
            {
                request.PdfOptions = new PdfOptions() { };
            }

            request.PdfOptions.Format = PaperFormat.A4;
            request.PdfOptions.MarginOptions.Bottom = "1.5cm";
            request.PdfOptions.MarginOptions.Top = "1.5cm";
            request.PdfOptions.MarginOptions.Left = "1.5cm";
            request.PdfOptions.MarginOptions.Right = "1.5cm";
            request.PdfOptions.Scale = new decimal(0.8);

            var pdf = File(await page.PdfDataAsync(request.PdfOptions), "application/pdf");
            await browser.CloseAsync();
            return pdf;
        }

Expected behavior:

Consistent file size with less than or about 5Mb

Actual behavior:

growing file size 70, 90, 100Mb

Versions

  • Which version of PuppeteerSharp are you using? 2.0.0
  • Which .NET runtime and version are you targeting? Core 2.2

Additional Information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SimonCroppcommented, Aug 14, 2020

@kblok looks like this can be closed?

1reaction
mgpepecommented, Jul 20, 2020

Sure, I just wrote you an email with the attached HTML

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDF getting bigger when edited
Yes, every edit will increase the file size, no matter how minor. To cause Acrobat to rewrite the full file, simply use the...
Read more >
Trim Down Large PDF Files With These 5 Simple Tips
Learn how to effectively reduce the file size of your PDF documents by adjusting 5 common PDF creation options.
Read more >
Why are pdfs different sizes when created from the same ...
The PDF is used to turn the drawing into something on paper and to combine PDFs. The PDFs many times have a larger...
Read more >
Is it possible that a file size increases “by itself” during ...
Symptoms When you print a document that contains lots of raster data, the size of the Enhanced Metafile (EMF) spool file may become...
Read more >
Why is my .pdf so much larger in file size than the InDesign ...
Press-ready PDF files are almost always much larger in terms of file size due to flattening and expanding of objects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found