.NET Core issue when inserting image

Developed a PoC in .Net Core using Aspose to generate reports, main targets:

  • to check the ease of implementation with minimum number of assemblies (as will port to Linux servers, and will have interaction with a mix of technologies as PostGres, PHP)
  • to check the quality of the image from the report;
  • get to know the best way to add the image into report

Tried in 2 ways so far:

  • using Reporting template:
    var pic = new MemoryStream(File.ReadAllBytes(@“C:\Temp\print1.png”));

  • using DocumentBuilder instance , and built in method:
    builder.InsertImage(@“C:\Temp\print1.png”);

On both scenarios throw exception → missing assembly SkiaSharp.

Would appreciate if can also show us with example (feed image file, template) how to add image using expressions. We observed can be achieved using 4 types, know how to try the first 3 (strream, byte[], object) but also interested on the last → A string containing an image URI, path.

@Remus87 Aspose.Words for .NET Standard and for .NET6 use SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

Thanks Alexey,

We’ve decided to continue for the ease of development the poc with .net framework (when starting the new proj we’ll use the net6 or 8 though)

As for the:

@Remus87 .NET6 and .NET8 are not .NET framework, they are .NET Core versions.
https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0

Do you mean adding an images using LINQ Reporting Syntax? If so, please see our documentation to learn how to achieve this:
https://docs.aspose.com/words/net/inserting-images-dynamically/

For example see the following code and documents:

Document doc = new Document(@"C:\Temp\in.docx");
string imgUrl = @"https://cms.admin.containerize.com/templates/aspose/App_Themes/V3/images/aspose-logo.png";
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, imgUrl, "img");
doc.Save(@"C:\Temp\out.docx");

in.docx (15.6 KB)
out.docx (14.3 KB)

Yes, we know that. In fact the name .Net Core (after .Net Core 3.1) is replaced by simple .Net and the version to be released

Thanks for the sample provided. Just what we need.

1 Like