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:
Embed Image in PDF with iText
How to embed images in PDF using iText Java Library?
✍: FYIcenter.com
Here is a tutorial for creating a PDF document with an embedded image
using iText Java Library.
1. Create a Java file, EmbeddedImage.java:
/**
* An image embedded in text in PDF with iText
*/
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.layout.*;
import com.itextpdf.layout.element.*;
import com.itextpdf.io.image.*;
import java.io.*;
public class EmbeddedImage {
public static void main(String args[]) throws IOException {
PdfWriter writer = new PdfWriter("image.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
Image fox = new Image(ImageDataFactory.create("fox.bmp"));
Paragraph p = new Paragraph("The quick brown ")
.add(fox)
.add(" jumps over the lazy dog.");
document.add(p);
document.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 \ EmbeddedImage.java fyicenter$ ls -l *.pdf 11683 image.pdf
3. View the new PDF, image.pdf, in a browser. You see a PDF page with an embedded image.
⇒ Draw Shape in PDF with iText
⇐ Bullet List in PDF with iText
2021-11-13, ∼1655🔥, 0💬
Popular Posts:
JDK 1.1 source code directory contains Java source code for JDK 1.1 core classes: "C:\fyicenter\jdk-...
JAX-WS is an API for building web services and clients. It is the next generation Web Services API r...
MXP1 is a stable XmlPull parsing engine that is based on ideas from XPP and in particular XPP2 but c...
What Is fop.jar? I got it from the fop-2.7-bin.zip. fop.jar in fop-2.7-bin.zip is the JAR file for F...
What Is commons-logging-1.2.jar? commons-logging-1.2.jar is the JAR file for Apache Commons Logging ...