pl.vane.pdf.factory.PDFWriter.java Source code

Java tutorial

Introduction

Here is the source code for pl.vane.pdf.factory.PDFWriter.java

Source

/*
    
 Copyright (c) 2015-2015, Michal Szczepanski
 All rights reserved.
    
 This source code is licensed under the BSD-style license found in the
 LICENSE file in the root directory of this source tree.
    
 */

package pl.vane.pdf.factory;

import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;

import java.awt.*;
import java.io.IOException;

/**
 * Author: Michal Szczepanski
 * Date: 23/03/15
 * Time: 23:43
 */
public class PDFWriter {
    public static void drawString(PDPageContentStream stream, PDFont font, int fontSize, double leading, float x,
            float y, String text) throws IOException {
        stream.setStrokingColor(Color.BLACK);
        stream.setNonStrokingColor(Color.BLACK);
        stream.beginText();
        stream.setFont(font, fontSize);
        stream.setLeading(leading);
        stream.newLineAtOffset(x, y);
        for (String line : text.split("\n")) {
            stream.showText(line);
            stream.newLine();
        }
        stream.endText();

    }
}