字母间距itext转换html iText7

时间:2018-08-31 23:00:13

标签: java itext jsoup

如何执行自动间距,以使文本填充整个div而不会离开blank spaces,文本是动态的,有时会很大,但是在其他小的文本中,{ {1}}的文字是您想要的,转换为html时会丢失pdf

我正在使用:css stylehtml2pdf-2.0.2jsoup-1.11.3

itextpdf-7.1.2

PdfWriter writer = new PdfWriter ( "path" );
PdfDocument pdf = new PdfDocument ( writer );
PdfMerger merger = new PdfMerger ( pdf );
Document document = Jsoup.parse ( listaHtml.get ( index ).replace ( "< !-- body", "body" ), "UTF-8" );
document.select ( "pre" ).first ( ).tagName ( "div" ).attr ( "style", "text-align: justify;text-align-last: justify;font-size: 0.9691em;margin-top: 5px; margin-bottom: 5px;" );

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( );
PdfDocument tempPagePdf = new PdfDocument ( new PdfWriter ( byteArrayOutputStream ) );
HtmlConverter.convertToPdf ( new ByteArrayInputStream ( document .toString ( ).getBytes ( StandardCharsets.UTF_8 ) ), tempPagePdf, properties );
tempPagePdf = new PdfDocument ( new PdfReader ( new ByteArrayInputStream ( byteArrayOutputStream.toByteArray ( ) ) ) );
merger.merge ( tempPagePdf , 1, tempPagePdf .getNumberOfPages ( ) );
tempPagePdf.close ( );
}
pdf.close ( );

0 个答案:

没有答案