Skip to content

Commit 56141c2

Browse files
authored
Merge pull request #22 from Api2Pdf/2.0.0
2.0.0
2 parents 6b06dcd + f53c28a commit 56141c2

File tree

8 files changed

+429
-376
lines changed

8 files changed

+429
-376
lines changed

README.md

Lines changed: 104 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# api2pdf.php
2-
PHP code for [Api2Pdf REST API](https://www.api2pdf.com/documentation)
2+
PHP code for [Api2Pdf REST API](https://www.api2pdf.com/documentation/v2)
33

4-
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**.
4+
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**.
55

66
- [Installation](#installation)
77
- [Resources](#resources)
@@ -28,13 +28,11 @@ Run the following from command line:
2828

2929
## Usage without Composer
3030

31-
Copy the files in the `src` directory to a sub-directory in your project, then add the following in the beginning of your PHP file:
31+
Copy the file in the `src` directory to a sub-directory in your project, then add the following in the beginning of your PHP file:
3232

3333
```
3434
require_once 'your-own-directory/Api2Pdf.php';
35-
require_once 'your-own-directory/ApiResult.php';
3635
37-
use Api2Pdf\Api2Pdf;
3836
```
3937

4038
## <a name="resources"></a>Resources
@@ -63,68 +61,56 @@ All usage starts by calling the import command and initializing the client by pa
6361

6462
Once you initialize the client, you can make calls like so:
6563

66-
$result = $apiClient->headlessChromeFromHtml('<p>Hello, World</p>');
67-
echo $result->getPdf();
64+
$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>');
65+
echo $result->getFile();
6866

6967
### Result Format
7068

7169
An ApiResult object is returned from every API call. If a call is unsuccessful then an exception will be thrown with a message containing the result of failure.
7270

73-
Additional attributes include the total data usage in, out, and the cost for the API call, typically very small fractions of a penny.
71+
Additional attributes include the total data usage out, and the cost for the API call, typically very small fractions of a penny.
7472

75-
$pdfLink = $result->getPdf();
76-
$mbIn = $result->getMbIn();
77-
$mbOut = $result->getMbOut();
73+
$file = $result->getFile();
7874
$cost = $result->getCost();
75+
$mbOut = $result->getMbOut();
76+
$seconds = $result->getSeconds();
7977
$responseId = $result->getResponseId();
8078

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

8381
**Convert HTML to PDF**
8482

85-
$result = $apiClient->wkHtmlToPdfFromHtml('<p>Hello, World</p>');
83+
$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>');
8684

8785
**Convert HTML to PDF (load PDF in browser window and specify a file name)**
8886

89-
$apiClient->setInline(true);
90-
$apiClient->setFilename('test.pdf');
91-
$result = $apiClient->wkHtmlToPdfFromHtml('<p>Hello, World</p>');
87+
$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>', $inline = false, $fileName = "test.pdf");
9288

9389
**Convert HTML to PDF (use arguments for advanced wkhtmltopdf settings)**
9490
[View full list of wkhtmltopdf options available.](https://www.api2pdf.com/documentation/advanced-options-wkhtmltopdf/)
9591

96-
$apiClient->setInline(true);
97-
$apiClient->setFilename('test.pdf');
98-
$apiClient->setOptions(
99-
[
100-
'orientation' => 'landscape',
101-
'pageSize'=> 'A4'
102-
]
103-
);
104-
$result = $apiClient->wkHtmlToPdfFromHtml('<p>Hello, World</p>');
92+
$options = [
93+
"orientation" => "landscape",
94+
"pageSize" => "A4"
95+
];
96+
$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>', $options = $options);
10597

10698
**Convert URL to PDF**
10799

108-
$result = $apiClient->wkHtmlToPdfFromUrl('http://www.api2pdf.com');
100+
$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com');
109101

110102
**Convert URL to PDF (load PDF in browser window and specify a file name)**
111103

112-
$apiClient->setInline(true);
113-
$apiClient->setFilename('test.pdf');
114-
$result = $apiClient->wkHtmlToPdfFromUrl('http://www.api2pdf.com');
104+
$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com', $inline = false, $fileName = "test.pdf");
115105

116106
**Convert URL to PDF (use arguments for advanced wkhtmltopdf settings)**
117107
[View full list of wkhtmltopdf options available.](https://www.api2pdf.com/documentation/advanced-options-wkhtmltopdf/)
118108

119-
$apiClient->setInline(true);
120-
$apiClient->setFilename('test.pdf');
121-
$apiClient->setOptions(
122-
[
123-
'orientation' => 'landscape',
124-
'pageSize'=> 'A4'
125-
]
126-
);
127-
$result = $apiClient->wkHtmlToPdfFromUrl('http://www.api2pdf.com');
109+
$options = [
110+
"orientation" => "landscape",
111+
"pageSize" => "A4"
112+
];
113+
$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com', $options = $options);
128114

129115

130116
---
@@ -133,108 +119,132 @@ Additional attributes include the total data usage in, out, and the cost for the
133119

134120
**Convert HTML to PDF**
135121

136-
$result = $apiClient->headlessChromeFromHtml('<p>Hello, World</p>');
122+
$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>');
137123

138124
**Convert HTML to PDF (load PDF in browser window and specify a file name)**
139125

140-
$apiClient->setInline(true);
141-
$apiClient->setFilename('test.pdf');
142-
$result = $apiClient->headlessChromeFromHtml('<p>Hello, World</p>');
126+
$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>', $inline = false, $filename = "test.pdf");
143127

144128
**Convert HTML to PDF (use arguments for advanced Headless Chrome settings)**
145129
[View full list of Headless Chrome options available.](https://www.api2pdf.com/documentation/advanced-options-headless-chrome/)
146130

147-
$apiClient->setInline(true);
148-
$apiClient->setFilename('test.pdf');
149-
$apiClient->setOptions(
150-
[
151-
'landscape' => true,
152-
'printBackground' => false
153-
]
154-
);
155-
$result = $apiClient->headlessChromeFromHtml('<p>Hello, World</p>');
131+
$options = [
132+
"landscape" => true
133+
];
134+
$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>', $options = $options);
156135

157136
**Convert URL to PDF**
158137

159-
$result = $apiClient->headlessChromeFromUrl('http://www.api2pdf.com');
138+
$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com');
160139

161140
**Convert URL to PDF (load PDF in browser window and specify a file name)**
162141

163-
$apiClient->setInline(true);
164-
$apiClient->setFilename('test.pdf');
165-
$result = $apiClient->headlessChromeFromUrl('http://www.api2pdf.com');
142+
$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com', $inline = false, $filename = "test.pdf");
166143

167144
**Convert URL to PDF (use arguments for advanced Headless Chrome settings)**
168145
[View full list of Headless Chrome options available.](https://www.api2pdf.com/documentation/advanced-options-headless-chrome/)
169146

170-
$apiClient->setInline(true);
171-
$apiClient->setFilename('test.pdf');
172-
$apiClient->setOptions(
173-
[
174-
'landscape' => true,
175-
'printBackground' => false
176-
]
177-
);
178-
$result = $apiClient->headlessChromeFromUrl('http://www.api2pdf.com');
147+
$options = [
148+
"landscape" => true
149+
];
150+
$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com', $options = $options);
151+
152+
**Convert HTML to Image**
153+
154+
$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>');
155+
156+
**Convert HTML to Image (load image in browser window and specify a file name)**
157+
158+
$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>', $inline = false, $filename = "test.jpg");
159+
160+
**Convert HTML to Image (use arguments for advanced Headless Chrome settings)**
161+
[View full list of Headless Chrome options available.](https://www.api2pdf.com/documentation/advanced-options-headless-chrome/)
162+
163+
$options = [
164+
"fullPage" => true
165+
];
166+
$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>', $options = $options);
167+
168+
**Convert URL to Image**
169+
170+
$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com');
171+
172+
**Convert URL to Image (load image in browser window and specify a file name)**
173+
174+
$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com', $inline = false, $filename = "test.jpg");
175+
176+
**Convert URL to Image (use arguments for advanced Headless Chrome settings)**
177+
[View full list of Headless Chrome options available.](https://www.api2pdf.com/documentation/advanced-options-headless-chrome/)
178+
179+
$options = [
180+
"landscape" => true
181+
];
182+
$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com', $options = $options);
179183

180184
---
181185

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

184-
LibreOffice supports the conversion to PDF from the following file formats:
185-
186-
- doc / docx
187-
- xls / xlsx
188-
- ppt / pptx
189-
- gif
190-
- jpg
191-
- png
192-
- bmp
193-
- rtf
194-
- txt
195-
- html
188+
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.
196189

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

199192
**Convert Microsoft Office Document or Image to PDF**
200193

201-
$result = $apiClient->libreOfficeConvert('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');
202-
203-
**Convert Microsoft Office Document or Image to PDF (load PDF in browser window and specify a file name)**
194+
$result = $apiClient->libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');
204195

205-
$apiClient->setInline(true);
206-
$apiClient->setFilename('test.pdf');
207-
$result = $apiClient->libreOfficeConvert('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');
208-
196+
**Thumbnail or Image Preview of a PDF or Office Document or Email file**
197+
198+
$result = $apiClient->libreOfficeThumbnail('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');
199+
200+
**Convert HTML to Microsoft Word or Docx**
201+
202+
$result = $apiClient->libreOfficeHtmlToDocx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html');
203+
204+
**Convert HTML to Microsoft Excel or Xlsx**
205+
206+
$result = $apiClient->libreOfficeHtmlToXlsx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html');
207+
208+
**Convert PDF to HTML**
209+
210+
$result = $apiClient->libreOfficePdfToHtml('http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf');
209211
---
210212

211-
## <a name="merge"></a>Merge / Concatenate Two or More PDFs
213+
## <a name="merge"></a>PdfSharp - Merge / Concatenate Two or More PDFs, Add bookmarks to pdfs, add passwords to pdfs
212214

213-
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.
215+
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.
214216

215217
**Merge PDFs from list of URLs to existing PDFs**
216218

217219
$linksToPdfs = ['https://LINK-TO-PDF', 'https://LINK-TO-PDF'];
218-
$mergeResult = $apiClient->merge($linksToPdfs)
220+
$mergeResult = $apiClient->pdfsharpMerge($linksToPdfs)
219221

220-
**Merge PDFs from list of URLs to existing PDFs (load PDF in browser window and specify a file name)**
222+
**Add bookmarks to existing PDF**
221223

222-
$apiClient->setInline(true);
223-
$apiClient->setFilename('test.pdf');
224-
$linksToPdfs = ['https://LINK-TO-PDF', 'https://LINK-TO-PDF'];
225-
$mergeResult = $apiClient->merge($linksToPdfs)
224+
$linkToPdf = 'https://LINK-TO-PDF';
225+
$bookmarks = [
226+
[ "Page" => 0, "Title" => "Introduction" ],
227+
[ "Page" => 1, "Title" => "Second page" ]
228+
];
229+
$bookmarkResult = $apiClient->pdfsharpMerge($linkToPdf, $bookmarks)
230+
231+
**Add password to existing PDF**
232+
233+
$linkToPdf = 'https://LINK-TO-PDF';
234+
$userpassword = 'hello';
235+
$bookmarkResult = $apiClient->pdfsharpMerge($linkToPdf, $userpassword)
226236

227237
---
228238

229239
## <a name="helper-methods"></a>Helper Methods
230240

231241
**delete($responseId)**
232242

233-
By default, Api2Pdf deletes your PDFs 24 hours after they have been generated. For developers who require higher levels of security and wish to delete their PDFs can make a DELETE request API call by using the `responseId` retrieved from the original request.
243+
By default, Api2Pdf will delete your generated file 24 hours after it has been generated. For those with high security needs, you may want to delete your file on command. You can do so by making an DELETE api call with the `responseId` attribute that was returned on the original JSON payload.
234244

235-
$result = $apiClient->headlessChromeFromHtml("<p>Hello World</p>");
245+
$result = $apiClient->chromeHtmlToPdf("<p>Hello World</p>");
236246
$responseId = $result->getResponseId();
237247
//delete pdf
238-
$apiClient->delete($responseId);
248+
$apiClient->utilityDelete($responseId);
239249

240250

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api2pdf/api2pdf.php",
3-
"description": "A client library for API2PDF service to convert HTML to PDF",
3+
"description": "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",
44
"license": "MIT",
55
"homepage": "https://www.api2pdf.com",
66
"support": {

0 commit comments

Comments
 (0)