Skip to content

Commit

Permalink
Merge pull request #57 from jhonnymertz/pdfbox_update
Browse files Browse the repository at this point in the history
Updating pdfbox dependency and fixing build warning
  • Loading branch information
jhonnymertz committed Jul 5, 2019
2 parents 04e97ae + af89683 commit 905a9a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If you are using Gradle/Maven, see example below:
In your `build.gradle`:
```groovy
dependencies {
compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.10-RELEASE'
compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.11-RELEASE'
}
```

Expand All @@ -26,7 +26,7 @@ In your `pom.xml`:
<dependency>
<groupId>com.github.jhonnymertz</groupId>
<artifactId>java-wkhtmltopdf-wrapper</artifactId>
<version>1.1.10-RELEASE</version>
<version>1.1.11-RELEASE</version>
</dependency>
```

Expand Down
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.jhonnymertz</groupId>
<artifactId>java-wkhtmltopdf-wrapper</artifactId>
<version>1.1.10-RELEASE</version>
<version>1.1.11-RELEASE</version>
<packaging>jar</packaging>

<name>Java WkHtmlToPdf Wrapper</name>
Expand Down Expand Up @@ -38,18 +38,24 @@
</developer>
</developers>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.9</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.6</version>
</dependency>

<dependency>
Expand All @@ -75,7 +81,7 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.16</version>
<version>2.0.16</version>
<scope>test</scope>
</dependency>

Expand All @@ -93,6 +99,7 @@
<!-- Show 100% of the lines from the stack trace (doesn't work) -->
<trimStackTrace>false</trimStackTrace>
</configuration>
<version>2.22.1</version>
<executions>
<execution>
<id>unit-tests</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.WrapperConfig;
import com.github.jhonnymertz.wkhtmltopdf.wrapper.configurations.XvfbConfig;
import com.github.jhonnymertz.wkhtmltopdf.wrapper.params.Param;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripper;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -89,13 +88,9 @@ public void testRemovingGeneratedFile() throws Exception {
}

private String getPdfTextFromBytes(byte[] pdfBytes) throws IOException {
PDFParser parser = new PDFParser(new ByteArrayInputStream(pdfBytes));
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
String text = new PDFTextStripper().getText(pdDocument);

// that is a valid PDF (otherwise an IOException occurs)
parser.parse();
PDFTextStripper pdfTextStripper = new PDFTextStripper();
PDDocument pdDocument = new PDDocument(parser.getDocument());
String text = pdfTextStripper.getText(pdDocument);
pdDocument.close();
return text;
}
Expand Down Expand Up @@ -128,13 +123,8 @@ public void testPdfWithXvfb() throws Exception {

// WHEN
byte[] pdfBytes = pdf.getPDF();

PDFParser parser = new PDFParser(new ByteArrayInputStream(pdfBytes));

// that is a valid PDF (otherwise an IOException occurs)
parser.parse();
PDFTextStripper pdfTextStripper = new PDFTextStripper();
String pdfText = pdfTextStripper.getText(new PDDocument(parser.getDocument()));
PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(pdfBytes));
String pdfText = new PDFTextStripper().getText(pdDocument);

Assert.assertThat("document should be generated", pdfText, containsString("Google"));
}
Expand Down

0 comments on commit 905a9a9

Please sign in to comment.