Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Draw Shape in PDF with iText
How to draw shapes in PDF using iText Java Library?
✍: FYIcenter.com
Here is a tutorial for creating a PDF document with some drawing shapes
using iText Java Library.
1. Create a Java file, DrawingShape.java:
/**
* Drawing shapes in PDF with iText
*/
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.kernel.pdf.canvas.*;
import com.itextpdf.layout.*;
import java.io.*;
public class DrawingShape {
public static void main(String args[]) throws IOException {
PdfWriter writer = new PdfWriter("shape.pdf");
PdfDocument pdf = new PdfDocument(writer);
PdfCanvas canvas = new PdfCanvas(pdf.addNewPage());
canvas.moveTo(72, 72).lineTo(360, 72).stroke();
canvas.rectangle(144, 144, 72, 72).fill();
canvas.circle(360, 144, 72).fill();
pdf.close();
}
}
2. Run the Java program iText 7 Java Library.
fyicenter$ java -cp java -cp kernel-7.1.4.jar:layout-7.1.4.jar: \ io-7.1.4.jar:slf4j-api-1.7.31.jar \ DrawingShape.java fyicenter$ ls -l *.pdf 1043 shape.pdf
3. View the new PDF, shape.pdf, in a browser. You see a PDF page with some drawing shapes.
⇒ Get PDF Document Info with iText
⇐ Embed Image in PDF with iText
2022-04-28, ∼2024🔥, 1💬
Popular Posts:
What is ojdbc.jar - JDBC Driver for Oracle? ojdbc.jar is a JDBC driver from Oracle that provides dat...
Java Servlet 3.0 Specification API. JAR File Size and Download Location: File name: servlet-api.jar,...
JDK 17 jdk.localedata.jmod is the JMOD file for JDK 17 Localedata module. JDK 17 Locale Data module ...
What Is commons-fileupload-1.3.3 .jar?commons-fileupload-1.3.3 .jaris the JAR file for Apache Common...
JDK 11 java.xml.jmod is the JMOD file for JDK 11 XML (eXtensible Markup Language) module. JDK 11 XML...