参照pdfbox2.0.0修改的。给出两点坐标连成一条直线。
package testpdf1;import java.io.IOException;import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.pdmodel.PDPage;import org.apache.pdfbox.pdmodel.PDPageContentStream;/** * Create a blank PDF and write the contents to a file. */public final class drawline{ private drawline() { } @SuppressWarnings("deprecation") public static void main(String[] args) throws IOException { String filename = "/Users/pengfei/Desktop/per.pdf"; PDDocument doc = new PDDocument(); try { // a valid PDF document requires at least one page PDPage blankPage = new PDPage(); doc.addPage(blankPage); PDPageContentStream contentStream = new PDPageContentStream(doc, blankPage); contentStream.setStrokingColor(66, 177, 230); contentStream.drawLine(100, 100, 200, 100); contentStream.drawLine(20, 20, 800, 800); contentStream.close(); doc.save(filename); } finally { doc.close(); } }}