Hexadecimal value 0x04- is an invalid character

I’m getting the error “hexadecimal value 0x04, is an invalid character.” when trying to generate a pdf file.

Any advice on likely culprits would be appreciated.

It’s pdf v5.0.1.

Seems like v4.9 (or even 5.0) against the same code never had this problem.

Hello Erixc,

Thanks for using our products.

Can you please share some code snippet that can help us in reproducing this problem at our end ? We are really sorry for this inconvenience.

In the following, having the img (image) within the header would cause the error:

Dim myHeaderText As New StringBuilder
'removed_img <img src=" & “http://” & myDomain & “/DesktopModules/Surplus_RFQ/Surplus-Solutions-LLC-Logo.png”" width=““200"” height=”“45"” />
myHeaderText.Append(“

<td valign=”“bottom”“><td valign=”“bottom”" align=““right”” nowarp=““nowrap””>Surplus Solutions LLC
151 Broadway, Suite 225, Providence, RI 02903
Office: (401) 276-8233 | Fax: (276) 345-2870
Email: info@SurplusSolutionsLLC.com
")

'Instantiate a Text paragraph that will store the content to show as header
Dim textH As Text = New Text(hf1, myHeaderText.ToString)
textH.IsHtmlTagSupported = True

'Add the text object to the Paragraphs collection of HeaderFooter object to
'display header on the pages of PDF document
hf1.Paragraphs.Add(textH)



Hello Erixc,

Sorry for replying you late.

I have tried executing the source HTML that you have shared and I am afraid I am unable to execute it. But, after little modification to the code, I am able to generate a PDF document with header containing Image and text both. Please take a look over the following code snippet that I have used to test the scenario using Aspose.Pdf for .NET 5.0.1. Can you please share some working code that can help us in reproducing this problem. We apologize for your inconvenience.

As per my observations, you need to insert image and text inside table header. I think the better approach is to use table inside header and place the contents inside it. For more related information, please visit Table in Header/Footer section

[VB.NET]

Dim pdf1 As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
Create a section in the Pdf object
Dim sec1 As Aspose.Pdf.Section = pdf1.Sections.Add()

Dim hf1 As Aspose.Pdf.HeaderFooter = New Aspose.Pdf.HeaderFooter()
Dim myHeaderText As New StringBuilder
myHeaderText.Append("

Surplus Solutions LLC
151 Broadway, Suite 225, Providence, RI 02903
Office: (401) 276-8233 | Fax: (276) 345-2870
Email: info@SurplusSolutionsLLC.com
")
myHeaderText.Append("<img src=d:/pdftest/Aspose.jpg width='200' height='45'/>")

'Instantiate a Text paragraph that will store the content to show as header
Dim textH As Text = New Text(hf1, myHeaderText.ToString)
textH.IsHtmlTagSupported = True
'Add the text object to the Paragraphs collection of HeaderFooter object to
'display header on the pages of PDF document
hf1.Paragraphs.Add(textH)
sec1.OddHeader = hf1
sec1.EvenHeader = hf1
'Save the Pdf
pdf1.Save("d:/pdftest/HeaderFooter_InvalidCharacter-Issue.pdf")