Example usage for com.lowagie.text.pdf PdfContentByte moveTo

List of usage examples for com.lowagie.text.pdf PdfContentByte moveTo

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte moveTo.

Prototype


public void moveTo(float x, float y) 

Source Link

Document

Move the current point (x, y), omitting any connecting line segment.

Usage

From source file:br.org.archimedes.io.pdf.elements.LineExporter.java

License:Open Source License

public void exportElement(Line line, Object outputObject) throws IOException {

    PDFWriterHelper helper = (PDFWriterHelper) outputObject;
    PdfContentByte cb = helper.getPdfContentByte();

    Point initial = helper.modelToDocument(line.getInitialPoint());
    Point ending = helper.modelToDocument(line.getEndingPoint());
    float x = (float) initial.getX();
    float y = (float) initial.getY();
    cb.moveTo(x, y);
    x = (float) ending.getX();
    y = (float) ending.getY();
    cb.lineTo(x, y);//  www  .  ja v a  2  s  .co  m
    cb.stroke();
}

From source file:br.org.archimedes.io.pdf.elements.LinePointsExporter.java

License:Open Source License

/**
 * @param points/*  www. j av a  2 s  .  com*/
 *            The points that form the line within the helper view area
 */
public void exportLine(List<Point> points) {
    PdfContentByte cb = helper.getPdfContentByte();

    if (points != null && points.size() == 2) {
        Point initial = points.get(0);
        Point ending = points.get(1);

        float x = (float) initial.getX();
        float y = (float) initial.getY();
        cb.moveTo(x, y);
        x = (float) ending.getX();
        y = (float) ending.getY();
        cb.lineTo(x, y);
        cb.stroke();
    }
}

From source file:ch.gpb.elexis.kgexporter.pdf.HeaderFooterPageEvent.java

License:Open Source License

public void onStartPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(sbHeader),
            rect.getLeft(), rect.getTop(), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, new Phrase(sDate),
            rect.getRight(), rect.getTop(), 0);

    PdfContentByte cb = writer.getDirectContentUnder();

    //cb.rectangle(document.left(), document.top(),
    //   document.right() - document.left(), document.top() - 25);
    /*/*ww  w  .java  2 s.com*/
    System.out.println("l: " + document.left());
    System.out.println("r: " + document.right());
    System.out.println("t: " + document.top());
    System.out.println("b: " + document.bottom());
    l: 36.0
    r: 559.0
    t: 806.0
    b: 36.0
    */

    //Rectangle rect2 = new Rectangle(document.top() - 36, document.top() - 36, 559, 1);

    /*
    float l = 36f;
    float r = 36f;
    float t = 559f;
    float b = 2f;
            
    Rectangle rect2 = new Rectangle(l, r, t, b);
            
    //Rectangle rect2 = new Rectangle(36, 36, 559, 1);
    rect2.setBorder(Rectangle.BOTTOM);
    rect2.setBorderWidth(0.5f);
    cb.rectangle(rect2);
            
    //cb.setColorStroke(Color.BLACK);
    */

    /*
    for (int i = 30; i > 0; i--) {
        System.err.println((float) i / 10);
        cb.setLineWidth((float) i / 10);
        cb.moveTo(36, 806 - (5 * i));
        cb.lineTo(400, 806 - (5 * i));
        cb.stroke();
    }
    cb.moveTo(10, 50);
    cb.lineTo(559, 50);
     */
    cb.setLineWidth(0.5f);
    cb.moveTo(30, 791);
    cb.lineTo(559, 791);

    cb.stroke();

}

From source file:ch.gpb.elexis.kgexporter.pdf.HeaderFooterPageEvent.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = writer.getBoxSize("art");
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(this.sbFooter),
            rect.getLeft(), rect.getBottom(), 0);

    /*/*w  w w  .  j av  a2s.  co  m*/
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("Bottom Right"),
       rect.getRight(), rect.getBottom(), 0);
    */
    PdfContentByte cb = writer.getDirectContentUnder();

    cb.setLineWidth(0.5f);

    cb.moveTo(30, 50);
    cb.lineTo(559, 50);
    cb.stroke();

}

