Skip to content

Commit 9afcfac

Browse files
committed
Merge branch 'SZUE-master'
Conflicts: .gitignore src/main/java/be/quodlibet/boxable/Table.java
2 parents 7e165d7 + 7f7db05 commit 9afcfac

22 files changed

+1465
-487
lines changed

.classpath

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/main/java">
4+
<attributes>
5+
<attribute name="FROM_GRADLE_MODEL" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src/test/java">
9+
<attributes>
10+
<attribute name="FROM_GRADLE_MODEL" value="true"/>
11+
</attributes>
12+
</classpathentry>
13+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
14+
<attributes>
15+
<attribute name="maven.pomderived" value="true"/>
16+
</attributes>
17+
</classpathentry>
18+
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
19+
<classpathentry exported="true" kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
20+
<classpathentry kind="con" path="org.springsource.ide.eclipse.gradle.dsld.classpathcontainer"/>
21+
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
22+
<classpathentry kind="con" path="GROOVY_SUPPORT"/>
23+
<classpathentry kind="output" path="target/classes"/>
24+
</classpath>

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ manifest.mf
1010
*.jar
1111
*.war
1212
*.ear
13-
.project
14-
.classpath
13+
1514
.idea
1615
target
1716
*.iml
17+
/bin/
18+
/build/
19+
.settings
20+
.gradle
21+
.metadata

.project

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>boxable</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
23+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
24+
</natures>
25+
</projectDescription>

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
boxable
22
=======
33

