I am trying to migrate iText from 7.0.4 to 7.2.5. There were few breaking change in terms of package that I fixed.
The main issue I am now running into is the html to PDF is adding padding / line spacing . This is major blocker since the PDF (letters) to be out of alignment and cannot be printed as per previous spec.
Anyone that has run into this issue before ? I can confirm that the html are the same and the output with change of jars are causing this issue.
private void createPdf(String src, String dest, String resources) throws Exception
{
FileOutputStream outputStream = null;
Document doc = null;
PdfWriter pdfWriter = null;
PdfDocument pdfDoc = null;
FileInputStream inputStream = null;
try
{
outputStream = new FileOutputStream(SecurityUtil.checkFileName(dest));
WriterProperties writerProperties = new WriterProperties();
// Add metadata
writerProperties.addXmpMetadata();
writerProperties.setFullCompressionMode(true);
pdfWriter = new PdfWriter(outputStream, writerProperties);
pdfDoc = new PdfDocument(pdfWriter);
doc = new Document(pdfDoc);
doc.setMargins(50, 50, 100, 50);
pdfDoc.getCatalog().setLang(new PdfString("en-US"));
// Set the document to be tagged
pdfDoc.setTagged();
pdfDoc.getCatalog().setViewerPreferences(new PdfViewerPreferences().setDisplayDocTitle(true));
// Set meta tags
PdfDocumentInfo pdfMetaData = pdfDoc.getDocumentInfo();
pdfMetaData.setAuthor("");
pdfMetaData.addCreationDate();
pdfMetaData.getProducer();
pdfMetaData.setCreator("");
pdfMetaData.setKeywords("letter, accessibility");
pdfMetaData.setSubject("PDF accessibility");
// Title is derived from html
// pdf conversion
ConverterProperties props = new ConverterProperties();
FontProvider fp = new DefaultFontProvider(true, true, true);
LOGSERVICE.logInfo("Font resource Folder:" + resources);
if (!StringUtil.isEmptyAfterTrim(resources))
{
fp.addDirectory(resources);
}
props.setFontProvider(fp);
props.setBaseUri(resources);
// Setup custom tagworker factory for better tagging of headers
DefaultTagWorkerFactory tagWorkerFactory = new AccessibilityTagWorkerFactory();
props.setTagWorkerFactory(tagWorkerFactory);
inputStream = new FileInputStream(SecurityUtil.checkFileName(src));
HtmlConverter.convertToPdf(inputStream, pdfDoc, props);
}
finally
{
if (doc != null)
doc.close();
if (pdfDoc != null)
pdfDoc.close();
if (pdfWriter != null)
pdfWriter.close();
if (outputStream != null)
SecurityUtil.safeClose(outputStream);
if (inputStream != null)
SecurityUtil.safeClose(inputStream);
}
}
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.0.4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>1.0.1</version>
</dependency>
migration to
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>4.0.5</version>
</dependency>