From source file:classroom.filmfestival_c.Movies19.java

protected static void drawGrid(PdfWriter writer, List<String> places, String day, float left,
        float column_width, float top, float row_height) {

    // CANVAS//from w ww .  j  a  v  a  2 s.com
    PdfContentByte directcontent = writer.getDirectContent();
    Rectangle art = writer.getBoxSize("art");

    // LINES

    directcontent.setLineWidth(1);
    float bottom = art.getTop();

    // rows
    int rows = places.size();
    for (int i = 0; i <= rows; i++) {
        directcontent.moveTo(art.getLeft(), art.getTop() - (i * row_height));
        directcontent.lineTo(art.getRight(), art.getTop() - (i * row_height));
        bottom = art.getTop() - (i * row_height);
    }

    // Rectangle
    directcontent.moveTo(art.getLeft(), art.getTop());
    directcontent.lineTo(art.getLeft(), bottom);
    directcontent.moveTo(left, art.getTop());
    directcontent.lineTo(left, bottom);
    directcontent.moveTo(art.getLeft() + (COLUMNS * column_width), art.getTop());
    directcontent.lineTo(art.getLeft() + (COLUMNS * column_width), bottom);
    directcontent.stroke();

    // columns
    directcontent.saveState();
    directcontent.setLineWidth(0.3f);
    directcontent.setColorStroke(SILVER);
    directcontent.setLineDash(3, 1);
    for (int i = 2; i < COLUMNS; i++) {
        directcontent.moveTo(art.getLeft() + (i * column_width), art.getTop());
        directcontent.lineTo(art.getLeft() + (i * column_width), bottom);
    }
    directcontent.stroke();
    directcontent.restoreState();

    // TEXT

    // date
    directcontent.beginText();
    directcontent.setFontAndSize(FONT, 12);
    directcontent.showTextAligned(Element.ALIGN_RIGHT, day, art.getLeft() - 5, art.getTop(), 90);
    directcontent.endText();

    // time
    for (int i = 1; i < COLUMNS; i++) {
        directcontent.beginText();
        directcontent.setFontAndSize(FONT, 8);
        directcontent.showTextAligned(Element.ALIGN_LEFT, TIME[i - 1], art.getLeft() + (i * column_width) + 5,
                top + 5, 90);
        directcontent.endText();
    }

    // places
    for (int i = 0; i < rows; i++) {
        directcontent.beginText();
        directcontent.setFontAndSize(FONT, 12);
        directcontent.showTextAligned(Element.ALIGN_CENTER, places.get(i), art.getLeft() + 16,
                art.getTop() - ((i + 0.5f) * row_height), 90);
        directcontent.endText();
    }
}

From source file:classroom.filmfestival_c.Movies19.java

protected static void drawMovie(PdfWriter writer, FestivalScreening screening, List<String> places,
        float minute, float left, float top, float row_height) throws DocumentException {
    FilmTitle movie = screening.getFilmTitle();
    // defining the rectangle
    int place = places.indexOf(screening.getId().getPlace());
    float llx, urx, lly, ury;
    llx = left + minute * getMinutesAfter930(screening);
    urx = llx + minute * (screening.getShortfilm() + movie.getDuration());
    ury = top - place * row_height;//w  w w  .  j av a2  s  . co  m
    lly = top - ((place + 1) * row_height);

    // FOREGROUND
    PdfContentByte foreground = writer.getDirectContent();

    // rectangle
    foreground.setColorStroke(BLACK);
    foreground.setLineWidth(1);
    foreground.moveTo(urx, lly);
    foreground.lineTo(llx, lly);
    foreground.lineTo(llx, ury);
    foreground.lineTo(urx, ury);
    foreground.closePathStroke();
    // title
    ColumnText ct = new ColumnText(foreground);
    ct.setSimpleColumn(new Phrase(movie.getTitle(), SMALLEST), llx, lly, urx, ury, 14, Element.ALIGN_CENTER);
    ct.go();

    // BACKGROUND
    PdfContentByte background = writer.getDirectContentUnder();

    // draw background
    background.setColorFill(getColor(movie));
    background.moveTo(urx, lly);
    background.lineTo(llx, lly);
    background.lineTo(llx, ury);
    background.lineTo(urx, ury);
    background.fill();

    // draw a white P for press screenings
    if (screening.getPress() == 1) {
        background.saveState();
        background.beginText();
        background.setFontAndSize(FONT, 24);
        background.setColorFill(WHITE);
        background.showTextAligned(Element.ALIGN_CENTER, "P", (llx + urx) / 2f, (lly + ury) / 2f - 12, 0);
        background.endText();
        background.restoreState();
    }

    // draw shortfilm
    background.setColorStroke(WHITE);
    if (screening.getShortfilm() > 0) {
        background.moveTo(llx + (minute * screening.getShortfilm()), lly);
        background.lineTo(llx + (minute * screening.getShortfilm()), ury);
        background.stroke();
    }
}