4-
54
Create tables in pdf documents using [PDFBox](http://pdfbox.apache.org)
65

76
- Example pdf can be found at [examples](http://goo.gl/a7QvRM)
87

98
- Example code can be found at [SampleCode](https://github.com/dhorions/boxable/blob/master/src/test/java/be/quodlibet/boxable/TableTest.java)
109

10+
The project is Java 7 compliant.
11+
1112
Maven :
1213
The project can be used as a Maven dependency by using jitpack.io.
1314
* add the repository :

build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apply plugin: 'java'
2+
3+
sourceCompatibility = 1.7
4+
5+
/*
6+
* Gets the version name from the latest Git tag
7+
*/
8+
def getVersionName = {
9+
->
10+
def stdout = new ByteArrayOutputStream()
11+
exec {
12+
commandLine 'git', 'describe', '--tags'
13+
standardOutput = stdout
14+
}
15+
return stdout.toString().trim()
16+
}
17+
version = getVersionName()
18+
group = 'com.github.dgautier'
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
compile 'org.apache.pdfbox:pdfbox:2.0.0-RC2'
26+
compile 'org.slf4j:slf4j-api:1.7.10'
27+
compile 'com.google.guava:guava:18.0'
28+
testCompile 'junit:junit:4.12'
29+
}

pom.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44

5-
5+
66
<parent>
77
<groupId>org.sonatype.oss</groupId>
88
<artifactId>oss-parent</artifactId>
99
<version>9</version>
1010
</parent>
11-
11+
1212
<modelVersion>4.0.0</modelVersion>
1313
<groupId>com.github.dgautier</groupId>
1414
<artifactId>boxable</artifactId>
15-
<version>0.1-SNAPSHOT</version>
15+
<version>0.2-SNAPSHOT</version>
1616
<packaging>jar</packaging>
1717

1818
<name>Boxable, a high-level API to creates table on top of Apache Pdfbox</name>
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>org.apache.pdfbox</groupId>
2424
<artifactId>pdfbox</artifactId>
25-
<version>1.8.8</version>
25+
<version>2.0.0-RC1</version>
2626
<scope>compile</scope>
2727
</dependency>
2828

@@ -62,6 +62,18 @@
6262
</execution>
6363
</executions>
6464
</plugin>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-compiler-plugin</artifactId>
68+
<version>3.1</version>
69+
<configuration>
70+
<source>1.7</source>
71+
<target>1.7</target>
72+
<compilerArguments>
73+
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
74+
</compilerArguments>
75+
</configuration>
76+
</plugin>
6577
<plugin>
6678
<groupId>external.atlassian.jgitflow</groupId>
6779
<artifactId>jgitflow-maven-plugin</artifactId>
Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package be.quodlibet.boxable;
22

3+
import java.io.IOException;
4+
35
import org.apache.pdfbox.pdmodel.PDDocument;
46
import org.apache.pdfbox.pdmodel.PDPage;
5-
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
6-
import org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg;
7-
8-
import javax.imageio.ImageIO;
9-
import java.awt.image.BufferedImage;
10-
import java.io.IOException;
11-
import java.io.InputStream;
7+
import org.apache.pdfbox.pdmodel.PDPageContentStream;
8+
import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
9+
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
1210

1311
/**
1412
* Created by dgautier on 3/18/2015.
@@ -19,23 +17,15 @@ public abstract class AbstractPageTemplate extends PDPage {
1917

2018
protected abstract float yStart();
2119

22-
protected void addPicture(PDJpeg ximage, float cursorX, float cursorY, int width, int height) throws IOException {
20+
protected void addPicture(PDImageXObject ximage, float cursorX, float cursorY, int width, int height) throws IOException {
2321

2422
PDPageContentStream contentStream = new PDPageContentStream(getDocument(), this, true, false);
25-
contentStream.drawXObject(ximage, cursorX, cursorY, width, height);
23+
contentStream.drawImage(ximage, cursorX, cursorY, width, height);
2624
contentStream.close();
2725
}
2826

29-
protected PDJpeg loadPicture(String nameJPGFile) throws IOException {
30-
InputStream inputStream = loadStream(nameJPGFile);
31-
BufferedImage awtImage = ImageIO.read(inputStream);
32-
return new PDJpeg(getDocument(), awtImage, 1.0f);
27+
protected PDImage loadPicture(String nameJPGFile) throws IOException {
28+
return PDImageXObject.createFromFile(nameJPGFile, getDocument());
3329
}
3430

35-
private InputStream loadStream(String fileName) {
36-
return getClass().getClassLoader().getResourceAsStream(fileName);
37-
}
38-
39-
40-
4131
}

src/main/java/be/quodlibet/boxable/AbstractTemplatedTable.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
package be.quodlibet.boxable;
22

3+
import java.io.IOException;
4+
35
import org.apache.pdfbox.pdmodel.PDDocument;
46

5-
import java.io.IOException;
7+
import be.quodlibet.boxable.page.PageProvider;
68

79
/**
810
* Created by dgautier on 3/18/2015.
911
*/
1012
public abstract class AbstractTemplatedTable<T extends AbstractPageTemplate> extends Table<T> {
13+
14+
@Deprecated
15+
public AbstractTemplatedTable(float yStart, float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, T currentPage, boolean drawLines, boolean drawContent) throws IOException {
16+
super(yStart, yStartNewPage, bottomMargin, width, margin, document, currentPage, drawLines, drawContent);
17+
}
18+
19+
@Deprecated
20+
public AbstractTemplatedTable(float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, boolean drawLines, boolean drawContent) throws IOException {
21+
super(yStartNewPage, bottomMargin, width, margin, document, drawLines, drawContent);
22+
setYStart(getCurrentPage().yStart());
23+
}
1124

12-
public AbstractTemplatedTable(float yStart, float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, T currentPage, boolean drawLines, boolean drawContent) throws IOException {
13-
super(yStart, yStartNewPage, bottomMargin, width, margin, document, currentPage, drawLines, drawContent);
25+
public AbstractTemplatedTable(float yStart, float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, T currentPage, boolean drawLines, boolean drawContent, PageProvider<T> pageProvider) throws IOException {
26+
super(yStart, yStartNewPage, 0, bottomMargin, width, margin, document, currentPage, drawLines, drawContent, pageProvider);
1427
}
1528

16-
public AbstractTemplatedTable(float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, boolean drawLines, boolean drawContent) throws IOException {
17-
super(yStartNewPage, bottomMargin, width, margin, document, drawLines, drawContent);
29+
public AbstractTemplatedTable(float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, boolean drawLines, boolean drawContent, PageProvider<T> pageProvider) throws IOException {
30+
super(yStartNewPage, 0, bottomMargin, width, margin, document, drawLines, drawContent, pageProvider);
1831
setYStart(getCurrentPage().yStart());
1932
}
2033

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
package be.quodlibet.boxable;
22

33
import java.io.IOException;
4+
45
import org.apache.pdfbox.pdmodel.PDDocument;
56
import org.apache.pdfbox.pdmodel.PDPage;
67

8+
import be.quodlibet.boxable.page.DefaultPageProvider;
9+
import be.quodlibet.boxable.page.PageProvider;
10+
711
/**
812
* Created by dgautier on 3/18/2015.
913
*/
1014
public class BaseTable extends Table<PDPage> {
1115

1216
public BaseTable(float yStart, float yStartNewPage, float bottomMargin, float width, float margin, PDDocument document, PDPage currentPage, boolean drawLines, boolean drawContent) throws IOException {
13-
super(yStart, yStartNewPage, bottomMargin, width, margin, document, currentPage, drawLines, drawContent);
17+
super(yStart, yStartNewPage, 0, bottomMargin, width, margin, document, currentPage, drawLines, drawContent, new DefaultPageProvider(document, currentPage.getMediaBox()));
18+
}
19+
20+
public BaseTable(float yStart, float yStartNewPage, float pageTopMargin, float bottomMargin, float width, float margin, PDDocument document, PDPage currentPage, boolean drawLines, boolean drawContent) throws IOException {
21+
super(yStart, yStartNewPage, pageTopMargin, bottomMargin, width, margin, document, currentPage, drawLines, drawContent, new DefaultPageProvider(document, currentPage.getMediaBox()));
22+
}
23+
24+
public BaseTable(float yStart, float yStartNewPage, float pageTopMargin, float bottomMargin, float width, float margin, PDDocument document, PDPage currentPage, boolean drawLines, boolean drawContent, final PageProvider<PDPage> pageProvider) throws IOException {
25+
super(yStart, yStartNewPage, pageTopMargin, bottomMargin, width, margin, document, currentPage, drawLines, drawContent, pageProvider);
1426
}
1527

1628
@Override
1729
protected void loadFonts() {
1830
// Do nothing as we don't have any fonts to load
1931
}
2032

21-
@Override
22-
protected PDPage createPage()
23-
{
24-
PDPage newPage = new PDPage();
25-
getDocument().addPage(newPage);
26-
return newPage;
27-
}
2833
}
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package be.quodlibet.boxable;
22

3+
import java.io.IOException;
4+
35
import org.apache.pdfbox.pdmodel.PDDocument;
4-
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
6+
import org.apache.pdfbox.pdmodel.font.PDType0Font;
57

6-
import java.io.IOException;
8+
import be.quodlibet.boxable.utils.FontUtils;
79

810
/**
911
* Created by dgautier on 3/19/2015.
12+
*
13+
* @deprecated All methods have been moved elsewhere, see each method for more
14+
* details
1015
*/
16+
@Deprecated
1117
public class BoxableUtils {
1218

13-
public static final PDTrueTypeFont loadFont(PDDocument document,String fontPath) throws IOException {
14-
return PDTrueTypeFont.loadTTF(document, BoxableUtils.class.getClassLoader().getResourceAsStream(fontPath));
15-
}
19+
/**
20+
* @deprecated Use {@link FontUtils#loadFont(PDDocument, String)} instead
21+
*/
22+
@Deprecated
23+
public static final PDType0Font loadFont(PDDocument document, String fontPath) throws IOException {
24+
return PDType0Font.load(document, BoxableUtils.class.getClassLoader().getResourceAsStream(fontPath));
25+
}
1626
}

0 commit comments

Comments
 (0)