-1

i have the following code which is working fine. I am generating pdffile through html content using library HTML-Randerer. 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 . I have searched but did not find any solution.

Note:"Html content has no image just tag and textual data only "

Library: HTML Renderer

Question: How to compress the pdf file using HTML Renderer is there any method ?

Code

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

    }

Thanks!

Usman lqbal
  • 935
  • 1
  • 9
  • 31
  • 2
    Why down vote kindly explain me? – Usman lqbal Apr 29 '16 at 09:47
  • 1
    PdfGenerator is not part of PDFsharp and I don't know what it does. PDFsharp has a few options that control the size of the file. Without seeing a PDF file I cannot say why you get large files. The PDF file will include the required fonts. With several different fonts this can be several MiB. Just speculation without a PDF file to look at. – I liked the old Stack Overflow Apr 30 '16 at 07:34
  • @ThomasH here` https://github.com/ArthurHub/HTML-Renderer/blob/master/Source/HtmlRenderer.PdfSharp/PdfGenerator.cs` PdfGenerator is a part of PDFsharp . i don't know how you say that `PdfGenerator` is not part of `PDFsharp`. – Usman lqbal Apr 30 '16 at 11:07
  • and i will upload pdf `sample` which i'm generating through `html` – Usman lqbal Apr 30 '16 at 11:10
  • PdfGenerator is not part of PDFsharp. See here: https://github.com/empira/PDFsharp – I liked the old Stack Overflow Apr 30 '16 at 12:58
  • @ThomasH here is a `pdf` please do look at it and suggest me a direction. [Pdf file](https://www.dropbox.com/s/lgjkihqdofrdhwu/foo.pdf?dl=0) – Usman lqbal May 02 '16 at 13:32
  • @ThomasH after studying your link [PDFsharp](https://github.com/empira/PDFsharp) i am come to the conclusion that i am **WRONG ** `pdfGenerator` is not a part of `PDFsharp` but is of `HTML Renderer` library. so now i have updated my question. and thanks for pointing the mistake.. – Usman lqbal May 02 '16 at 13:43
  • Is the HTML file all you got? You should get much smaller PDF files if you create the PDF using MigraDoc directly, using data from e.g. a database. – I liked the old Stack Overflow May 02 '16 at 14:20
  • @PDFsharpTeam no i have to generate the `PDF` from `html` as i have to send html along with the `pdf` its a client requirement – Usman lqbal May 10 '16 at 14:03

2 Answers2

1

The PDF "foo.pdf" you provide contains 33 pages, each pages is between 150 kB to 350 kB in size.

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.

  • Thanks for reply :) . oky i'm trying to change the style . then i will tell you what the result .. – Usman lqbal May 02 '16 at 14:39
  • 1
    [foo_TestFile1](https://www.dropbox.com/s/08968hp3wt7iywp/foo_Test1.pdf?dl=0) .here is a file .i have changed the style (even style is removed) . file size is now decreases to `3.9MB` (Original size was 11MB ). but i need more size reduction .Is there any thing else that i can do to reduce more size? – Usman lqbal May 03 '16 at 14:37
0

It seems you can't do it with 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

Community
  • 1
  • 1
Dick Bos
  • 384
  • 3
  • 8
  • Thanks for reply ..The link which you posted is not what i need ., i have clearly mention in question that i need some function in `pdfsharp` library if there exists to compress file . – Usman lqbal Apr 29 '16 at 13:58