From source file:classroom.filmfestival_c.Movies22.java

public static void main(String[] args) {
    // step 1//from  w ww.  j av a  2  s  . c  o m
    Document document = new Document(new Rectangle(WIDTH, HEIGHT));
    try {
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM));
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage);
        // step 3
        document.open();
        // step 4
        PdfContentByte cb = writer.getDirectContent();

        // top part of the card
        cb.setColorFill(RED);
        cb.rectangle(0, mm2pt(57f), WIDTH, HEIGHT - mm2pt(57f));
        cb.fill();
        cb.setColorFill(BLACK);
        cb.rectangle(0, mm2pt(61), WIDTH, mm2pt(21f));
        cb.fill();
        cb.setColorFill(WHITE);

        Image kubrick = Image.getInstance(KUBRICK);
        kubrick.scaleToFit(WIDTH, mm2pt(21));
        kubrick.setAbsolutePosition(0, mm2pt(61));
        cb.addImage(kubrick);

        Image logo = Image.getInstance(LOGO);
        logo.scaleToFit(mm2pt(14), mm2pt(14));
        logo.setAbsolutePosition(mm2pt(37), mm2pt(65));
        cb.addImage(logo);

        cb.beginText();
        cb.setFontAndSize(FONT, 7);
        cb.showTextAligned(Element.ALIGN_CENTER, "Flanders International Film Festival-Ghent", WIDTH / 2,
                mm2pt(58.5f), 0);
        cb.endText();

        // bottom part of the card

        TextField filmfestival = new TextField(writer, new Rectangle(0, 0, WIDTH, mm2pt(9)), "filmfestival");
        filmfestival.setBackgroundColor(GRAY);
        filmfestival.setTextColor(WHITE);
        filmfestival.setText("www.filmfestival.be");
        filmfestival.setFontSize(14);
        filmfestival.setOptions(TextField.READ_ONLY);
        filmfestival.setAlignment(Element.ALIGN_CENTER);
        writer.addAnnotation(filmfestival.getTextField());

        cb.beginText();
        cb.moveText(mm2pt(1.5f), mm2pt(12));
        cb.setFontAndSize(FONT, 21);
        cb.setColorFill(RED);
        cb.showText("10");
        cb.setColorFill(BLUE);
        cb.showText("/");
        cb.setColorFill(RED);
        cb.showText("21");
        cb.setColorFill(BLUE);
        cb.showText("OCT");
        cb.setColorFill(GREEN);
        cb.showText("2006");
        cb.endText();
        cb.setColorStroke(BLUE);
        cb.moveTo(mm2pt(24.5f), mm2pt(29));
        cb.lineTo(mm2pt(24.5f), mm2pt(36));
        cb.moveTo(mm2pt(24.5f), mm2pt(48));
        cb.lineTo(mm2pt(24.5f), mm2pt(54));
        cb.stroke();

        // central part of the card
        PushbuttonField photo = new PushbuttonField(writer,
                new Rectangle(mm2pt(3), mm2pt(29), mm2pt(24), mm2pt(54)), "photo");
        PdfTemplate t1 = cb.createTemplate(mm2pt(21), mm2pt(25));
        t1.setColorFill(GRAY);
        t1.rectangle(0, 0, mm2pt(21), mm2pt(25));
        t1.fill();
        photo.setTemplate(t1);
        photo.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        writer.addAnnotation(photo.getField());

        TextField type = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(46), WIDTH - mm2pt(1.5f), mm2pt(54)), "type");
        type.setTextColor(GRAY);
        type.setText("TYPE");
        type.setFontSize(0);
        writer.addAnnotation(type.getTextField());

        TextField number = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(44), WIDTH - mm2pt(1.5f), mm2pt(48)), "number");
        number.setText("N\u00b0 0000000");
        number.setFontSize(8);
        writer.addAnnotation(number.getTextField());

        TextField name = new TextField(writer,
                new Rectangle(mm2pt(26), mm2pt(28), WIDTH - mm2pt(1.5f), mm2pt(40)), "name");
        name.setText("Name");
        name.setFontSize(8);
        name.setOptions(TextField.MULTILINE);
        writer.addAnnotation(name.getTextField());

        PushbuttonField barcode = new PushbuttonField(writer,
                new Rectangle(mm2pt(3), mm2pt(23), WIDTH - mm2pt(3), mm2pt(28)), "barcode");
        PdfTemplate t2 = cb.createTemplate(WIDTH - mm2pt(6), mm2pt(5));
        t2.setColorFill(GRAY);
        t2.rectangle(0, 0, WIDTH - mm2pt(6), mm2pt(5));
        t2.fill();
        barcode.setTemplate(t2);
        barcode.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
        writer.addAnnotation(barcode.getField());

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // step 4
    document.close();
}

