إضافة أشكال دائرة إلى PDF في Java

إضافة حدود دائرة

  1. أنشئ PDF جديد Document.
  2. أضف Page إلى الوثيقة.
  3. أنشئ كائنًا من الفئة Graph الحاوية وإضافتها إلى الصفحة.
  4. أنشئ كائنًا من الفئة Circle الشكل واضبط هندسته.
  5. أضف Circle إلى Graph الحاوية.
  6. عيّن خصائص الشكل المطلوبة في المثال، بما في ذلك Color.
  7. احفظ ملف 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());
    }
}

إضافة دائرة مملوءة بالنص

  1. أنشئ PDF جديد Document.
  2. أضف Page إلى الوثيقة.
  3. أنشئ كائنًا من الفئة Graph الحاوية وإضافتها إلى الصفحة.
  4. أنشئ كائنًا من الفئة Circle الشكل واضبط هندسته.
  5. أضف Circle إلى Graph الحاوية.
  6. عيّن خصائص الشكل المطلوبة في المثال، بما في ذلك Color و TextFragment.
  7. احفظ ملف 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());
    }
}