Aspose::Words::Saving::ResourceSavingArgs::get_ResourceFileUri method

ResourceSavingArgs::get_ResourceFileUri method

Gets or sets the uniform resource identifier (URI) used to reference the resource file from the document.

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

Remarks

This property allows you to change URIs of resource files exported to fixed page HTML or SVG documents.

Aspose.Words automatically generates an URI for every resource file during export to fixed page HTML or SVG format. The generated URIs reference resource files saved by Aspose.Words. However, the URIs can be incorrect if resource files are to be moved to other location or if resource files are saved to streams. This property allows to correct URIs in these cases.

When the event is fired, this property contains the URI that was generated by Aspose.Words. You can change the value of this property to provide a custom URI for the resource file.

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