Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bolded numeration for no reason #366

Closed
acieplinski opened this issue Jul 8, 2019 · 4 comments
Closed

Bolded numeration for no reason #366

acieplinski opened this issue Jul 8, 2019 · 4 comments

Comments

@acieplinski
Copy link

Hello,
I found some weird behaviour when I generate PDF with 2 or more pages. When there's a bold word (in < strong> tags, as you can see '< strong>expedita< /strong>' in my attachment) in the last line of the page, then numeration on the next page is bold as well (it shouldn't be as there's a < /strong>)
This is my code:

public void htmlToPdf(OutputStream outputStream, String htmlString) {
		try {
			PdfRendererBuilder builder = new PdfRendererBuilder();
			String xhtml = convertToXhtml(htmlString);
			builder.withHtmlContent(xhtml, "");
			builder.toStream(outputStream);
			builder.run();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

There's a 'convertToXhtml' method, I attached xhtml.txt so you can review what is put into 'withHtmlContent(...)'
Have you met that problem? Any idea if I can avoid rendering pdf that way?

xhtml.txt
image

@syjer
Copy link
Contributor

syjer commented Jul 9, 2019

hi @acieplinski , you are right, it's a bug.

I've tested in the sandbox (https://sandbox.openhtmltopdf.com/) and I can reproduce your issue.

As a simple (and temporary) workaround, you can do the following, add a custom style to override the counter:

<style>
ol {
  list-style: none;
  counter-reset: list-counter;
}
ol li {
  counter-increment: list-counter;
}
ol li::before {
  content: counter(list-counter) ". ";
  font-weight: normal;
}
</style>

@acieplinski
Copy link
Author

Could you describe how do you 'inject' the styling? It should be in xhtml in header? Or there's a way to use an external stylesheet?

@syjer
Copy link
Contributor

syjer commented Jul 9, 2019

@acieplinski I think that I would add it inline in the document.

When you get the html string, you convert it in a dom tree, create the style element, add it in the "head" element and you are good to go.

Or yes, you can reference an external css if you want.

@syjer
Copy link
Contributor

syjer commented Nov 16, 2019

Taking a better look at this issue.

A shorter and simpler reproducer:

<html>
<head>
    <style>
        p {
            page-break-after: always;
        }
    </style>
</head>
<body>
<p>
    <b>bolded text</b>
</p>
<ol>
    <li>counter should not be bold</li>
</ol>
</body>
</html>

The counter is currently bold, which is wrong.

What I noticed is in PdfBoxFastOutputDevice.drawStringFast , the call getFontSpecification() (https://github.com/danfickle/openhtmltopdf/blob/open-dev-v1/openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxFastOutputDevice.java#L442 ) return the same FontSpecification as the one used in the "bolded text".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants