Skip to content

Commit

Permalink
Merge pull request #6 from Api2Pdf/2.0.0
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
apexdodge committed Jul 11, 2021
2 parents 568c1bf + fc41816 commit 26b4e34
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 591 deletions.
127 changes: 87 additions & 40 deletions README.md
Expand Up @@ -2,9 +2,9 @@
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.api2pdf.client/api2pdf/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.api2pdf.client/api2pdf)

# api2pdf.java
Java client for [Api2Pdf REST API](https://www.api2pdf.com/documentation)
Java client for [Api2Pdf REST API](https://www.api2pdf.com/documentation/v2)

Api2Pdf.com is a REST API for instantly generating PDF documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), and images. The API also supports merge / concatenation of two or more PDFs. Api2Pdf is a wrapper for popular libraries such as **wkhtmltopdf**, **Headless Chrome**, and **LibreOffice**.
Api2Pdf.com is a powerful REST API for instantly generating PDF and Office documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), Email files, and images. You can generate image preview or thumbnail of a PDF, office document, or email file. The API also supports merge / concatenation of two or more PDFs, setting passwords on PDFs, and adding bookmarks to PDFs. Api2Pdf is a wrapper for popular libraries such as **wkhtmltopdf**, **Headless Chrome**, **PdfSharp**, and **LibreOffice**.

