Aspose::Words::Saving::ResourceSavingArgs::get_ResourceFileName method

ResourceSavingArgs::get_ResourceFileName method

Gets or sets the file name (without path) where the resource will be saved to.

System::String Aspose::Words::Saving::ResourceSavingArgs::get_ResourceFileName() const

Remarks

This property allows you to redefine how the resource file names are generated during export to fixed page HTML or SVG.

When the event is fired, this property contains the file name that was generated by Aspose.Words. You can change the value of this property to save the resource into a different file. Note that file names must be unique.

Aspose.Words automatically generates a unique file name for every resource when exporting to fixed page HTML or SVG format. How the resource file name is generated depends on whether you save the document to a file or to a stream.

When saving a document to a file, the generated resource file name looks like %...

When saving a document to a stream, the generated resource file name looks like Aspose.Words....

ResourceFileName must contain only the file name without the path. Aspose.Words determines the path for saving and the value of the src attribute for writing to fixed page HTML or SVG using the document file name, the ResourcesFolder or ResourcesFolder and ResourcesFolderAlias or ResourcesFolderAlias properties.

Examples

Shows how to use a callback to track external resources created while converting a document to HTML.

void ResourceSavingCallback()
{
    auto doc = MakeObject<Document>(MyDir + u"Bullet points with alternative font.docx");

    auto callback = MakeObject<ExHtmlFixedSaveOptions::FontSavingCallback>();

    auto saveOptions = MakeObject<HtmlFixedSaveOptions>();
    saveOptions->set_ResourceSavingCallback(callback);

    doc->Save(ArtifactsDir + u"HtmlFixedSaveOptions.UsingMachineFonts.html", saveOptions);

    std::cout << callback->GetText() << std::endl;
}

class FontSavingCallback : public IResourceSavingCallback
{
public:
    void ResourceSaving(SharedPtr<ResourceSavingArgs> args) override
    {
        mText->AppendLine(String::Format(u"Original document URI:\t{0}", args->get_Document()->get_OriginalFileName()));
        mText->AppendLine(String::Format(u"Resource being saved:\t{0}", args->get_ResourceFileName()));
        mText->AppendLine(String::Format(u"Full uri after saving:\t{0}\n", args->get_ResourceFileUri()));
    }

    String GetText()
    {
        return mText->ToString();
    }

    FontSavingCallback() : mText(MakeObject<System::Text::StringBuilder>())
    {
    }

private:
    SharedPtr<System::Text::StringBuilder> mText;
};

See Also