From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java

License:Open Source License

public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc,
        boolean whiteBackground) throws Exception {
    final int margin = 15;
    File f = File.createTempFile("cages__", ".pdf");
    Document doc = new Document(PageSize.A4.rotate());
    Image maleImg, femaleImg, nosexImg;
    try {/* w  ww.j av a2 s. c o m*/
        maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png"));
        femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png"));
        nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png"));
    } catch (Exception e) {
        throw new Exception("Could not find images in the classpath: " + e);
    }

    FileOutputStream os = new FileOutputStream(f);
    PdfWriter writer = PdfWriter.getInstance(doc, os);
    doc.open();

    PdfContentByte canvas = writer.getDirectContentUnder();

    float tileW = (doc.getPageSize().getWidth()) / 4;
    float tileH = (doc.getPageSize().getHeight()) / 2;
    for (int i = 0; i < cages.size(); i++) {
        Container cage = cages.get(i);

        Study study = cage.getStudy();
        Set<Group> groups = cage.getGroups();
        Group group = cage.getGroup();
        Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME);
        animals.addAll(cage.getBiosamples());

        //Find the treatments applied to this group
        Set<NamedTreatment> allTreatments = new LinkedHashSet<>();
        for (Group gr : groups) {
            allTreatments.addAll(gr.getAllTreatments(-1));
        }

        //Draw
        if (i % 8 == 0) {
            if (i > 0)
                doc.newPage();
            drawCageSeparation(doc, canvas);
        }

        int col = (i % 8) % 4;
        int row = (i % 8) / 4;

        float x = margin + tileW * col;
        float x2 = x + tileW - margin;
        float baseY = tileH * row;
        float y;

        //Display Sex
        canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50));
        Image img = null;
        String sex = getMetadata(animals, "Sex");
        if (study.isBlindAll()) {
            img = nosexImg;
        } else if (sex.equals("M")) {
            img = maleImg;
        } else if (sex.equals("F")) {
            img = femaleImg;
        } else if (sex.length() > 0) {
            img = nosexImg;
        }
        if (img != null) {
            img.scaleToFit(20, 20);
            img.setAbsolutePosition(tileW * (col + 1) - 33,
                    doc.getPageSize().getHeight() - (tileH * row + 12 + margin));
            doc.add(img);
        }
        if (group != null && group.getColor() != null && (study != null && !study.isBlind())
                && !whiteBackground) {
            Color c = group.getColor();
            canvas.saveState();
            canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170);
            canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2,
                    tileH - 2);
            canvas.fill();
            canvas.restoreState();
        }
        Color treatmentColor = Color.BLACK;
        if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) {
            int offset = 0;
            for (NamedTreatment t : allTreatments) {
                if (t.getColor() != null) {
                    if (allTreatments.size() == 1)
                        treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2,
                                t.getColor().getBlue() / 2);
                    canvas.saveState();
                    canvas.setColorStroke(Color.BLACK);
                    canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(),
                            t.getColor().getBlue());
                    y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28;
                    canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4,
                            22, 22);
                    canvas.fillStroke();
                    canvas.restoreState();
                    offset++;
                }
            }
        }

        canvas.beginText();
        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f);
        canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x,
                doc.getPageSize().getHeight() - (baseY + 23), 0);

        canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f);
        y = 42 + baseY;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 15;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 86;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 22;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 14;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 23;
        if (study != null && !study.isBlind() && printGroupsTreatments)
            canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 50;
        canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0);
        y += 13;
        canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0);
        canvas.endText();

        y = 42 + baseY;
        print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65,
                doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f);
        y += 15;

        if (animals.size() <= 6) {
            int n = 0;
            for (Biosample animal : animals) {
                print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50,
                        12, 12, FontFactory.HELVETICA, Color.BLACK, 11f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60,
                            doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD,
                            Color.BLACK, 11f);
                }
                n++;
            }
        } else {
            int nPerRow = animals.size() / 2;
            int n = 0;
            for (Biosample animal : animals) {
                int nx = n / nPerRow;
                int ny = n % nPerRow;
                print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2,
                        doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12,
                        FontFactory.HELVETICA, Color.BLACK, 10f);
                if (animal.getSampleName() != null && animal.getSampleName().length() > 0) {
                    print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35,
                            doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12,
                            12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f);
                }
                n++;
            }
        }

        y += 86;
        print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0,
                10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10,
                FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 22;
        print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11,
                BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 14;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11,
                    BaseFont.HELVETICA_BOLD, Color.BLACK, 11f);
        y += 23;
        if (!study.isBlind() && printGroupsTreatments)
            print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y,
                    x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor,
                    printTreatmentDesc ? 9f : 10f);
        y += 50;
        print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2,
                15, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
        y += 13;
        print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2,
                20, 10, FontFactory.HELVETICA, Color.BLACK, 10f);
    }

    doc.close();
    os.close();
    Desktop.getDesktop().open(f);
    try {
        Thread.sleep(500);
    } catch (Exception e) {
    }

}

