svishnevsky / PDFtoPrinter

.Net Wrapper over PDFtoPrinter util allows to print PDF files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CleanupFilesPrinter not removing files

JeffSE97062 opened this issue · comments

CleanupFilesPrinter does not delete files after printing. The files are on my local PC and print successfully. I have administrative rights on the box.

Hi @JeffSE97062

Do you run the application with the same permission level as you have? Have you tried to run the app As Administrator?

I did try running as administrator and the file still wasn't removed.

Is the application a long running one like service or web server or it exists immediately after sending a file to a printer?

Exits immediately.

Thanks! And thanks for putting this together.

Hi @JeffSE97062

Could you please try the 1.4.2 version and confirm that it solves your issue?

To turn on awaiting of file deletion you need to pass "true" to CleanupFilesPrinter constructor like below:
new CleanupFilesPrinter(new PDFtoPrinterPrinter(), true);

Hi @svishnevsky, same issue with the 1.4.2. The file is not removed.

Do you use a similar approach like below?
`var wrapper = new CleanupFilesPrinter(new PDFtoPrinterPrinter(), true);
await wrapper.Print(new PrintingOptions("Microsoft Print to PDF", "somefile.pdf"));'

Yes.
`
class Program
{
static void Main(string[] args)
{
print();
}

    static async void print()
    {
        // Delete after printing. Doesn't seem to work.
        var wrapper = new CleanupFilesPrinter(new PDFtoPrinterPrinter(), true);

        await wrapper
            .Print(new PrintingOptions(
                Properties.Settings.Default.Printer,
                Properties.Settings.Default.FileToPrint)
                );

    }
}`

Thanks for sharing the code. You call the "print" method with no await, so your application exists before a Task is completed. Could you please try something like:
static sync Task Main(string[] args) { await print() }
or
static void Main(string[] args) { print(),GetAwaiter().GetResult(); }

That worked. Thanks.