PHP code example of api2pdf / api2pdf.php

1. Go to this page and download the library: Download api2pdf/api2pdf.php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

api2pdf / api2pdf.php example snippets


use Api2Pdf\Api2Pdf;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$result = $apiClient->chromeHtmlToPdf("<p>Hello World</p>");
$responseId = $result->getResponseId();
//delete pdf
$apiClient->utilityDelete($responseId);

$ composer