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

KeepTogether in paragraph broken with more than one chunk and different font #399

Closed
kunkelt opened this issue Aug 20, 2020 · 0 comments · Fixed by #523
Closed

KeepTogether in paragraph broken with more than one chunk and different font #399

kunkelt opened this issue Aug 20, 2020 · 0 comments · Fixed by #523
Labels
Milestone

Comments

@kunkelt
Copy link

kunkelt commented Aug 20, 2020

The fix of #271 and commit 1d3c049 brought a new issue for our application. Paragraphs with more than one chunk and different fonts lead to unexpected line breaks inside a paragraph.

Code to reproduce:

public class TestBad134 {
	public static final String CREATED_PDF = "./src/test/TestBad134.pdf";

	public static void main(String[] args) {
		Document document = new Document();
		try {
			PdfWriter.getInstance(document, new FileOutputStream(CREATED_PDF));
			document.open();

			Chunk chunk1 = new Chunk("Hier ", FontFactory.getFont(BaseFont.COURIER, 10));
			Chunk chunk2 = new Chunk("fetter", FontFactory.getFont(BaseFont.COURIER_BOLD, 10));
			Chunk chunk3 = new Chunk(" Text", FontFactory.getFont(BaseFont.COURIER, 10));

			Paragraph para = new Paragraph();
			para.add(chunk1);
			para.add(chunk2);
			para.add(chunk3);
			para.setKeepTogether(true);
			document.add(para);
		}
		catch (DocumentException | IOException de) {
			System.err.println(de.getMessage());
		}
		document.close();
	}
}

Result is:
grafik

Expected:
grafik

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