#1363·QuestPDF

Add a cancellation token to stop long running document generation

Author: FrancGithubCreated Dec 15, 2025Updated Dec 15, 2025

I would propose to add in the while a check if a cancellation token, passed as an argument, has a cancel request instead of while (true)

https://github.com/QuestPDF/QuestPDF/blob/8aa1bf3a68af3bea974869b039af0afdaa1e2138/Source/QuestPDF/Drawing/DocumentGenerator.cs#L239

So, if I need abort a long running document generation, I can cancel the token passed to GeneratePdf

csharp
var ctsGenPdf = new CancellationTokenSource();
var doc = Document.Create(.....);

doc.GeneratePdf(pp.PdfOutputPath, ctsGenPdf.Token);