إضافة أشكال دائرة إلى PDF في Java
Contents
[
Hide
]
إضافة حدود دائرة
- أنشئ PDF جديد Document.
- أضف Page إلى الوثيقة.
- أنشئ كائنًا من الفئة Graph الحاوية وإضافتها إلى الصفحة.
- أنشئ كائنًا من الفئة Circle الشكل واضبط هندسته.
- أضف Circle إلى Graph الحاوية.
- عيّن خصائص الشكل المطلوبة في المثال، بما في ذلك Color.
- احفظ ملف PDF الناتج Document.
public static void addCircle(Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
Graph graph = new Graph(400.0, 200.0);
graph.setBorder(new BorderInfo(BorderSide.All, Color.getGreen()));
Circle circle = new Circle(100, 100, 40);
circle.getGraphInfo().setColor(Color.getGreenYellow());
graph.getShapes().addItem(circle);
page.getParagraphs().add(graph);
document.save(outputFile.toString());
}
}
إضافة دائرة مملوءة بالنص
- أنشئ PDF جديد Document.
- أضف Page إلى الوثيقة.
- أنشئ كائنًا من الفئة Graph الحاوية وإضافتها إلى الصفحة.
- أنشئ كائنًا من الفئة Circle الشكل واضبط هندسته.
- أضف Circle إلى Graph الحاوية.
- عيّن خصائص الشكل المطلوبة في المثال، بما في ذلك Color و TextFragment.
- احفظ ملف PDF الناتج Document.
public static void addCircleFilled(Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
Graph graph = new Graph(400.0, 200.0);
graph.setBorder(new BorderInfo(BorderSide.All, Color.getGreen()));
Circle circle = new Circle(100, 100, 40);
circle.getGraphInfo().setColor(Color.getGreenYellow());
circle.getGraphInfo().setFillColor(Color.getGreen());
circle.setText(new TextFragment("Circle"));
graph.getShapes().addItem(circle);
page.getParagraphs().add(graph);
document.save(outputFile.toString());
}
}