Hi Team
I am attempting to generate the tiff file from my linux machine, the file file was not loading properly(Fonts are missing) I have observed this issue after .Net 6 migration.
These are docker commands I have used to install fonts image.png (33.8 KB) image.png (1.5 KB)
Code I have used to generate the tiff file.
public void ConvertHtmlToTif(Stream source, Stream destination, HtmlToTifConversionOptions options)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (HTMLDocument doc = new HTMLDocument(source, ""))
{
CreateAndCropImageFromHtml(doc, destination, options);
}
stopwatch.Stop();
logger.Trace("Converted HTML to TIF in {0}", stopwatch.Elapsed);
}
void CreateAndCropImageFromHtml(HTMLDocument document, Stream tiffStream, HtmlToTifConversionOptions options)
{
using (MemoryStream imageStr = new MemoryStream())
{
// 1 - Convert HTML to bitmap
CreateBitmap(document, imageStr, options);
// 2 - load bitmap into System.Drawing.Bitmap to manipulate it.
using (Bitmap bmp = (Bitmap)Image.FromStream(imageStr))
{
logger.Trace($"Converted HTML to bitmap, size is {bmp.Width}x{bmp.Height}");
// Only bottom needs to be applied, because Aspose Image Save options support "AdjustToWidestPage"
var result =
options.TrimFromBottom
? AutoCropBottomOnly(bmp, options.BackgroundColor ?? Color.White, options.AdditionalBottomMarginInPixels)
: AutoCrop(bmp, options.BackgroundColor ?? Color.White);
if (result != null)
result.Save(tiffStream, ImageFormat.Tiff);
else
bmp.Save(tiffStream, ImageFormat.Tiff);
}
}
}
Please help me to resolve this issue.
Note: I have used latest aspose libraries.
Which Aspose for .NET APIs you are using? The docker file (as per your screenshot) suggests you are using Aspose.Cells. But your pasted code and issue does not suggest this.
Hi @Amjad_Sahi
I am using the following library to generate the tiff files. <PackageReference Include="Aspose.HTML" Version="22.10.0" />
Usually, the above attached code uses the above library to generate html document then the generated html document converted to Tiff image with help of bitmap, please see the below code for more info.
void CreateAndCropImageFromHtml(HTMLDocument document, Stream tiffStream, HtmlToTifConversionOptions options)
{
using (MemoryStream imageStr = new MemoryStream())
{
// 1 - Convert HTML to bitmap
CreateBitmap(document, imageStr, options);
// 2 - load bitmap into System.Drawing.Bitmap to manipulate it.
using (Bitmap bmp = (Bitmap)Image.FromStream(imageStr))
{
logger.Trace($"Converted HTML to bitmap, size is {bmp.Width}x{bmp.Height}");
// Only bottom needs to be applied, because Aspose Image Save options support "AdjustToWidestPage"
var result =
options.TrimFromBottom
? AutoCropBottomOnly(bmp, options.BackgroundColor ?? Color.White, options.AdditionalBottomMarginInPixels)
: AutoCrop(bmp, options.BackgroundColor ?? Color.White);
if (result != null)
result.Save(tiffStream, ImageFormat.Tiff);
else
bmp.Save(tiffStream, ImageFormat.Tiff);
}
}
An investigation ticket as HTMLNET-4139 has been logged in our issue tracking system to analyze this case in details. We will check and try to determine the actual cause of the issue and let you know as soon as the ticket is resolved. Please be patient and spare us some time.
The ticket has just been logged in our issue tracking system and we are afraid that it is pending for an initial investigation. We will investigate and fix it on first come first serve basis. Meanwhile, you can please share your sample HTML as well as it would help in analysis.
As you suggested above, I have implemented the code to set custom fonts with the user service, but still same issue, However there is change in the file after applying this code. One letter shown in the below image “D”(Highlighted with orange box) FontWithCustom.PNG (31.0 KB)
If you see initial screenshot, you will get the difference.
I have seen the ticket still in open state, please let me know if you need any help on this issue.
Thanks for your kind feedback. We are investigating the case further and will surely let you know once the ticket is resolved or we need something from your side. Please spare us some time.
We could not use your Dockerfile, because an error is generated when trying to build it.
Perhaps it is not given in full. According to the Docker documentation, it should start with FROM instruction “A Dockerfile must begin with a FROM instruction.”(Dockerfile reference | Docker Docs)
There is also no source code to convert the document to Bitmap.
Could you please send the full dockerfile so that the problem with Tiff conversion can be reproduced?
Using a standard Microsoft image, we successfully converted the document to PDF format. We attached an example of a Docker file and code.
internal class Program
{
static void Main(string[] args)
{
ConvertHtmlToTif();
}
public static void ConvertHtmlToTif()
{
using (Stream stream = File.Open("HTMLPage1.html", FileMode.Open))
using (HTMLDocument doc = new HTMLDocument(stream, ""))
{
using (MemoryStream imageStr = new MemoryStream())
{
var renderer = new HtmlRenderer();
var device = new PdfDevice(new FileCreateStreamProvider(".", "HTMLPage1.pdf"));
renderer.Render(device, doc);
}
}
}
}
Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0
STOPSIGNAL SIGINT
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN fc-cache -f -v
WORKDIR /app
COPY . .
Hi @asad.ali
Thank you so much for looking into this issue.
I am okay with the above docker file and code you refered above or else u can wrote your own code, but the code should run under .net6 in linux environment.
Convert the given sample html file into tiff image, attach the docker file&code. I will use that and run in my system.
I am also able to convert html to pdf, but here only issue with html to tiff conversion. Please check from your side once.