Skip to main content
Skip table of contents

pdfHTML: Fixed Behavior for <input> Tags with Negative Numbers

Introduction

The <input> tag is essentially a text box in HTML, and the value that the tag contains is displayed in that text box. More information about the <input> tag can be found here.

In pdfHTML 3.0.0 and earlier versions, when the tag had the number attribute (<input type="number">) an empty rectangle would be rendered in the resulting PDF, as shown below: 

broken-input-tag.png

Empty <input> tag

However, in pdfHTML 3.0.1 released along with iText Core version 7.1.12, this behavior has been fixed and the number is correctly displayed:

fixed-input-tag.png

Correctly rendered <input> tag

Example code

JAVA
package misc.articleExamples.input;

import com.itextpdf.html2pdf.HtmlConverter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class NegativeInputHtml {

	public static void main(String[] args) {
		String html = "<!doctype html>\n" +
			"<html>\n" +
			"<head>\n" +
			"</head>\n" +
			"<body>\n" +
			"<div><label>Label</label><input type=\"number\" value=\"-4\">\n" +
			"</div>\n" +
			"</body>\n" +
			"</html>";
		try {
			HtmlConverter.convertToPdf(html, new FileOutputStream("src/main/java/misc/articleExamples/out.pdf"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
C#
using iText.Html2pdf;
using System;
using System.IO;

namespace Articles
{
    class Program
    {
        static void Main(string[] args)
        {
            string html = "<!doctype html>\n" +
                "<html>\n" +
                "<head>\n" +
                "</head>\n" +
                "<body>\n" +
                "<div><label>Label</label><input type=\"number\" value=\"-4\">\n" +
                "</div>\n" +
                "</body>\n" +
                "</html>";

            try
            {
                HtmlConverter.ConvertToPdf(html, new FileStream("src/main/java/misc/articleExamples/out.pdf", FileMode.Create);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.