PHP code example of grim-reapper / pdf-services-php
1. Go to this page and download the library: Download grim-reapper/pdf-services-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/ */
grim-reapper / pdf-services-php example snippets
use GrimReapper\PdfServices\Client;
use GrimReapper\PdfServices\Config\PdfServicesConfig;
$config = new PdfServicesConfig(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
organizationId: 'your-organization-id',
region: 'us' // 'us' (default) or 'eu'
);
$client = new Client($config);
$service = $client->createPdf();
// From HTML string
$pdf = $service->fromHtml('<h1>Hello World</h1>', [
'format' => 'A4',
'
$service = $client->convert();
// DOCX to PDF
$pdf = $service->docxToPdf('document.docx');
// PDF to DOCX
$docx = $service->pdfToDocx('input.pdf');
// Image to PDF
$pdf = $service->imageToPdf('photo.jpg');
$service = $client->forms();
// Fill form
$service->fillForm('template.pdf', ['first_name' => 'John'])->saveTo('filled.pdf');
// Export data (JSON)
$data = $service->exportFormData($doc, 'json');
// Extract text and tables
$zip = $client->extract()->extract('document.pdf', ['text', 'tables']);
$zip->saveTo('extracted_data.zip');
// Extract text only
$zip = $client->extract()->extract('document.pdf', ['text']);
// Extract with table images and figures
$zip = $client->extract()->extract('document.pdf', ['text'], [
'renditionsToExtract' => ['tables', 'figures']
]);
// Extract tables as CSV
$zip = $client->extract()->extract('document.pdf', ['tables'], [
'tableOutputFormat' => 'csv'
]);
$service = $client->markdown();
// Basic conversion (returns ZIP with markdown.json)
$service->toMarkdown('document.pdf')->saveTo('markdown_output.zip');
// Include base64-encoded figures
$service->toMarkdown('document.pdf', ['getFigures' => true])->saveTo('markdown_with_images.zip');
$service = $client->images();
// Convert to JPEG (default, returns ZIP)
$service->toJpeg('document.pdf')->saveTo('images-jpeg.zip');
// Convert to PNG
$service->toPng('document.pdf')->saveTo('images-png.zip');
// Convert to TIFF
$service->toTiff('document.pdf')->saveTo('images-tiff.zip');
// Or use the general method with custom options
$service->toImages('document.pdf', 'jpeg', 'zipOfPageImages')->saveTo('output.zip');