danfickle / danfickle/openhtmltopdf

[Accessibility][ScreenReader]Problem with bold, italics, underline text in generated PDF

Open
#680 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2.2k
Forks
423
PR merge metrics
No merged PRs in 30d

Description

EDIT: I tested the HTML fragment (in the end of post) in https://sandbox.openhtmltopdf.com/ and it shows the same behavior I described (try to select the line to see it happen).

Hello,

When we have some text with formatting (bold), the resulting PDF is kind of weird. The formatted text shows correctly in the PDF, but when I select the text (as seen in the image below), I select the start of the line, then the end, and finally the formatted text. Inspecting in Firefox, the order seems incorrect to me (it is the same I described for selection):
![openhtmltopdf-wrong-order-bold-text](https://user-images.githubusercontent.com/34720010/113010556-4f12ad00-914f-11eb-9cf1-e22fdda4446a.png)

The same problem occurs when a user tries to use a screen reader (such as NVDA) to read the text (it reads in the wrong order).

I want to know if the problem is related to this lib or maybe it is in the PDFBox

Below, the code used to generate the PDF:
```java
private static final String ESTILO_BASE = " "
+ " body { word-wrap: break-word; font-family: 'Courier New', Courier, monospace; }"
+ " table { width: 100% !important } "
+ " @page {margin-bottom: 1.5cm; margin-top: 4.5cm; margin-left: 2.6cm; margin-right: 1cm;}";
private static final String CABECALHO_XHTML = "\n" + "]>\n";

public byte[] obterPdf(DocumentoParaAssinaturaDto documentoDto, String produtorDocumento) {
String idProcessoDocumento = documentoDto.getIdProcessoDocumentoCurto();
ByteArrayOutputStream streamPdfa = new ByteArrayOutputStream();
try {
byte[] html = Base64.decodeBase64(documentoDto.getDocumentoBinarioBase64());
OrientacaoDocumentoHTMLEnum orientacaoDocumento = documentoDto.getOrientacaoDocumento();
PdfRendererBuilder geradorPdf = new PdfRendererBuilder();
String htmlConteudo = ESTILO_BASE + orientacaoDocumento.getCSS()
+ new String(html, StandardCharsets.ISO_8859_1);
Document htmlDoc = Jsoup.parse(htmlConteudo);
htmlDoc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
String htmlConteudoAjustado = new HTMLLimpezaServico().limpar(htmlDoc);
// Deve ser incluido o doctype com a entity   no topo do XHTML para o gerador funcionar
htmlConteudoAjustado = CABECALHO_XHTML + htmlConteudoAjustado;

geradorPdf.withProducer(produtorDocumento);
geradorPdf.useFastMode();
geradorPdf.withHtmlContent(htmlConteudoAjustado, "");
geradorPdf.toStream(streamPdfa);
geradorPdf.run();
} catch (Exception e) {
throw new ConversaoHtmlParaPdfException(MensagensAssinaturaEnum.ERRO_CONVERSAO_HTML_PDF, e,
idProcessoDocumento);
}

return streamPdfa.toByteArray();
}
```

the html used to that image is:
```html

Em relação ao crédito remanescente da autora, determino a transferência do numerário para a conta indicada na petição de ID


```
thanks in advance and congrats for this work!
A. Lucas

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.