We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert HTML to PDF in a Linux Docker using Aspose.PDF for .NET - System.NullReferenceException occurs

We’re getting a “System.NullReferenceException: Object reference not set to an instance of an object.” when we try to initialize a Aspose.Pdf.Document object. Here is the function that is causing the issue:

public static bool CreatePDFFile(MemoryStream memStream, string htmlText, string footerText = null)
{
//Instantiate PDF instance by calling empty constructor
Aspose.Pdf.License pdflic = new Aspose.Pdf.License();
pdflic.SetLicense(“Aspose.PDF.lic”);

byte[] fileBytes = Encoding.ASCII.GetBytes(htmlText);

// Initialize document object
var htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions { InputEncoding = “utf-8” };
//Document pdfDocument = new Document(“c:\temp\foo.html”, htmlLoadOptions);
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new MemoryStream(fileBytes), htmlLoadOptions);

if (!String.IsNullOrEmpty(footerText))
{
// Create header
TextStamp textStamp = new TextStamp(footerText);
// Set properties of the stamp
textStamp.BottomMargin = 10;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Bottom;
// Add footer on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(textStamp);
}
}

pdfDocument.Save(memStream);

return true;
}

This code works just fine our development Windows machines, but is failing when we push the build to our Linux Docker environment.

Environment
.Net Core 2.2 Runtime
Docker Linux
Aspose.PDF Version 20.4.0

@rnakagawa,

Thanks for contacting support.

Can you please share source html file so that we may help you out.

The incoming “htmlText” looks like this:

<html>
<body>
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tbody>
			<tr>
				<td style="padding-top: 15px;"><strong>Title</strong></td>
			</tr>
			<tr>
				<td colspan="3">My title</td>
			</tr>

			<tr style="vertical-align:top">
				<td style="padding-top: 15px;"><strong>Published Date</strong><br />01-01-2020</td>
				<td style="padding-top: 15px;"><strong>Author</strong><br />Author Name</td>
				<td style="padding-top: 15px;"><strong>POCs</strong><br />List of POCs</td>
			</tr>

			<tr>
				<td style="padding-top: 15px;"><strong>Summary</strong></td>
			</tr>
			<tr>
				<td colspan="3">Long summary text</td>
			</tr>

			<tr>
				<td style="padding-top: 15px;"><strong>Discipline(s)</strong></td>
			</tr>
			<tr>
				<td colspan="3">Some disciplines</td>
			</tr>

			<tr>
				<td style="padding-top: 15px;"><strong>Description</strong></td>
			</tr>
			<tr>
				<td colspan="3">Long description</td>
			</tr>

			<tr>
				<td style="padding-top: 15px;"><strong>Attachment(s)</strong></td>
			</tr>
			<tr>
				<td colspan="3">No attachments</td>
			</tr>

		</tbody>
	</table>
</body>
</html>

I’ve checked the incoming memStream object and it is initialized. The error is thrown on this line:

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new MemoryStream(fileBytes), htmlLoadOptions);

For reference, here is the full error message"

System.NullReferenceException: Object reference not set to an instance of an object.
at #=zF42PEgna4sVOwrAPnluxylH5sbJdJ_EHNGdV4Tg=.#=zSt$0Ixcb2bvi(#=zJYbsSKBpepbVIdA4bIsrwT5q96PwJKlYQg== #=z97ZgON8=, Char #=zpNB6c8g=)
at #=zF42PEgna4sVOwrAPnluxylH5sbJdJ_EHNGdV4Tg=.#=zSt$0Ixcb2bvi(#=zJYbsSKBpepbVIdA4bIsrwT5q96PwJKlYQg== #=z97ZgON8=)
at #=zGHCl2X431kMSlOiJJaNY4KeEyC74EL6oxeM4tqQGMFrX.#=zO2xlQsc=()
at #=zLLd8k7YrHXhkFuySq0xiffs53a5oY_I04Izjx7_3yzJ_.#=zxy$TbEOT98UO()
at #=z$ESMopXPKTEtpumx1XEwzrTUzwbmCYPQJ4K68foZc5QNvvFESpojYBQ=.#=zSCkVlI31Ewiw()
at #=z$ESMopXPKTEtpumx1XEwzrTUzwbmCYPQJ4K68foZc5QNvvFESpojYBQ=.#=zqy1n4OnDAEgIXcLiZxM8g60=(List1 #=zWUCIDBU=, #=zu6_AyYcOGi_C3EsKgWxJz2CO6qnOzILP_hZ7W18= #=zkV8eM7k=) at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Next()
at #=zBC2PsSjZPJJwcaWiP37EuS6XXDP0CZH0Xw==.#=ziWbhqtvI9QND(#=zjgMLFCiV6qE_Bpq2c5gzw5s= #=zjx$Qcg2LKG27dt4qVw==, #=z_S90LZaRNwpvmWImgsFtn02fBD4a[] #=z2Lo$W7XMMKR1, #=zzTRj_uMXVaq2j6$SvnL89dut1fdF #=z$Nxs8Gg=, TimeSpan #=zgQ7UIjc=)
at #=zqfE5YK_c2XmntSEWbgVBV$5BM1FB.Render(#=zzTRj_uMXVaq2j6$SvnL89dut1fdF #=z$Nxs8Gg=, TimeSpan #=zgQ7UIjc=, #=zkbaqoeKnLTbtif4YTbJL$MY=[] #=zC01gR9c=)
at #=zoU0hnsxX1kWw1$XRdCrKsQ8QSI0G.Render(#=zzTRj_uMXVaq2j6$SvnL89dut1fdF #=z$Nxs8Gg=, #=zSCjYFIQ= #=zXMXocF8=, TimeSpan #=zgQ7UIjc=)
at #=zoU0hnsxX1kWw1$XRdCrKsQ8QSI0G.Render(#=zzTRj_uMXVaq2j6$SvnL89dut1fdF #=z$Nxs8Gg=, #=zSCjYFIQ= #=zXMXocF8=)
at #=zwzybKmLAKr2nk4h0kcKF$w02nW2t.#=zI6Zmen4=(Stream #=zfu4yBCCzeO9E, Document #=z0Zfxy4qSH0DN, HtmlLoadOptions #=zE1pPT3IS0Eqd, String #=z3micdQ8STZk7)
at #=zwzybKmLAKr2nk4h0kcKF$w02nW2t.#=zI6Zmen4=(Stream #=zfu4yBCCzeO9E, Document #=z0Zfxy4qSH0DN, HtmlLoadOptions #=zE1pPT3IS0Eqd)
at Aspose.Pdf.Document.#=zbr81cto=(Stream #=zgDsdBJM=, LoadOptions #=zY1ySzLA=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at savant_service.Utility.Util.CreatePDFFile(MemoryStream memStream, String htmlText, String footerText) in /opt/app-root/src/savant-service/savant-service/Utility/Util.cs:line 238
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

1 Like

@rnakagawa,

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-48107 in our issue tracking system to investigate and resolve this issue as soon possible.

1 Like

The issues you have found earlier (filed as PDFNET-48107) have been fixed in Aspose.PDF for .NET 20.7.