Drawing lines

This is a code example of iText PDF, discover more.

31st May 2016

Switch code for this example


    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;

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);
        new DrawingLines().manipulatePdf(DEST);

    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);
                .moveTo(36, 36)
                .lineTo(36, 806)
                .lineTo(559, 36)
                .lineTo(559, 806)

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now