StrokeColorPDF.java Source code

Java tutorial

Introduction

Here is the source code for StrokeColorPDF.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class StrokeColorPDF {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("StrokeColorPDF.pdf"));

            document.open();
            PdfContentByte cb = writer.getDirectContent();

            cb.setLineWidth(10f);
            cb.setRGBColorStrokeF(0f, 255f, 0f);
            cb.moveTo(100, 700);
            cb.lineTo(200, 800);

            cb.stroke();

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }
}