All Projects → Api2Pdf → api2pdf.php

Api2Pdf / api2pdf.php

Licence: MIT license
PHP client library for the Api2Pdf.com REST API - Convert HTML to PDF, URL to PDF, Office Docs to PDF, Merge PDFs, HTML to Image, URL to Image, HTML to Docx, HTML to Xlsx, PDF to HTML, Thumbnail preview of office files

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to api2pdf.php

pydf
PDF generation in python using wkhtmltopdf for heroku and docker
Stars: ✭ 68 (+61.9%)
Mutual labels:  wkhtmltopdf, html-to-pdf, pdf-generation
Snappy
PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
Stars: ✭ 3,986 (+9390.48%)
Mutual labels:  html-to-pdf, pdf-generation, html-to-image
Nbzxing
🔥 2020年最好用的开源扫码,全方位优化,强烈推荐!! 支持多种常规zxing无法扫出的码,用就完了!! 🔥
Stars: ✭ 184 (+338.1%)
Mutual labels:  qrcode, barcode
Escpos Thermalprinter Android
Useful library to help Android developpers to print with (Bluetooth, TCP, USB) ESC/POS thermal printer.
Stars: ✭ 204 (+385.71%)
Mutual labels:  qrcode, barcode
carbone
Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
Stars: ✭ 810 (+1828.57%)
Mutual labels:  libreoffice, pdf-generation
Segno
Python QR Code and Micro QR Code encoder
Stars: ✭ 144 (+242.86%)
Mutual labels:  qrcode, barcode
Rxtool
Android开发人员不得不收集的工具类集合 | 支付宝支付 | 微信支付(统一下单) | 微信分享 | Zip4j压缩(支持分卷压缩与加密) | 一键集成UCrop选择圆形头像 | 一键集成二维码和条形码的扫描与生成 | 常用Dialog | WebView的封装可播放视频 | 仿斗鱼滑动验证码 | Toast封装 | 震动 | GPS | Location定位 | 图片缩放 | Exif 图片添加地理位置信息(经纬度) | 蛛网等级 | 颜色选择器 | ArcGis | VTPK | 编译运行一下说不定会找到惊喜
Stars: ✭ 11,567 (+27440.48%)
Mutual labels:  qrcode, barcode
Qrcodereader
Barcode and QR code reader built in Swift
Stars: ✭ 237 (+464.29%)
Mutual labels:  qrcode, barcode
Zzyqrcode
a scanner for QRCode barCode 最好用的ios二维码、条形码,扫描、生成框架,支持闪光灯,从相册获取,扫描音效等,高仿微信,微博
Stars: ✭ 123 (+192.86%)
Mutual labels:  qrcode, barcode
Etherpad Lite
Etherpad: A modern really-real-time collaborative document editor.
Stars: ✭ 11,937 (+28321.43%)
Mutual labels:  libreoffice, pdf-generation
Carbone
Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
Stars: ✭ 487 (+1059.52%)
Mutual labels:  libreoffice, pdf-generation
Aws Lambda Libreoffice
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Stars: ✭ 145 (+245.24%)
Mutual labels:  libreoffice, pdf-generation
Zxinglite
🔥 ZXing的精简版,优化扫码和生成二维码/条形码,内置闪光灯等功能。扫描风格支持:微信的线条样式,支付宝的网格样式。几句代码轻松拥有扫码功能 ,ZXingLite让集成更简单。(扫码识别速度快如微信)
Stars: ✭ 2,117 (+4940.48%)
Mutual labels:  qrcode, barcode
Barcode
barcode.php - Generate barcodes from a single PHP file. MIT license.
Stars: ✭ 141 (+235.71%)
Mutual labels:  qrcode, barcode
Tc Lib Barcode
PHP library to generate linear and bidimensional barcodes
Stars: ✭ 165 (+292.86%)
Mutual labels:  qrcode, barcode
React Native Qrcode Scanner
A QR code scanner component for React Native.
Stars: ✭ 1,796 (+4176.19%)
Mutual labels:  qrcode, barcode
Qrcoder
A pure C# Open Source QR Code implementation
Stars: ✭ 2,794 (+6552.38%)
Mutual labels:  qrcode, barcode
ZZYQRCode
a scanner for QRCode barCode 最好用的ios二维码、条形码,扫描、生成框架,支持闪光灯,从相册获取,扫描音效等,高仿微信,微博
Stars: ✭ 124 (+195.24%)
Mutual labels:  qrcode, barcode
Swiftscan
A barcode and qr code scanner( 二维码 各种码识别,生成,界面效果)
Stars: ✭ 1,349 (+3111.9%)
Mutual labels:  qrcode, barcode
Sgqrcode
The easy to use bar code and QR code scan library for iOS【支持二维码生成、从相册中读取二维码、条形码和二维码扫描】
Stars: ✭ 1,571 (+3640.48%)
Mutual labels:  qrcode, barcode

api2pdf.php

PHP code for Api2Pdf REST API

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

Run the following from command line:

$ composer require api2pdf/api2pdf.php

