svishnevsky / PDFtoPrinter

.Net Wrapper over PDFtoPrinter util allows to print PDF files.
MIT License
164 stars 41 forks source link

CleanupFilesPrinter not removing files #31

Closed JeffSE97062 closed 3 years ago

JeffSE97062 commented 3 years ago

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

svishnevsky commented 3 years ago

Hi @JeffSE97062

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

JeffSE97062 commented 3 years ago

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

svishnevsky commented 3 years ago

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

JeffSE97062 commented 3 years ago

Exits immediately.

svishnevsky commented 3 years ago

I see. File cleanup works by timer in background that why it doesn't work in your case. I'll publish an update early next week to support such cases. However files are deleted with a delay, so your application will await the end of the operation.

Thanks, Sergey


From: JeffSE97062 @.> Sent: Friday, September 24, 2021 7:52:32 PM To: svishnevsky/PDFtoPrinter @.> Cc: Sergey Vishnevskiy @.>; Comment @.> Subject: Re: [svishnevsky/PDFtoPrinter] CleanupFilesPrinter not removing files (#31)

Exits immediately.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/svishnevsky/PDFtoPrinter/issues/31#issuecomment-926850846, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AASEJU6SCSE6TMLNEVR2GQ3UDTCHBANCNFSM5ER3QSYQ.

JeffSE97062 commented 3 years ago

Thanks! And thanks for putting this together.

svishnevsky commented 3 years ago

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);

JeffSE97062 commented 3 years ago

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

svishnevsky commented 3 years ago

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"));'

JeffSE97062 commented 3 years ago

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)
                );

    }
}`
svishnevsky commented 3 years ago

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(); }

JeffSE97062 commented 3 years ago

That worked. Thanks.