From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java

License:Open Source License

private static void drawCageSeparation(Document doc, PdfContentByte canvas) {
    canvas.setLineWidth(1f);//from   www.j  av a 2 s . co  m
    canvas.setColorStroke(Color.BLACK);
    canvas.moveTo(0, doc.getPageSize().getHeight() / 2);
    canvas.lineTo(doc.getPageSize().getWidth(), doc.getPageSize().getHeight() / 2);
    canvas.moveTo(doc.getPageSize().getWidth() / 4, 0);
    canvas.lineTo(doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight());
    canvas.moveTo(2 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getBottom());
    canvas.lineTo(2 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight());
    canvas.moveTo(3 * doc.getPageSize().getWidth() / 4, 0);
    canvas.lineTo(3 * doc.getPageSize().getWidth() / 4, doc.getPageSize().getHeight());
    canvas.stroke();
}

From source file:com.estate.pdf.Page.java

protected void drawLine(float x1, float y1, float x2, float y2, Color color) {
    PdfContentByte cb = writer.getDirectContentUnder();
    // Set our line color
    cb.setColorStroke(color);//from  w w w .  j ava  2 s  .  co  m
    cb.setLineWidth(.75f);

    // do the line
    cb.moveTo(x1, y1);
    cb.lineTo(x2, y2);
    cb.stroke();

}