// Path: src/main/java/mkl/testarea/pdfbox1/content/PdfRenderingEndorsementAlternative.java
// static public class BandColumn
// {
//     public enum Layout
//     {
//         headerText(150, TEXT_WIDTH, 0, 10),
//         leftHalfPageField(LEFT_MARGIN, FIELD_WIDTH, HALF_WIDTH - 2 * FIELD_WIDTH - 10, 10),
//         rightHalfPageField(HALF_WIDTH, FIELD_WIDTH, HALF_WIDTH - 2 * FIELD_WIDTH - 10, 10);
// 
//         Layout(float x, int fieldWidth, int valueWidth, int space)
//         {
//             this.x = x;
//             this.fieldWidth = fieldWidth;
//             this.valueWidth = valueWidth;
//             this.space = space;
//         }
// 
//         final float x;
//         final int fieldWidth, valueWidth, space;
//     }
// 
//     public BandColumn(Layout layout, String labelField, String value)
//     {
//         this(layout.x, layout.space, labelField, value, layout.fieldWidth, layout.valueWidth);
//     }
// 
//     public BandColumn(float x, int space, String labelField, String value, int fieldWidth, int valueWidth)
//     {
//         this.x = x;
//         this.space = space;
//         this.labelField = labelField;
//         this.value = value;
//         this.fieldWidth = fieldWidth;
//         this.valueWidth = valueWidth;
//     }
// 
//     List<Chunk> toChunks() throws IOException
//     {
//         final List<Chunk> result = new ArrayList<Chunk>();
//         result.addAll(toChunks(0, fieldWidth, PDType1Font.TIMES_BOLD, labelField));
//         result.addAll(toChunks(10 + fieldWidth, valueWidth, PDType1Font.TIMES_ROMAN, value));
//         return result;
//     }
// 
//     List<Chunk> toChunks(int offset, int width, PDFont font, String text) throws IOException
//     {
//         if (text == null || text.length() == 0)
//             return Collections.emptyList();
// 
//         final List<Chunk> result = new ArrayList<Chunk>();
//         float y = -space;
//         List<String> rows = getRows(text, width, font);
//         for (String row: rows)
//         {
//             result.add(new Chunk(x+offset, y, space, font, row));
//             y-= space;
//         }
//         return result;
//     }
// 
//     final float x;
//     final int space, fieldWidth, valueWidth;
//     final String labelField, value;
// }


import static mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn.Layout.leftHalfPageField;
import static mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn.Layout.rightHalfPageField;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.junit.BeforeClass;
import org.junit.Test;
package mkl.testarea.pdfbox1.content;





/**
 * <a href="http://stackoverflow.com/questions/30767643/pdfbox-issue-while-changing-page">
 * PdfBox issue while changing page
 * </a>
 * <p>
 * This test tests the rendering code in {@link PdfRenderingEndorsementAlternative} (which
 * is an alternative approach to the OP's {@link PdfRenderingEndorsement}) using the data
 * from the OP's sample file <a href="https://drive.google.com/file/d/0B-z424N1EYicR1BxUUtUSkw4V1U/view?usp=sharing">Endoso-44-17.pdf</a>.
 * </p>
 * @author mkl
 */
