Java Tutorial/PDF/Arc
Версия от 17:44, 31 мая 2010; (обсуждение)
Draw arc
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document.rupress = false;
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(150, 150);
template.setLineWidth(12f);
template.arc(40f, 10f, 20f, -50f, 90f, 45f);
template.stroke();
template.setLineCap(PdfContentByte.LINE_JOIN_ROUND);
template.arc(80f, 30f, 160f, 10f, 90f, 180f);
template.arc(115f, 65f, 25f, 5f, 0f, 360f);
template.stroke();
cb.addTemplate(template, 0f, 0f);
document.close();
}
}
Fill an arc
import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document.rupress = false;
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
cb.setColorStroke(new GrayColor(0.2f));
cb.setColorFill(new GrayColor(0.9f));
cb.arc(250, 730, 370, 810, 45, 270);
cb.fillStroke();
document.close();
}
}