You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SLIDESDOC-616 Update the article "Exporting Presentations to HTML with Externally Linked Images" (#785)
Updated the title and added keywords and description for SEO purposes.
Updated the text and improved comments in the code example (C++, Python via .NET).
description: "Export PowerPoint and OpenDocument presentations to HTML in C++ using Aspose.Slides with externally linked images—faster pages, code examples, and setup tips."
6
26
---
7
27
8
-
{{% alert color="primary" %}}
28
+
{{% alert color="primary" %}}
9
29
10
-
This article describes an advanced technique that allows controlling which resources are embedded into the resulting HTML file and which are saved externally and referenced from the HTML file.
30
+
The presentation-to-HTML export process lets you specify:
31
+
32
+
1. which resources are embedded in the resulting HTML file, and
33
+
1. which resources are saved externally and referenced from the HTML file.
34
+
35
+
{{% /alert %}}
11
36
12
-
{{% /alert %}}
13
37
## **Background**
14
-
The default HTML export behavior is to embed any resource into the HTML file. Such approach results in a single HTML file that is easy to view and distribute. All necessary resources are base64-encoded inside. But such approach has two drawbacks:
15
38
16
-
- The size of output is significantly larger because of the base64 encoding. It is difficult to replace the images contained in the file.
39
+
An alternative approach using [ILinkEmbedController](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/) avoids these limitations.
40
+
41
+
The `LinkController` class below implements [ILinkEmbedController](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/) and is passed to the [HtmlOptions](https://reference.aspose.com/slides/cpp/aspose.slides.export/htmloptions/htmloptions/#htmloptionshtmloptionssystemsharedptrilinkembedcontroller-constructor) constructor. The interface exposes three methods that control how resources are embedded or linked during HTML export:
17
42
18
-
In this article we will see how we can change the default behavior using the **Aspose.Slides for C++** to link the images externally rather than embedding in the HTML file. We will use the [ILinkEmbedController](https://reference.aspose.com/slides/cpp/class/aspose.slides.export.i_link_embed_controller) interface which contains three methods to control the resource embedding and saving process. We can pass this interface to the[HtmlOptions](https://reference.aspose.com/slides/cpp/class/aspose.slides.export.html_options) class constructor when preparing the export.
43
+
[GetObjectStoringLocation(id, entityData, semanticName, contentType, recommendedExtension)](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/getobjectstoringlocation): Called when the exporter encounters a resource and must decide where to store it. The most important parameters are `id` (the resource’s unique identifier for this export run) and `contentType` (the resource MIME type). Return [LinkEmbedDecision.Link](https://reference.aspose.com/slides/cpp/aspose.slides.export/linkembeddecision/)to link the resource, or [LinkEmbedDecision.Embed](https://reference.aspose.com/slides/cpp/aspose.slides.export/linkembeddecision/) to embed it.
19
44
20
-
Following is the complete code of the **LinkController** class which implements the [ILinkEmbedController](https://reference.aspose.com/slides/cpp/class/aspose.slides.export.i_link_embed_controller) interface. As mentioned before, the **LinkController** must implement the [ILinkEmbedController](https://reference.aspose.com/slides/cpp/class/aspose.slides.export.i_link_embed_controller) interface. This interface specifies three methods:
45
+
[GetUrl(id, referrer)](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/geturl/): Returns the URL that will appear in the resulting HTML for the resource identified by `id` (optionally considering the referrer object).
21
46
22
-
-**LinkEmbedDecision GetObjectStoringLocation(int32_t id, ArrayPtr<uint8_t> entityData, String semanticName, String contentType, String recomendedExtension)** It is called when the exporter encounters a resource and needs to decide how to store it. The most important parameters are ‘id’ – the resource unique identifier for the entire export operation and ‘contentType’ – contains the resource MIME type. If we decide to link the resource we should return LinkEmbedDecision::Link from this method. Otherwise, LinkEmbedDecision::Embed should be returned to embed the resource.
23
-
-**String GetUrl(int32_t id, int32_t referrer)**
24
-
It is called to get the resource URL in the form how it is used in the resulting file, say for a ```<img src=%method_result_here%>``` tag. The resource is identified by ‘id’.
The final method of the sequence, it is called when it comes to storing the resource externally. We have the resource identifier and the resource contents as a byte array. It’s up to us what to do with the provided resource data.
47
+
[SaveExternal(id, entityData)](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/saveexternal/): Called when a resource selected for linking needs to be written externally. Because the identifier and contents are provided (as a byte array), you can persist the resource however you like.
27
48
28
-
```cpp
29
-
/// <summary>
30
-
/// This class is responsible for making decisions about the resources saved externally.
31
-
/// It must implement the Aspose::Slides::Export::ILinkEmbedController interface.
32
-
/// </summary>
49
+
The C++ `LinkController` implementation of [ILinkEmbedController](https://reference.aspose.com/slides/cpp/aspose.slides.export/ilinkembedcontroller/) follows below.
50
+
51
+
```cpp
33
52
classLinkController : publicILinkEmbedController
34
53
{
35
54
public:
55
+
// Initializes a new instance of the LinkController class.
After writing the **LinkController** class, now we will use it with [HtmlOptions](https://reference.aspose.com/slides/cpp/class/aspose.slides.export.html_options) class to export the presentation to HTML having externally linked images using the following code.
152
+
After implementing the `LinkController` class, you can use it with the [HtmlOptions](https://reference.aspose.com/slides/cpp/aspose.slides.export/htmloptions/htmloptions/) class to export the presentation to HTML with externally linked images, as shown below:
We pass **SlideImageFormat::Svg** to the **set_SlideImageFormat** method which means the resulting HTML file will contain SVG data inside to draw the presentation contents.
167
+
We assigned `SlideImageFormat::Svg` to the `SlideImageFormat` property so that the resulting HTML file will contain SVG data to render the presentation’s contents.
139
168
140
-
As for the content types, it depends on the actual image data contained in the presentation. If there are raster bitmaps in the presentation then the class code must be ready to process both ‘image/jpeg’ and ‘image/png’ content types. The actual content type of the exported raster bitmaps may not match the content type of the images stored in the presentation. The Aspose.Slides for C++ internal algorithms perform size optimization and use either JPG or PNG codec whichever generates smaller data size. Images containing alpha-channel (transparency) are always encoded to PNG.
169
+
Content types: If the presentation contains raster bitmaps, then the class code must be prepared to process both `image/jpeg` and `image/png` content types. The content of the exported bitmap images may not match what was stored in the presentation. Aspose.Slides’ internal algorithms perform size optimization and use either the JPEG or PNG codec (depending on which produces a smaller file size). Images containing an alphachannel (transparency) are always encoded as PNG.
Copy file name to clipboardExpand all lines: en/net/developer-guide/technical-articles/exporting-presentations-to-html-with-externally-linked-images/_index.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,8 @@ keywords:
20
20
- ODP to HTML
21
21
- linked image
22
22
- externally linked image
23
-
- Python
23
+
- .NET
24
+
- C#
24
25
- Aspose.Slides
25
26
description: "Export PowerPoint and OpenDocument presentations to HTML in .NET using Aspose.Slides with externally linked images—faster pages, code examples, and setup tips."
26
27
---
@@ -162,7 +163,7 @@ class LinkController : ILinkEmbedController
162
163
}
163
164
```
164
165
165
-
After implementing the `LinkController` class, you can use it with the [HtmlOptions](https://reference.aspose.com/slides/net/aspose.slides.export/htmloptions/htmloptions/#constructor_1) class to export the presentation to HTML with externally linked images, as shown below:
166
+
After implementing the `LinkController` class, you can use it with the [HtmlOptions](https://reference.aspose.com/slides/net/aspose.slides.export/htmloptions/htmloptions/) class to export the presentation to HTML with externally linked images, as shown below:
166
167
167
168
```cs
168
169
using (varpresentation=newPresentation(@"C:\data\input.pptx"))
0 commit comments