com.aspose.words
Class DocumentSavingArgs

java.lang.Object
    extended by com.aspose.words.DocumentSavingArgs

public class DocumentSavingArgs 
extends java.lang.Object

An argument passed into IDocumentSavingCallback.notify(com.aspose.words.DocumentSavingArgs).

To learn more, visit the Save a Document documentation article.

Example:

Shows how to manage a document while saving to html.
public void progressCallback(int saveFormat, String ext) throws Exception
{
    Document doc = new Document(getMyDir() + "Big document.docx");

    // Following formats are supported: Html, Mhtml, Epub.
    HtmlSaveOptions saveOptions = new HtmlSaveOptions(saveFormat);
    {
        saveOptions.setProgressCallback(new SavingProgressCallback());
    }

    try {
        doc.save(getArtifactsDir() + MessageFormat.format("HtmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
    }
    catch (IllegalStateException exception) {
        Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
    }

}

public static Object[][] progressCallbackDataProvider() throws Exception
{
    return new Object[][]
            {
                    {SaveFormat.HTML,  "html"},
                    {SaveFormat.MHTML,  "mhtml"},
                    {SaveFormat.EPUB,  "epub"},
            };
}

/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
    /// <summary>
    /// Ctr.
    /// </summary>
    public SavingProgressCallback()
    {
        mSavingStartedAt = new Date();
    }

    /// <summary>
    /// Callback method which called during document saving.
    /// </summary>
    /// <param name="args">Saving arguments.</param>
    public void notify(DocumentSavingArgs args)
    {
        Date canceledAt = new Date();
        long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
        long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);

        if (ellapsedSeconds > MAX_DURATION)
            throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
    }

    /// <summary>
    /// Date and time when document saving is started.
    /// </summary>
    private Date mSavingStartedAt;

    /// <summary>
    /// Maximum allowed duration in sec.
    /// </summary>
    private static final double MAX_DURATION = 0.01d;
}

Property Getters/Setters Summary
doublegetEstimatedProgress()
           Overall estimated percentage progress.
 

Property Getters/Setters Detail

getEstimatedProgress

public double getEstimatedProgress()
Overall estimated percentage progress.

Example:

Shows how to manage a document while saving to xamlflow.
public void progressCallback(int saveFormat, String ext) throws Exception
{
    Document doc = new Document(getMyDir() + "Big document.docx");

    // Following formats are supported: XamlFlow, XamlFlowPack.
    XamlFlowSaveOptions saveOptions = new XamlFlowSaveOptions(saveFormat);
    {
        saveOptions.setProgressCallback(new SavingProgressCallback());
    }

    try {
        doc.save(getArtifactsDir() + MessageFormat.format("XamlFlowSaveOptions.ProgressCallback.{0}", ext), saveOptions);
    }
    catch (IllegalStateException exception) {
        Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
    }
}

public static Object[][] progressCallbackDataProvider() throws Exception
{
    return new Object[][]
            {
                    {SaveFormat.XAML_FLOW,  "xamlflow"},
                    {SaveFormat.XAML_FLOW_PACK,  "xamlflowpack"},
            };
}

/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
    /// <summary>
    /// Ctr.
    /// </summary>
    public SavingProgressCallback()
    {
        mSavingStartedAt = new Date();
    }

    /// <summary>
    /// Callback method which called during document saving.
    /// </summary>
    /// <param name="args">Saving arguments.</param>
    public void notify(DocumentSavingArgs args)
    {
        Date canceledAt = new Date();
        long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
        long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);

        if (ellapsedSeconds > MAX_DURATION)
            throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
    }

    /// <summary>
    /// Date and time when document saving is started.
    /// </summary>
    private Date mSavingStartedAt;

    /// <summary>
    /// Maximum allowed duration in sec.
    /// </summary>
    private static final double MAX_DURATION = 0.01d;
}

Example:

Shows how to manage a document while saving to html.
public void progressCallback(int saveFormat, String ext) throws Exception
{
    Document doc = new Document(getMyDir() + "Big document.docx");

    // Following formats are supported: Html, Mhtml, Epub.
    HtmlSaveOptions saveOptions = new HtmlSaveOptions(saveFormat);
    {
        saveOptions.setProgressCallback(new SavingProgressCallback());
    }

    try {
        doc.save(getArtifactsDir() + MessageFormat.format("HtmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
    }
    catch (IllegalStateException exception) {
        Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
    }

}

public static Object[][] progressCallbackDataProvider() throws Exception
{
    return new Object[][]
            {
                    {SaveFormat.HTML,  "html"},
                    {SaveFormat.MHTML,  "mhtml"},
                    {SaveFormat.EPUB,  "epub"},
            };
}

/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
    /// <summary>
    /// Ctr.
    /// </summary>
    public SavingProgressCallback()
    {
        mSavingStartedAt = new Date();
    }

    /// <summary>
    /// Callback method which called during document saving.
    /// </summary>
    /// <param name="args">Saving arguments.</param>
    public void notify(DocumentSavingArgs args)
    {
        Date canceledAt = new Date();
        long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
        long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);

        if (ellapsedSeconds > MAX_DURATION)
            throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
    }

    /// <summary>
    /// Date and time when document saving is started.
    /// </summary>
    private Date mSavingStartedAt;

    /// <summary>
    /// Maximum allowed duration in sec.
    /// </summary>
    private static final double MAX_DURATION = 0.01d;
}

Example:

Shows how to manage a document while saving to docx.
public void progressCallback(int saveFormat, String ext) throws Exception
{
    Document doc = new Document(getMyDir() + "Big document.docx");

    // Following formats are supported: Docx, FlatOpc, Docm, Dotm, Dotx.
    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(saveFormat);
    {
        saveOptions.setProgressCallback(new SavingProgressCallback());
    }

    try {
        doc.save(getArtifactsDir() + MessageFormat.format("OoxmlSaveOptions.ProgressCallback.{0}", ext), saveOptions);
    }
    catch (IllegalStateException exception) {
        Assert.assertTrue(exception.getMessage().contains("EstimatedProgress"));
    }
}

public static Object[][] progressCallbackDataProvider() throws Exception
{
    return new Object[][]
            {
                    {SaveFormat.DOCX,  "docx"},
                    {SaveFormat.DOCM,  "docm"},
                    {SaveFormat.DOTM,  "dotm"},
                    {SaveFormat.DOTX,  "dotx"},
                    {SaveFormat.FLAT_OPC,  "flatopc"},
            };
}

/// <summary>
/// Saving progress callback. Cancel a document saving after the "MaxDuration" seconds.
/// </summary>
public static class SavingProgressCallback implements IDocumentSavingCallback
{
    /// <summary>
    /// Ctr.
    /// </summary>
    public SavingProgressCallback()
    {
        mSavingStartedAt = new Date();
    }

    /// <summary>
    /// Callback method which called during document saving.
    /// </summary>
    /// <param name="args">Saving arguments.</param>
    public void notify(DocumentSavingArgs args)
    {
        Date canceledAt = new Date();
        long diff = canceledAt.getTime() - mSavingStartedAt.getTime();
        long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);

        if (ellapsedSeconds > MAX_DURATION)
            throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
    }

    /// <summary>
    /// Date and time when document saving is started.
    /// </summary>
    private Date mSavingStartedAt;

    /// <summary>
    /// Maximum allowed duration in sec.
    /// </summary>
    private static final double MAX_DURATION = 0.01d;
}

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.