Usage without Composer

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:

require_once 'your-own-directory/Api2Pdf.php';

Resources

Resources this API supports:

Authorization

Acquire API Key

Create an account at portal.api2pdf.com to get your API key.

Usage

Initialize the Client

All usage starts by calling the import command and initializing the client by passing your API key as a parameter to the constructor.

use Api2Pdf\Api2Pdf;

$apiClient = new Api2Pdf('YOUR-API-KEY');

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

$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>');
echo $result->getFile();

Result Format

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.

Additional attributes include the total data usage out, and the cost for the API call, typically very small fractions of a penny.

$file = $result->getFile();
$cost = $result->getCost();
$mbOut = $result->getMbOut();
$seconds = $result->getSeconds();
$responseId = $result->getResponseId();

wkhtmltopdf

Convert HTML to PDF

$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>');

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

$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>', $inline = false, $fileName = "test.pdf");

Convert HTML to PDF (use arguments for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

$options = [
    "orientation" => "landscape",
    "pageSize" => "A4"
];
$result = $apiClient->wkHtmlToPdf('<p>Hello, World</p>', $inline = false, $filename = "test.pdf", $options = $options);

Convert URL to PDF

$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com');

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

$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com', $inline = false, $fileName = "test.pdf");

Convert URL to PDF (use arguments for advanced wkhtmltopdf settings) View full list of wkhtmltopdf options available.

$options = [
    "orientation" => "landscape",
    "pageSize" => "A4"
];
$result = $apiClient->wkUrlToPdf('http://www.api2pdf.com', $inline = false, $filename = "test.pdf", $options = $options);

Headless Chrome

Convert HTML to PDF

$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>');

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

$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>', $inline = false, $filename = "test.pdf");

Convert HTML to PDF (use arguments for advanced Headless Chrome settings) View full list of Headless Chrome options available.

$options = [
    "landscape" => true
];
$result = $apiClient->chromeHtmlToPdf('<p>Hello, World</p>', $inline = false, $filename = "test.pdf", $options = $options);

Convert URL to PDF

$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com');

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

$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com', $inline = false, $filename = "test.pdf");

Convert URL to PDF (use arguments for advanced Headless Chrome settings) View full list of Headless Chrome options available.

$options = [
    "landscape" => true
];
$result = $apiClient->chromeUrlToPdf('http://www.api2pdf.com', $inline = false, $filename = "test.pdf", $options = $options);

Convert HTML to Image

$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>');

Convert HTML to Image (load image in browser window and specify a file name)

$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>', $inline = false, $filename = "test.jpg");

Convert HTML to Image (use arguments for advanced Headless Chrome settings) View full list of Headless Chrome options available.

$options = [
    "fullPage" => true
];
$result = $apiClient->chromeHtmlToImage('<p>Hello, World</p>', $inline = false, $filename = "test.jpg", $options = $options);

Convert URL to Image

$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com');

Convert URL to Image (load image in browser window and specify a file name)

$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com', $inline = false, $filename = "test.jpg");

Convert URL to Image (use arguments for advanced Headless Chrome settings) View full list of Headless Chrome options available.

$options = [
    "fullPage" => true
];
$result = $apiClient->chromeUrlToImage('http://www.api2pdf.com', $inline = false, $filename = "test.jpg", $options = $options);

LibreOffice

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

$result = $apiClient->libreOfficeAnyToPdf('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');

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

$result = $apiClient->libreOfficeThumbnail('https://www.api2pdf.com/wp-content/themes/api2pdf/assets/samples/sample-word-doc.docx');

Convert HTML to Microsoft Word or Docx

$result = $apiClient->libreOfficeHtmlToDocx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html');

Convert HTML to Microsoft Excel or Xlsx

$result = $apiClient->libreOfficeHtmlToXlsx('http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html');

Convert PDF to HTML

$result = $apiClient->libreOfficePdfToHtml('http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf');

PdfSharp - Merge / Concatenate Two or More PDFs, Add bookmarks to pdfs, add passwords to pdfs

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 list of URLs to existing PDFs

$linksToPdfs = ['https://LINK-TO-PDF', 'https://LINK-TO-PDF'];
$mergeResult = $apiClient->pdfsharpMerge($linksToPdfs);

Add bookmarks to existing PDF

$linkToPdf = 'https://LINK-TO-PDF';
$bookmarks = [
    [ "Page" => 0, "Title" => "Introduction" ],
    [ "Page" => 1, "Title" => "Second page" ] 
];
$bookmarkResult = $apiClient->pdfsharpAddBookmarks($linkToPdf, $bookmarks);

Add password to existing PDF

$linkToPdf = 'https://LINK-TO-PDF';
$userpassword = 'hello';
$bookmarkResult = $apiClient->pdfsharpAddPassword($linkToPdf, $userpassword);

Helper Methods

delete($responseId)

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.

$result = $apiClient->chromeHtmlToPdf("<p>Hello World</p>");
$responseId = $result->getResponseId();
//delete pdf
$apiClient->utilityDelete($responseId);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].