- [Installation](#installation)
- [Resources](#resources)
Expand All @@ -21,7 +21,7 @@ The Java client library is available as a Maven Package and can be installed wit
<dependency>
<groupId>com.api2pdf.client</groupId>
<artifactId>api2pdf</artifactId>
<version>1.0.4</version>
<version>2.0.0</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -55,37 +55,37 @@ All usage starts by importing the api2pdf library and creating a new object.
Once you initialize the client, you can make calls like so:

```
Api2PdfResponse pdfResponse = a2pClient.headlessChromeFromHtml("<p>test</p>", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.chromeHtmlToPdf("<p>test</p>", true, "test.pdf");
System.out.println(response.getFile());
```

### Successful Result Format

{
'pdf': 'https://link-to-pdf-only-available-for-24-hours',
'mbIn': 0.08421039581298828,
'mbOut': 0.08830547332763672,
'cost': 0.00017251586914062501,
'success': true,
'error': null,
'responseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
'FileUrl': 'https://link-to-pdf-only-available-for-24-hours',
'Seconds': 0.08421039581298828,
'MbOut': 0.08830547332763672,
'Cost': 0.00017251586914062501,
'Success': true,
'Error': null,
'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}

### Failed Result Format

{
'success': false,
'error': 'some reason for the error',
'responseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
'Success': false,
'Error': 'some reason for the error',
'ResponseId': '6e46637a-650d-46d5-af0b-3d7831baccbb'
}

## <a name="wkhtmltopdf"></a> wkhtmltopdf

**Convert HTML to PDF (load PDF in browser window (true or false) and specify a file name)**.

```
Api2PdfResponse pdfResponse = a2pClient.wkhtmlToPdfFromHtml("<p>Hello, World</p>", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.wkhtmlHtmlToPdf("<p>Hello, World</p>", true, "test.pdf");
System.out.println(response.getFile());
```

**Convert HTML to PDF (use HashMap for advanced wkhtmltopdf settings)**
Expand All @@ -95,15 +95,15 @@ System.out.println(pdfResponse.getPdf());
Map<String, String> options = new HashMap<String, String>();
options.put("orientation", "landscape");
options.put("pageSize", "A4");
Api2PdfResponse pdfResponse = a2pClient.wkhtmlToPdfFromHtml("<p>Hello, World</p>", true, "test.pdf", options);
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.wkhtmlHtmlToPdf("<p>Hello, World</p>", true, "test.pdf", options);
System.out.println(response.getFile());
```

**Convert URL to PDF (load PDF in browser window (true or false) and specify a file name)**.

```
Api2PdfResponse pdfResponse = a2pClient.wkhtmlToPdfFromUrl("https://www.github.com", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.wkhtmlUrlToPdf("https://www.github.com", true, "test.pdf");
System.out.println(response.getFile());
```

**Convert URL to PDF (use HashMap for advanced wkhtmltopdf settings)**
Expand All @@ -113,8 +113,8 @@ System.out.println(pdfResponse.getPdf());
Map<String, String> options = new HashMap<String, String>();
options.put("orientation", "landscape");
options.put("pageSize", "A4");
Api2PdfResponse pdfResponse = a2pClient.wkhtmlToPdfFromUrl("https://www.github.com", true, "test.pdf", options);
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.wkhtmlUrlToPdf("https://www.github.com", true, "test.pdf", options);
System.out.println(response.getFile());
```

---
Expand All @@ -124,8 +124,8 @@ System.out.println(pdfResponse.getPdf());
**Convert HTML to PDF (load PDF in browser window (true or false) and specify a file name)**

```
Api2PdfResponse pdfResponse = a2pClient.headlessChromeFromHtml("<p>Hello World</p>", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.chromeHtmlToPdf("<p>Hello World</p>", true, "test.pdf");
System.out.println(response.getFile());
```

**Convert HTML to PDF (use HashMap for advanced Headless Chrome settings)**
Expand All @@ -134,15 +134,15 @@ System.out.println(pdfResponse.getPdf());
```
Map<String, String> options = new HashMap<String, String>();
options.put("landscape", "true");
Api2PdfResponse pdfResponse = a2pClient.headlessChromeFromHtml("<p>Hello World</p>", true, "test.pdf", options);
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.chromeHtmlToPdf("<p>Hello World</p>", true, "test.pdf", options);
System.out.println(response.getFile());
```

**Convert URL to PDF (load PDF in browser window (true or false) and specify a file name)**

```
Api2PdfResponse pdfResponse = a2pClient.headlessChromeFromUrl("https://www.github.com", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.chromeUrlToPdf("https://www.github.com", true, "test.pdf");
System.out.println(response.getFile());
```

**Convert URL to PDF (use HashMap for advanced Headless Chrome settings)**
Expand All @@ -151,37 +151,84 @@ System.out.println(pdfResponse.getPdf());
```
Map<String, String> options = new HashMap<String, String>();
options.put("landscape", "true");
Api2PdfResponse pdfResponse = a2pClient.headlessChromeFromUrl("https://www.github.com", true, "test.pdf", options);
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.chromeUrlToPdf("https://www.github.com", true, "test.pdf", options);
System.out.println(response.getFile());
```

**Convert HTML to Image (load PDF in browser window (true or false) and specify a file name)**

```
Api2PdfResponse response = a2pClient.chromeHtmlToImage("<p>Hello World</p>", true, "test.png");
System.out.println(response.getFile());
```

**Convert URL to Image (load PDF in browser window (true or false) and specify a file name)**

```
Api2PdfResponse response = a2pClient.chromeUrlToImage("https://www.github.com", true, "test.png");
System.out.println(response.getFile());
```

---

## <a name="libreoffice"></a>LibreOffice

LibreOffice supports the conversion to PDF from the following file formats:

- doc, docx, xls, xlsx, ppt, pptx, gif, jpg, png, bmp, rtf, txt, html
Convert any office file to PDF, image file to PDF, email file to PDF, HTML to Word, HTML to Excel, and PDF to HTML. Any file that can be reasonably opened by LibreOffice should be convertible. Additionally, we have an endpoint for generating a *thumbnail* of the first page of your PDF or Office Document. This is great for generating an image preview of your files to users.

You must provide a url to the file. Our engine will consume the file at that URL and convert it to the PDF.

**Convert Microsoft Office Document or Image to PDF (load PDF in browser window (true or false) and specify a file name)**

```
Api2PdfResponse pdfResponse = a2pClient.libreofficeConvert("https://your-url-to-file", true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.libreofficeAnyToPdf("https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx", true, "test.pdf");
System.out.println(response.getFile());
```


**Thumbnail or Image Preview of a PDF or Office Document or Email file**

```
Api2PdfResponse response = a2pClient.libreofficeThumbnail("https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx", true, "test.png");
System.out.println(response.getFile());
```

**Convert HTML to Microsoft Word or Docx**

```
Api2PdfResponse response = a2pClient.libreofficeHtmlToDocx("http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html", true, "test.png");
System.out.println(response.getFile());
```

**Convert HTML to Microsoft Excel or Xlsx**

```
Api2PdfResponse response = a2pClient.libreofficeHtmlToDocx("http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html", true, "test.docx");
System.out.println(response.getFile());
```

**Convert HTML to Microsoft Excel or Xlsx**

```
Api2PdfResponse response = a2pClient.libreofficeHtmlToXlsx("http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html", true, "test.xlsx");
System.out.println(response.getFile());
```

**Convert PDF to HTML**

```
Api2PdfResponse response = a2pClient.libreofficeHtmlToXlsx("http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf", true, "test.png");
System.out.println(response.getFile());
```

---

## <a name="merge"></a>Merge / Concatenate Two or More PDFs
## <a name="merge"></a>PdfSharp

To use the merge endpoint, supply a list of urls to existing PDFs. The engine will consume all of the PDFs and merge them into a single PDF, in the order in which they were provided in the list.

**Merge PDFs from array of URLs to existing PDFs (load PDF in browser window (true or false) and specify a file name)****

```
String[] urls = { "your-url-to-pdf1.pdf", "your-url-to-pdf2.pdf" };
Api2PdfResponse pdfResponse = a2pClient.merge(urls, true, "test.pdf");
System.out.println(pdfResponse.getPdf());
Api2PdfResponse response = a2pClient.pdfsharpMerge(urls, true, "test.pdf");
System.out.println(response.getFile());
```
7 changes: 3 additions & 4 deletions api2pdf/pom.xml
Expand Up @@ -9,13 +9,12 @@
<artifactId>
api2pdf
</artifactId>
<version>1.0.3</version>
<version>2.0.0</version>
<name>
api2pdf
</name>
<description>
Api2Pdf is a powerful PDF generation API with no rate limits or file size constraints.
Generate PDFs from HTML, URLs, images, office documents, and more.
This client library is a wrapper for the Api2Pdf.com REST API. See full REST api documentation at https://www.api2pdf.com/documentation/v2. Api2Pdf is a powerful API that supports HTML to PDF, URL to PDF, HTML to Image, URL to Image, Thumbnail / image preview of an Office file, Office files (Word to PDF), HTML to Docx, HTML to excel, PDF to HTML, merge PDFs together, add bookmarks to PDFs, add passwords to PDFs
</description>
<url>
https://www.api2pdf.com/
Expand Down Expand Up @@ -75,7 +74,7 @@
https://github.com/Api2Pdf/api2pdf.java
</url>
<tag>
api2pdf-1.0.13
api2pdf-2.0.0
</tag>
</scm>
<properties>
Expand Down

0 comments on commit 26b4e34

Please sign in to comment.