PDF Gets bigger and bigger with each new generation
See original GitHub issueDescription
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:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kblok looks like this can be closed?
Sure, I just wrote you an email with the attached HTML