GeezerVison is showing github.com — itext create pdf · 1eozhang/Java@85cb624
File tree
Expand file treeCollapse file tree
Open diff view settings
src/main/java/com/hmkcode
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<classpath> |
| 3 | + <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/> |
| 4 | + <classpathentry kind="src" path="src/main/java" including="**/*.java"/> |
| 5 | + <classpathentry kind="output" path="target/classes"/> |
| 6 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
| 7 | + <classpathentry kind="var" path="M2_REPO/com/itextpdf/itextpdf/5.4.2/itextpdf-5.4.2.jar"/> |
| 8 | +</classpath> |
Collapse file
Copy file name to clipboard Collapse file
Copy file name to clipboard Collapse file
Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 3 | + <modelVersion>4.0.0</modelVersion> |
| 4 | + |
| 5 | + <groupId>com.hmkcode</groupId> |
| 6 | + <artifactId>itext-create-pdf</artifactId> |
| 7 | + <version>1.0-SNAPSHOT</version> |
| 8 | + <packaging>jar</packaging> |
| 9 | + |
| 10 | + <name>itext-create-pdf</name> |
| 11 | + <url>http://maven.apache.org</url> |
| 12 | + |
| 13 | + <properties> |
| 14 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 15 | + </properties> |
| 16 | + |
| 17 | + <dependencies> |
| 18 | + <dependency> |
| 19 | + <groupId>com.itextpdf</groupId> |
| 20 | + <artifactId>itextpdf</artifactId> |
| 21 | + <version>5.4.2</version> |
| 22 | + </dependency> |
| 23 | + </dependencies> |
| 24 | +</project> |
Collapse file
Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +package com.hmkcode; |
| 2 | + |
| 3 | +import java.io.FileNotFoundException; |
| 4 | +import java.io.FileOutputStream; |
| 5 | + |
| 6 | +import com.itextpdf.text.Document; |
| 7 | +import com.itextpdf.text.DocumentException; |
| 8 | +import com.itextpdf.text.Paragraph; |
| 9 | +import com.itextpdf.text.pdf.PdfWriter; |
| 10 | + |
| 11 | + |
| 12 | +public class HelloWorld |
| 13 | +{ |
| 14 | + public static void main( String[] args ) |
| 15 | + { |
| 16 | + try { |
| 17 | + |
| 18 | + // 1. create the document |
| 19 | + Document document = new Document(); |
| 20 | + // 2. get PdfWriter |
| 21 | + PdfWriter.getInstance(document, new FileOutputStream("helloworld.pdf")); |
| 22 | + // 3. open the document |
| 23 | + document.open(); |
| 24 | + // 4. add the content |
| 25 | + document.add(new Paragraph("Hello World!")); |
| 26 | + // 5. close the document |
| 27 | + document.close(); |
| 28 | + |
| 29 | + System.out.println("Document created!"); |
| 30 | + |
| 31 | + } catch (FileNotFoundException e) { |
| 32 | + e.printStackTrace(); |
| 33 | + } catch (DocumentException e) { |
| 34 | + e.printStackTrace(); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
Collapse file
Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +package com.hmkcode; |
| 2 | + |
| 3 | +import java.io.FileNotFoundException; |
| 4 | +import java.io.FileOutputStream; |
| 5 | + |
| 6 | +import com.itextpdf.text.Document; |
| 7 | +import com.itextpdf.text.DocumentException; |
| 8 | +import com.itextpdf.text.PageSize; |
| 9 | +import com.itextpdf.text.Paragraph; |
| 10 | +import com.itextpdf.text.Rectangle; |
| 11 | +import com.itextpdf.text.pdf.PdfWriter; |
| 12 | + |
| 13 | + |
| 14 | +public class PageSettings |
| 15 | +{ |
| 16 | + public static void main( String[] args ) |
| 17 | + { |
| 18 | + try { |
| 19 | + |
| 20 | + // 1. create the document page size: A4, margins: left:20 right:20 top:40 bottom:40 |
| 21 | + Document document = new Document(PageSize.A4, 20f,20f,40f,40); |
| 22 | + |
| 23 | + //for custom pagesize |
| 24 | + //Rectangle pagesize = new Rectangle(216f, 720f); |
| 25 | + |
| 26 | + // 2. get PdfWriter |
| 27 | + PdfWriter.getInstance(document, new FileOutputStream("pagesettings.pdf")); |
| 28 | + // 3. open the document |
| 29 | + document.open(); |
| 30 | + // 4. add the content |
| 31 | + document.add(new Paragraph("Hello World!")); |
| 32 | + // 5. close the document |
| 33 | + document.close(); |
| 34 | + |
| 35 | + System.out.println("Document created!"); |
| 36 | + |
| 37 | + } catch (FileNotFoundException e) { |
| 38 | + e.printStackTrace(); |
| 39 | + } catch (DocumentException e) { |
| 40 | + e.printStackTrace(); |
| 41 | + } |
| 42 | + } |
| 43 | +} |