Drawing lines

Tags: iText 7
Files: 
/*
 
    This file is part of the iText (R) project.
    Copyright (c) 1998-2016 iText Group NV
 
*/
 
/**
 * Example written in answer to:
 * http://stackoverflow.com/questions/34267096/
 */
package com.itextpdf.samples.sandbox.graphics;
 
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.color.DeviceCmyk;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.samples.GenericTest;
import com.itextpdf.test.annotations.type.SampleTest;
import org.junit.experimental.categories.Category;
 
import java.io.File;
 
@Category(SampleTest.class)
public class DrawingLines extends GenericTest {
    public static final String DEST = "./target/test/resources/sandbox/graphics/drawing_lines.pdf";
 
    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new DrawingLines().manipulatePdf(DEST);
    }
 
    @Override
    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        PdfCanvas canvas = new PdfCanvas(pdfDoc.addNewPage());
        Color magentaColor = new DeviceCmyk(0.f, 1.f, 0.f, 0.f);
        canvas.setStrokeColor(magentaColor)
                .moveTo(36, 36)
                .lineTo(36, 806)
                .lineTo(559, 36)
                .lineTo(559, 806)
                .closePathStroke();
        pdfDoc.close();
    }
}
File nameRaw URLUpdated
DrawingLines.javaDrawingLines.java2016-08-04 11:32 am
Results: 
File nameRaw URLUpdated
cmp_drawing_lines.pdfcmp_drawing_lines.pdf2016-08-04 11:34 am