Free Support Forum - aspose.com

Aspose.HTML HTML TO PDF issue

Hi,

I have recently purchased ASPOSE.HTML to convert HTML to PDF and I’m current getting the error message - “Object reference not set to an instance of an object.” around the result of the “Converter.ConvertHTML()” method.

I have made sure that the license file is correct and is being set correctly. Is there anyway in ASPOSE.HTML to check that the license is set and is valid?

I have noticed a bug in the latest version labelled HTMLNET-2667. Has there been any progress made on this bug as we’re relying heavily on this service.

Kind Regards.

@ROIAdmin

Would you please share your sample HTML with us so that we can test the scenario in our environment and address it accordingly.

We have logged an enhancement ticket as HTMLNET-2734 in our issue management system in order to implement isLicenesed Property (Gets licensed state of the system. Returns true if system works in licensed mode and false otherwise). We will inform you as soon as the property is added. Please spare us some time.

We would like to share with you that the above ticket has been resolved in Aspose.HTML for .NET 20.6.

Great, what object will the “isLicensed” method be available to be called on?

I have Aspose.HTML version 20.6.0 already installed, my sample html code is a simple hello world - used for testing:

"<html><head></head><body><p>Hello World!!</p></body></html>"

The code I’m using to set the license in a constructor as follows:

        Aspose.Html.License htmlLicense = new Aspose.Html.License();

        using (var stream = new FileStream("Aspose.HTML.lic", FileMode.Open))
        {
            // Apply a license using the stream.
            htmlLicense.SetLicense(stream);
        }

Then use the license to convert the HTML above using the following:

         using var streamProvider = new MemoryStreamProvider();

        // Initialize an HTML document
        using var document = new Aspose.Html.HTMLDocument(data, ".");

        var pdfSaveOptions = new Aspose.Html.Saving.PdfSaveOptions();

        // Convert HTML to PDF by using the MemoryStreamProvider
        Aspose.Html.Converters.Converter.ConvertHTML(document, pdfSaveOptions, streamProvider);

        // Get access to the memory stream that contains the result data
        var memory = streamProvider.Streams.First();
        memory.Seek(0, SeekOrigin.Begin);

        return memory.ToArray();

I just thought I’d provide the code just to help you get a insight into how I’m using the toolkit.

Just a side note, it does work locally, but when I release it to a server I get the original “object set to an instance” error

Thanks

@ROIAdmin

The issue you are mentioning seems related to specific environment as we tested it in our environment and were unable to replicate it. Could you please make sure that all necessary files and assemblies are present on the server. Please share full stack trace information with us so that we can check it and share our feedback with you accordingly.

After some more tweaking, I’ve revereted to a .net core 2.1 solution - the license file seems to be loading correctly now but when I got to perform a html to pdf conversion I’m getting the following error:

"errors":["The type initializer for 'Gdip' threw an exception.","   at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)\n   at Aspose.Html.Rendering.Pdf.PdfDevice.BeginPage(SizeF size)\n   at \u0006​  .\u0002(\u000e    \u0002)\n   at \b   .\u0003     \u0002(Renderer \u0002, \u000e   [] \u0003, IDevice \u0005, TimeSpan \b)\n   at Aspose.Html.Rendering.HtmlRenderer.Render(IDevice device, TimeSpan timeout, Document[] documents)\n   at Aspose.Html.Rendering.Renderer`1.Render(IDevice device, TDocument document, TimeSpan timeout)\n   at \u0003  .\u0002(\u0005   \u0002, IDevice \u0003)\n   at \u0003  .\u0002    \u0002(\u0005   \u0002, PdfSaveOptions \u0003, ICreateStreamProvider \u0005)\n   at Aspose.Html.Converters.Converter.ConvertHTML(HTMLDocument document, PdfSaveOptions options, ICreateStreamProvider provider)\n   at ROI.HtmlToPdfApi.Managers.AsposeManager.ConvertHtmlToPdf(String data) in C:\\dev\\html-to-pdf\\ROI.HtmlToPdfApi\\Managers\\AsposeManager.cs:line 71\n   at ROI.HtmlToPdfApi.S3Domain.S3Manager.ConvertHtmlToPdfAsync(String content) in C:\\dev\\html-to-pdf\\ROI.HtmlToPdfApi\\S3Domain\\S3Manager.cs:line 359","Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory","   at Interop.Libdl.dlopen(String fileName, Int32 flag)\n   at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()\n   at System.Drawing.SafeNativeMethods.Gdip..cctor()"]}

I’m publishing the app to an aws lambda function, and I’m guessing that it isn’t shipping the correct packages when deployed - “libdl” or “gdip”

Could you suggest a fix?

I’ve just tried to deploy it onto a windows server too and I’m getting the same errors.

@ROIAdmin

Would you kindly try installing Package libgdiplus in your AWS environment. In case issue still persists, please let us know. We will further proceed to assist you accordingly.