PDFsharp icon indicating copy to clipboard operation
PDFsharp copied to clipboard

Async IO should be supported

Open cfauchere opened this issue 1 year ago • 2 comments

Reporting an Issue Here

Expected Behavior

PDFSharp supports async API

Actual Behavior

PDFSharp does not support async API

Example

PdfReader.Open vs PdfReader.OpenAsync PdfDocument.Save vs PdfDocument.SaveAsync

Why is it important?

Look at implementation of PdfDocument OpenFromStream it calls stream.Read(array, 0, 1024); which is blocking. Blocking on IO can lead to threadpool starvation.

cfauchere avatar Oct 01 '24 23:10 cfauchere

There is PdfDocument.SaveAsync.

You can read the PDF file into a MemoryStream and use that with PdfReader.Open.

ThomasHoevel avatar Oct 02 '24 06:10 ThomasHoevel

@ThomasHoevel Unfortunately it looks like PdfDocument.SaveAsync() is only available in the prerelease version, not in the latest stable. Before that, the method is only defined for UWP builds.

nkosi23 avatar Oct 09 '24 17:10 nkosi23

@ThomasHoevel Is there any plan to add async IO ?

molinch avatar Dec 16 '25 15:12 molinch

@molinch There is since it is present in the prerelease version. As far as I am concerned, I am currently using the prelease version in production since it is stable for my use case and I haven't hit any problem. Hope this helps.

nkosi23 avatar Dec 16 '25 18:12 nkosi23

Actually, it looks like SaveAsync() is now supported as the stable version has been published, no need to use the prerelease. I guess this issue can be closed.

Edit: Yes i have just upgraded to the latest stable version and i can confirm that SaveAsync() is present and that everything works like a charm.

nkosi23 avatar Dec 16 '25 18:12 nkosi23

Thanks @nkosi23 you're right it's in 6.2.3 :) We can definitely close this

molinch avatar Dec 18 '25 10:12 molinch