public class RenderEndorsement
{
    final static File RESULT_FOLDER = new File("target/test-outputs", "content");

    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
        RESULT_FOLDER.mkdirs();
    }

    @Test
    public void testAlternativeQuick() throws IOException, COSVisitorException
    {
        String[] header = new String[]
        {
                "Daños - Agrícola y de animales",
                "2015-06-05 / 2016-01-31",
                "FONDO DE ASEGURAMIENTO AGRÍCOLA 21 DE OCTUBRE",
                "FNP-00004408003772000"
        };

        try (   InputStream logo = getClass().getResourceAsStream("Logo.jpg")   )
        {
            PDDocument document = new PDDocument();
            PdfRenderingEndorsementAlternative renderer = new PdfRenderingEndorsementAlternative(document, logo, header);

            renderer.render(
                    new BandColumn(leftHalfPageField, "Nombre del contrato/asegurado:", "Prueba Jesus Fac No Prop"),
                    new BandColumn(rightHalfPageField, "Nombre del contrato/asegurado:", "Prueba Jesus Fac No Prop con Endoso")
                    );

            renderer.gap(20);

            renderer.render(
                    new BandColumn(leftHalfPageField, "País:", "México"),
// Path: src/main/java/mkl/testarea/pdfbox1/content/PdfRenderingEndorsementAlternative.java
// static public class BandColumn
// {
//     public enum Layout
//     {
//         headerText(150, TEXT_WIDTH, 0, 10),
//         leftHalfPageField(LEFT_MARGIN, FIELD_WIDTH, HALF_WIDTH - 2 * FIELD_WIDTH - 10, 10),
//         rightHalfPageField(HALF_WIDTH, FIELD_WIDTH, HALF_WIDTH - 2 * FIELD_WIDTH - 10, 10);
// 
//         Layout(float x, int fieldWidth, int valueWidth, int space)
//         {
//             this.x = x;
//             this.fieldWidth = fieldWidth;
//             this.valueWidth = valueWidth;
//             this.space = space;
//         }
// 
//         final float x;
//         final int fieldWidth, valueWidth, space;
//     }
// 
//     public BandColumn(Layout layout, String labelField, String value)
//     {
//         this(layout.x, layout.space, labelField, value, layout.fieldWidth, layout.valueWidth);
//     }
// 
//     public BandColumn(float x, int space, String labelField, String value, int fieldWidth, int valueWidth)
//     {
//         this.x = x;
//         this.space = space;
//         this.labelField = labelField;
//         this.value = value;
//         this.fieldWidth = fieldWidth;
//         this.valueWidth = valueWidth;
//     }
// 
//     List<Chunk> toChunks() throws IOException
//     {
//         final List<Chunk> result = new ArrayList<Chunk>();
//         result.addAll(toChunks(0, fieldWidth, PDType1Font.TIMES_BOLD, labelField));
//         result.addAll(toChunks(10 + fieldWidth, valueWidth, PDType1Font.TIMES_ROMAN, value));
//         return result;
//     }
// 
//     List<Chunk> toChunks(int offset, int width, PDFont font, String text) throws IOException
//     {
//         if (text == null || text.length() == 0)
//             return Collections.emptyList();
// 
//         final List<Chunk> result = new ArrayList<Chunk>();
//         float y = -space;
//         List<String> rows = getRows(text, width, font);
//         for (String row: rows)
//         {
//             result.add(new Chunk(x+offset, y, space, font, row));
//             y-= space;
//         }
//         return result;
//     }
// 
//     final float x;
//     final int space, fieldWidth, valueWidth;
//     final String labelField, value;
// }


// Path: src/test/java/mkl/testarea/pdfbox1/content/RenderEndorsement.java
import static mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn.Layout.leftHalfPageField;
import static mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn.Layout.rightHalfPageField;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import mkl.testarea.pdfbox1.content.PdfRenderingEndorsementAlternative.BandColumn;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.junit.BeforeClass;
import org.junit.Test;

package mkl.testarea.pdfbox1.content;





/**
 * <a href="http://stackoverflow.com/questions/30767643/pdfbox-issue-while-changing-page">
 * PdfBox issue while changing page
 * </a>
 * <p>
 * This test tests the rendering code in {@link PdfRenderingEndorsementAlternative} (which
 * is an alternative approach to the OP's {@link PdfRenderingEndorsement}) using the data
 * from the OP's sample file <a href="https://drive.google.com/file/d/0B-z424N1EYicR1BxUUtUSkw4V1U/view?usp=sharing">Endoso-44-17.pdf</a>.
 * </p>
 * @author mkl
 */
public class RenderEndorsement
{
    final static File RESULT_FOLDER = new File("target/test-outputs", "content");

    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
        RESULT_FOLDER.mkdirs();
    }

    @Test
    public void testAlternativeQuick() throws IOException, COSVisitorException
    {
        String[] header = new String[]
        {
                "Daños - Agrícola y de animales",
                "2015-06-05 / 2016-01-31",
                "FONDO DE ASEGURAMIENTO AGRÍCOLA 21 DE OCTUBRE",
                "FNP-00004408003772000"
        };

        try (   InputStream logo = getClass().getResourceAsStream("Logo.jpg")   )
        {
            PDDocument document = new PDDocument();
            PdfRenderingEndorsementAlternative renderer = new PdfRenderingEndorsementAlternative(document, logo, header);

            renderer.render(
                    new BandColumn(leftHalfPageField, "Nombre del contrato/asegurado:", "Prueba Jesus Fac No Prop"),
                    new BandColumn(rightHalfPageField, "Nombre del contrato/asegurado:", "Prueba Jesus Fac No Prop con Endoso")
                    );

            renderer.gap(20);

            renderer.render(
                    new BandColumn(leftHalfPageField, "País:", "México"),
                    new BandColumn(rightHalfPageField, "País:", "México")