/* * Copyright (C) 2017 Lukas Zaruba, lukas.zaruba@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ package org.xhtmlrenderer.fop; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import org.junit.Test; import org.xhtmlrenderer.pdf.ITextRenderer; import org.xhtmlrenderer.pdf.ITextUserAgent; import com.itextpdf.text.DocumentException; /** * @author Lukas Zaruba, lukas.zaruba@gmail.com */ public class PDFHyphenationTest { private static final String XML = "\n" + " \n" + " " + " \n" + " \n" + " \n" + " Velice dlouhy text, ktery bude mit problemy se zalamovanim, pokud nebude perfektne nastaveno." + " \n" + ""; @Test public void testGenerator() throws Exception { Path temp = Files.createTempFile("pdfTest", ".pdf"); OutputStream os = Files.newOutputStream(temp); generatePDF(XML, os); System.out.println(temp); } private void generatePDF(String xml, OutputStream os) throws DocumentException, IOException { ITextRenderer renderer = new ITextRenderer(); ITextUserAgent ua = new ITextUserAgent(renderer.getOutputDevice()); ua.setSharedContext(renderer.getSharedContext()); renderer.getSharedContext().setUserAgentCallback(ua); renderer.getSharedContext().setLineBreakingStrategy(new FOPLineBreakingStrategy()); renderer.setDocumentFromString(xml); renderer.layout(); renderer.createPDF(os); } }