简体   繁体   English

如何压缩使用 HTML-Renderer 库 c# 生成的 PDF 文件

[英]How to compress PDF file that is generated using HTML-Renderer library c#

i have the following code which is working fine.我有以下代码工作正常。 I am generating pdf file through html content using library HTML-Randerer .我正在使用库HTML-Randerer通过html内容生成pdf文件。 Problem is that generated pdf file size become increases up to aprox 8MB some time.and i wanted to compress that file as i have to send this pdf to some of the client .问题是生成的pdf文件大小有时会增加到大约 8MB。我想压缩该文件,因为我必须将此pdf发送给某些客户端。 I have searched but did not find any solution.我已经搜索过,但没有找到任何解决方案。

Note:"Html content has no image just tag and textual data only "注意:“Html 内容没有图像,只有标签和文本数据”

Library: HTML Renderer库: HTML 渲染器

Question: How to compress the pdf file using HTML Renderer is there any method ?问题:如何使用HTML Renderer压缩 pdf 文件有什么方法吗?

Code代码

public void GenerateHtmlToPdf(string htmlContent, string sFilePath)
    {
        PdfDocument pdf = PdfGenerator.GeneratePdf(htmlContent, PageSize.A4, 25);
        pdf.Save(sFilePath);

    }

Thanks!谢谢!

The PDF "foo.pdf" you provide contains 33 pages, each pages is between 150 kB to 350 kB in size.您提供的 PDF“foo.pdf”包含 33 页,每页大小在 150 kB 到 350 kB 之间。

Each page draws hundreds of lines.每页画数百行。 Maybe the library draws four lines around each cell.也许图书馆在每个单元格周围画了四条线。 The same visual effect could be achieved with a few, long lines which would reduce the file size considerably.使用几行长行可以实现相同的视觉效果,这将大大减少文件大小。

There are many PDF Optimizer and PDF Compacter around, but I'm afraid they won't do much good with that file.周围有很多 PDF Optimizer 和 PDF Compacter,但恐怕它们对该文件的作用不大。

It seems you can't do it with pdfsharp.看来你不能用 pdfsharp 做到这一点。 And because you don't use images, there is no help there either in that direction.而且因为您不使用图像,所以在那个方向上也没有帮助。 You may read up on alternatives in another post Compress existing PDF using C# programming您可以在另一篇文章使用 C# 编程压缩现有 PDF 中阅读替代方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在C#中使用sevenzipsharper压缩PDF文件? - How to compress PDF file using sevenzipsharper in c#? 使用C#将HTML Renderer转换为PDF并将XML转换为Pdf - Convert HTML to PDF using HTML Renderer using C# and XML to Pdf 在 C# 中使用 Ghostscript 压缩 PDF - Compress PDF using Ghostscript in C# 如何在HTML中使用iTextSharp将HTML转换为PDF文件并保存 - How to Convert an Html to a PDF file and save it Using iTextSharp in C# SevenZipSharp-如何使用C#将多个目录压缩为单个文件? - SevenZipSharp - how to compress multiple directories into a single file using c#? 如何在.NET 2.0中的C#中使用GZipStream压缩文件 - How to compress a file using GZipStream in C# in .NET 2.0 如何将生成的pdf文件作为附件发送到C#的电子邮件中? - How to send generated pdf file as attachment in email from C#? 使用C#压缩单个文件 - Compress a single file using C# 如何在c#中最终生成的pdf文档中使用库TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator下载嵌入式图像? - How to download embedded image using library TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator in finally generated pdf document in c#? 如何使用Selenium C#从webapp下载生成的pdf文件并将其附加到Visual Studio中的测试结果 - How to download generated pdf file from webapp and attach it to test results in Visual Studio using Selenium C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM