Pechkin icon indicating copy to clipboard operation
Pechkin copied to clipboard

Pechkin doesn't clean up temp files

Open KCzar opened this issue 11 years ago • 5 comments

Unclear why it's the case, but it seems Pechkin leaves multiple temp files in the Windows temp folder ("C:Users\UserID\AppData\Local\Temp") similar to these:

wktemp-2d146b15-c8c7-4657-847b-b340a75e09b6.pdf tmp43D4.tmp tmp43D4.tmp.pdf

Files with the "wktemp" prefix are created by wkhtmltopdf (the original version) but they are never left in the Temp folder. They're always cleaned up. They do get left in the Temp folder when Pechkin is run, along with the other tmp files listed above.

All three of those files are left when I run the Html2PdfTestApp.exe executable produced from compiling Pechkin in Visual Studio and then click convert on the windows form that pops up.

Meanwhile the following line of code only leaves the first two (i.e. it doesn't create tmp43D4.tmp.pdf):

byte[] pdfBuf = new SynchronizedPechkin(new GlobalConfig()).Convert("

Hello world!

");

Anyone else having this issue? Anyone know how to fix it? It would seem to be more complicated than adding code to clean it up considering the filenames are randomly generated.

KCzar avatar Dec 13 '13 18:12 KCzar

I'm also seeing the wktemp-{guid}.pdf files being generated. Not a huge pain, but something I'd like to avoid, if possible. I've tried messing with the "SetOutputFile" method on the GlobalConfig object, but no luck.

In the GlobalConfig.cs file

private string _output = ""; // filename to dump PDF into, if "-", then it's dumped into stdout

I've tried:

new GlobalConfig().SetOutputFile("-")

but this only returns an empty byte array when passed to the .Convert method.

mallocation avatar Dec 23 '13 20:12 mallocation

EDIT:

This is what Ive got:

    GlobalConfig gc = new GlobalConfig();
        gc.SetOutputFile(url);
        gc.SetOutputFormat(GlobalConfig.OutputFormat.Pdf);    

        SynchronizedPechkin sc = new SynchronizedPechkin(gc);

        sc.Finished += OnScFinished;
        sc.Error += OnScError;

        ObjectConfig oc = new ObjectConfig();
        oc.SetLoadImages(true);
        oc.SetPrintBackground(true);
        oc.SetScreenMediaType(true);

        sc.Convert(oc, ps);

NOTE: You do NOT need to assign the convert method to a byte array, the convert writes the file out on its own. This is why you are getting temp files, the temp file is the file the Convert() method writes.

Skeldave avatar Jan 09 '14 20:01 Skeldave

Thank you everyone for your discussion here; I will see what can be done about this.

tuespetre avatar Apr 08 '14 13:04 tuespetre

This issue comes from wkhtmltopdf's implementation (I think) and was fixed in January in 0.12.3. I assume this is just a matter of updating Pechkin to that release or later. https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1981

orand avatar Oct 04 '16 19:10 orand

Although there was a fix in 0.12.3, this only seems to have worked when used from the command line, if you're using the c bindings like Pechkin does, I've seen the temp files problem still there. See the following pull request that fixes it. As yes, you'll need to pull an updated wkhtmltopdf dll into Pechkin. wkhtmltopdf/wkhtmltopdf#3930

robinbetts avatar May 25 '18 14:05 robinbetts