1

I am exploring Pechkin to convert webpage to PDF. I have used article: http://ourcodeworld.com/articles/read/366/how-to-generate-a-pdf-from-html-using-wkhtmltopdf-with-c-in-winforms

Ref: How to use wkhtmltopdf.exe in ASP.net

When i try to convert using html string, it works !

byte[] pdfContent = new SimplePechkin(new GlobalConfig()).Convert("<html><body><h1>Hello world!</h1></body></html>");

However when I follow "Generate PDF from a Website" section, I get empty pdf.

configuration.SetCreateExternalLinks(false)
    .SetFallbackEncoding(Encoding.ASCII)
    .SetLoadImages(true)
    .SetPageUri("http://ourcodeworld.com");

Has anyone encountered same issue? Appreciate all help/suggestions.

ProgSky
  • 2,530
  • 8
  • 39
  • 65
  • did you ever got any solution for this?? I observed that it works with certain sites and not all. Couple of sites that worked for me were news website http://thehindu.com and my blog on blogspot http://technicalsmile.blogspot.com – TechnicalSmile Apr 09 '18 at 07:54
  • I ended up using http://phantomjs.org/ to convert webpage to PDF. – ProgSky Apr 09 '18 at 13:59

1 Answers1

1

Try to use

https://github.com/tuespetre/TuesPechkin

var document = new HtmlToPdfDocument
{
    GlobalSettings =
    {
        ProduceOutline = true,
        DocumentTitle = "Pretty Websites",
        PaperSize = PaperKind.A4, // Implicit conversion to PechkinPaperSize
        Margins =
        {
            All = 1.375,
            Unit = Unit.Centimeters
        }
    },
    Objects = {
        new ObjectSettings { HtmlText = "<h1>Pretty Websites</h1><p>This might take a bit to convert!</p>" },
        new ObjectSettings { PageUrl = "www.google.com" },
        new ObjectSettings { PageUrl = "www.microsoft.com" },
        new ObjectSettings { PageUrl = "www.github.com" }
    }
};
 var tempFolderDeployment = new TempFolderDeployment();
 var win32EmbeddedDeployment = new Win32EmbeddedDeployment(tempFolderDeployment);
 var remotingToolset = new RemotingToolset<PdfToolset>(win32EmbeddedDeployment);

 var converter = ThreadSafeConverter(remotingToolset);
 byte[] pdfBuf = converter.Convert(document);
 // Very important - overwise cpu will grow !!!
 remotingToolset.Unload();

Edit


If someone else use this- please read my post here- very important!

https://stackoverflow.com/a/62428122/4836581

If you get errors use this link that help me-

TuesPechkin unable to load DLL 'wkhtmltox.dll'

Found it thanks to-

https://stackoverflow.com/a/26993484/4836581

Zvi Redler
  • 1,708
  • 1
  • 18
  • 29