when i used Aspose.Words(23.09.0) for convert HtmlString into pdf , Get error
System.NotSupportedException: Memory stream is not expandable.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.WriteByte(Byte value)
at bH.c(String a)
at UH.WEFSL9a(nG a)
at WE.a(oG a)
at kH.c()
at WGa.b(rbb a, YU b)
at WGa.pkaFSL9a(rbb a)
at Nua.NuaFSL9a(rbb a)
at Aspose.Words.Document.a(rbb a)
at Aspose.Words.Document.a(Stream a, String b, SaveOptions c)
at demoTask1.Controllers.ValuesController.GeneratePdfUsingAPIV3Code() in D:\Other Folder\Demos\generic name task\demoTask1\demoTask1\Controllers\ValuesController.cs:line 439}|System.Exception {System.NotSupportedException}
at document.Save
string htmlString = "<div><p>Aspose PDF</p><p>Test Content</p></div>";
Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.InsertHtml(htmlString);
doc.Save("HTMLToPDFExample.pdf", Aspose.Words.SaveFormat.Pdf);
if i used doc.Save(“HTMLToPDFExample.pdf”, Aspose.Words.SaveFormat.Pdf); its work for save in pdf format but i need to save html in MemoryStream insted of filename
i used Windows 11 Home Single Language
This Topic is created by asad.ali using Email to Topic tool.
@ravina Unfortunately, I cannot reproduce the problem on my side. I can successfully save document as PDF into a MemoryStream. I have used the following code for testing:
string htmlString = "<div><p>Aspose PDF</p><p>Test Content</p></div>";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(htmlString);
using (MemoryStream ms = new MemoryStream())
{
doc.Save(ms, SaveFormat.Pdf);
// get bytes
byte[] pdfBytes = ms.ToArray();
}
If possible, could you please provide a simple console application or code that will allow us to reproduce the problem on our side. We will check your scenario and provide you more information.
Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.InsertHtml(htmlString);
MemoryStream docStream = new MemoryStream();
doc.Save(docStream, Aspose.Words.SaveFormat.Pdf);
when i used this code withDocker i Get Error “Unhandled exception. System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKObject’ threw an exception.
2023-09-21 13:09:38 —> System.DllNotFoundException: Unable to load shared library ‘libSkiaSharp’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory”
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["PROJECT_NAME.csproj", "."]
RUN dotnet restore "./PROJECT_NAME.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "PROJECT_NAME.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "PROJECT_NAME.csproj" -c Release -o /app/publish /p:UseAppHost=false
#RUN apt-get update && apt-get install -y openssl
#RUN apt-get install -y openssl
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PROJECT_NAME.dll"]
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:
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.