How to cancel a save operation while converting documents to pdf, if it takes long time

I have dotnet core application which uses many aspose libraries to convert different document types to pdf, if it is taking too long, how can i cancel the operation.

I came accross IPageLayoutCallback for aspose.words, are there similar interfaces for other libs too

@Naqib,

Regarding Aspose.Cells, you can stop the conversion of Excel Workbook to various formats like PDF, HTML etc. using the InterruptMonitor object when it is taking too long. See the document for your complete reference.
https://docs.aspose.com/cells/net/stop-conversion-or-loading-using-interruptmonitor-when-it-is-taking-too-long/

Could you please specify which other Aspose for .NET libraries you are using, so we could assist you accordingly.

Cells is done, now i need to implement for slides, pdf and word.

@Naqib,

Thanks for sharing further details.

Our colleagues from Aspose.Slides, Aspose.PDF and Aspose.Words team will soon get back to you and guide you through.

@Naqib,
You can try using a general approach to perform and cancel document conversions based on tasks or threads in C#. More information:

@andrey.potapov thank you for the suggestion, can i get an example code to use with aspose.words

@Naqib,
My colleagues from Aspose.Words team will answer you soon.

@Naqib You can use IDocumentSavingCallback to cancel save operation. The example in the documentation demonstrates how to cancel save operation if it takes more time than expected.

Upon saving document to PDF however the most time is taken by document layout process than by saving operation. You can interrupt the layout process using IPageLayoutCallback. For example the following code interrupts the layout process when layout of two first pages is built:

int pagesToRender = 2;
Document doc = new Document("C:\\Temp\\in.docx");
doc.LayoutOptions.Callback = new PageLayoutCallback(pagesToRender);
try
{
    doc.UpdatePageLayout();
}
catch (PageLimitReachedException ex)
{
    PdfSaveOptions opt = new PdfSaveOptions();
    opt.PageSet = new PageSet(new PageRange(0, pagesToRender - 1));
    doc.Save("C:\\Temp\\out.pdf", opt);
}
private class PageLayoutCallback : IPageLayoutCallback
{
    public PageLayoutCallback(int maxPageCount)
    {
        mMaxPageCount = maxPageCount;
    }

    public void Notify(PageLayoutCallbackArgs args)
    {
        if (args.Event == PageLayoutEvent.PartReflowStarted &&
                args.PageIndex >= mMaxPageCount)
            throw new PageLimitReachedException();
    }

    private int mMaxPageCount;
}
private  class PageLimitReachedException : Exception { }

In the Notify method you can use other condition for the layout process interruption. For example check the flag set by the outside event.