gmanny / Pechkin

.NET Wrapper for WkHtmlToPdf static DLL. Allows you to utilize full power of the library.
400 stars 128 forks source link

Maximal image size #16

Open enKor opened 12 years ago

enKor commented 12 years ago

Hi, is there a maximal filesize or resolution of used images? I have problem when I use images in full resolution (from a camera - about 6Mpx?). When I use this fullsize image, the PDF cannot be created. But when I use smaller images it works fine. IDNK if it depends on "kB" size or "px" resolution. Any tips? Thanx

bUKaneer commented 12 years ago

@enKor You can set image quality with .SetMaxImageDpi() and .SetImageQuality() options in GlobalConfig. You can enable local resources with .SetAllowLocalContent(true) in ObjectConfig.

Taken from a @gmanny answer to a similar post that may help here: https://github.com/gmanny/Pechkin/issues/7

Example of using Global config can be found here add in what you need from the above and test : http://stackoverflow.com/questions/13267838/pechkin-html-to-pdf-that-includes-a-link-to-a-png-from-an-ssl-url

gmanny commented 12 years ago

Hello, I tested the library with both http://yhub.ru/u/p/PIA16239.jpg and http://yhub.ru/u/p/PIA16239.png, these are 35 Megapixel images, the second one is 38 MB. It rendered them fine.

I used these (random) options for that:

SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig().SetMargins(new Margins(300, 100, 150, 100))
                .SetCopyCount(1)
                .SetLosslessCompression(true).SetOutlineGeneration(true).SetOutputDpi(1200).SetPaperOrientation(true)
                .SetPaperSize(PaperKind.Letter));

byte[] buf = sc.Convert(new ObjectConfig(), htmlText.Text);
gmanny commented 12 years ago

Could you please provide more details about the error you are getting?

gmanny commented 12 years ago

Also, you could try using images from URLs I've provided and check whether your code works with them.

gmanny commented 12 years ago

Discovered that the actual code was without any options. Just

IPechkin sc = new SimplePechkin(new GlobalConfig().SetPaperSize(PaperKind.Letter).SetPaperOrientation(true));

byte[] buf = sc.Convert(new ObjectConfig(), htmlText.Text);
enKor commented 12 years ago

But when I try to apply it on http://www.prevlec.cz/db/ShowReport.aspx?code=repTiskProtokolu&id0=280284&usrlg=FiaL79o12 it do not work. I use this setup: SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig() .SetMargins(new Margins(10, 10, 10, 10)) .SetDocumentTitle("Report") .SetCopyCount(1) .SetImageQuality(100) .SetLosslessCompression(true) .SetMaxImageDpi(12000) .SetOutlineGeneration(true) .SetOutputDpi(300) .SetPaperOrientation(false) .SetPaperSize(PaperKind.A4));

and then:

byte[] buf = sc.Convert(new ObjectConfig().SetPrintBackground(true) .SetLoadImages(true) .SetAllowLocalContent(true) //.SetIntelligentShrinking(true) //.SetScreenMediaType(true) .SetZoomFactor(2.0) .SetCreateForms(false), new Uri(sUrl));

enKor commented 12 years ago

it throws: Unhandled exception at 0x77e4bef7 in MyWinFormApp_PdfGenerator.exe: 0xE0434352: 0xe0434352.

gmanny commented 12 years ago

There's no Convert method that takes both ObjectConfig and Uri.

gmanny commented 12 years ago

I also haven't encounter the error, when I ran the code you've provided (with the new Uri(sUrl) substituted with just sUrl), everything went fine, even from multiple threads.

I think it has to do with the thread-safeness of the component. Are you testing in the isolated environment, or in production/web? I. e. does it happen in the program which has only that code?

enKor commented 12 years ago

1) It runs in console app. It is a small app of some SQL updates and when all updates are done, then creates the PDF 2) I have created (small change) the overload for both ObjectConfig and Uri