فهرست منبع

new release and minor fixes in docs

Jhonny Mertz 4 سال پیش
والد
کامیت
2b3da9decb

+ 2 - 2
CONTRIBUTING.md

@@ -5,6 +5,6 @@ Requirements
 Running tests
 ------------
 
-This repo has two kinds of tests: integration and unit test.
+This repo has two kinds of tests: integration (dependent on `wkhtmltopdf`) and unit tests.
 
-Use `mvn test -B` to run only the unit tests.
+By default, `mvn clean install` runs all the tests. Use `mvn test -B` to run only the unit tests.

+ 2 - 2
README.md

@@ -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.12-RELEASE'
+    compile 'com.github.jhonnymertz:java-wkhtmltopdf-wrapper:1.1.13-RELEASE'
 }
 ```
 
@@ -26,7 +26,7 @@ In your `pom.xml`:
 <dependency>
     <groupId>com.github.jhonnymertz</groupId>
     <artifactId>java-wkhtmltopdf-wrapper</artifactId>
-    <version>1.1.12-RELEASE</version>
+    <version>1.1.13-RELEASE</version>
 </dependency>
 ```
 

+ 1 - 1
pom.xml

@@ -3,7 +3,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.github.jhonnymertz</groupId>
     <artifactId>java-wkhtmltopdf-wrapper</artifactId>
-    <version>1.1.12-RELEASE</version>
+    <version>1.1.13-RELEASE</version>
     <packaging>jar</packaging>
 
     <name>Java WkHtmlToPdf Wrapper</name>

+ 25 - 6
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/Pdf.java

@@ -26,7 +26,7 @@ import java.util.UUID;
 import java.util.concurrent.*;
 
 /**
- * Represents a Pdf file
+ * Represents a Pdf file and wraps up the wkhtmltopdf processing
  */
 public class Pdf {
 
@@ -51,6 +51,8 @@ public class Pdf {
 
     private File tempDirectory;
 
+    private static String TEMPORARY_FILE_PREFIX = "java-wkhtmltopdf-wrapper";
+
     private String outputFilename = null;
 
     private List<Integer> successValues = new ArrayList<Integer>(Arrays.asList(0));
@@ -177,9 +179,9 @@ public class Pdf {
      * Executes the wkhtmltopdf saving the results directly to the specified file path.
      *
      * @param path The path to the file where the PDF will be saved.
-     * @return
-     * @throws IOException
-     * @throws InterruptedException
+     * @return the pdf file saved
+     * @throws IOException when not able to save the file
+     * @throws InterruptedException when the PDF generation process got interrupted
      */
     public File saveAsDirect(String path) throws IOException, InterruptedException {
         File file = new File(path);
@@ -188,6 +190,14 @@ public class Pdf {
         return file;
     }
 
+    /**
+     * Generates a PDF file as byte array from the wkhtmltopdf output
+     *
+     * @return the PDF file as a byte array
+     * @throws IOException when not able to save the file
+     * @throws InterruptedException when the PDF generation process got interrupted
+     * @throws PDFExportException when the wkhtmltopdf process fails
+     */
     public byte[] getPDF() throws IOException, InterruptedException, PDFExportException {
 
         ExecutorService executor = Executors.newFixedThreadPool(2);
@@ -219,6 +229,15 @@ public class Pdf {
         }
     }
 
+    /**
+     * Get command as array string
+     *
+     * Note: htmlAsString pages are first store into a temp file, then the location is used in the wkhtmltopdf command
+     * this is a workaround to avoid huge commands
+     *
+     * @return the wkhtmltopdf command as string array
+     * @throws IOException when not able to save temporary files from htmlAsString
+     */
     protected String[] getCommandAsArray() throws IOException {
         List<String> commandLine = new ArrayList<String>();
 
@@ -241,7 +260,7 @@ public class Pdf {
                 // wkhtmltopdf, this is a workaround to avoid huge commands
                 if (page.getFilePath() != null)
                     Files.deleteIfExists(Paths.get(page.getFilePath()));
-                File temp = File.createTempFile("java-wkhtmltopdf-wrapper" + UUID.randomUUID().toString(), ".html", tempDirectory);
+                File temp = File.createTempFile(TEMPORARY_FILE_PREFIX + UUID.randomUUID().toString(), ".html", tempDirectory);
                 FileUtils.writeStringToFile(temp, page.getSource(), "UTF-8");
                 page.setFilePath(temp.getAbsolutePath());
                 commandLine.add(temp.getAbsolutePath());
@@ -306,7 +325,7 @@ public class Pdf {
      * Gets the final wkhtmltopdf command as string
      *
      * @return the generated command from params
-     * @throws IOException
+     * @throws IOException when not able to save temporary files from htmlAsString
      */
     public String getCommand() throws IOException {
         return StringUtils.join(getCommandAsArray(), " ");

+ 15 - 0
src/main/java/com/github/jhonnymertz/wkhtmltopdf/wrapper/page/PageType.java

@@ -1,7 +1,22 @@
 package com.github.jhonnymertz.wkhtmltopdf.wrapper.page;
 
+/**
+ * The Page type accepted by wkhtmltopdf
+ */
 public enum PageType {
+
+    /**
+     * Html as string
+     */
     htmlAsString,
+
+    /**
+     * Url page
+     */
     url,
+
+    /**
+     * File page
+     */
     file
 }