Launching the W-Pechkin converter more than once

I am using wtPechkin for my web application which I am testing locally on IIS using VS2013. The user clicks a button, and the current HTML file is saved as a PDF file, which is then emailed. This process will run regularly as the site data changes.

When converter.Convert(document)

first launched, it converts without issue. However, each subsequent attempt results in the process freezing and I need to restart VS.

Below is the code I used for testing.

public void MakePDF()
{
    var document = new HtmlToPdfDocument
    {
        GlobalSettings =
        {
            ProduceOutline = true,
            DocumentTitle = "Pretty Websites",
            PaperSize = PaperKind.A4, // Implicit conversion to PechkinPaperSize
            Margins =
            {
                All = 1.375,
                Unit = TuesPechkin.Unit.Centimeters
            }
        },
        Objects = {
            new ObjectSettings { HtmlText = "<h1>Pretty Websites</h1><p>This might take a bit to convert!</p>" }
        }
    };

    IConverter converter =
        new ThreadSafeConverter(
            new PdfToolset(
                new Win32EmbeddedDeployment(
                    new TempFolderDeployment())));

    byte[] result = converter.Convert(document);
}

      

Can anyone point me in the right direction? Most of my troubleshooting so far has resulted in some threading and merging discussions, but no specific code solutions for running W Pechkin more than once.

+3


source to share


1 answer


Have you tried ThreadSafeConverter

? StandardConverter

only suitable for small console applications.

IConverter converter =
    new ThreadSafeConverter(
        new RemotingToolset<PdfToolset>(
            new Win32EmbeddedDeployment(
                new TempFolderDeployment())));

byte[] result = converter.Convert(document);

      



Note that you must store the converter somewhere static or as a singleton instance (as mentioned here ).

+2


source







All Articles