-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlToPdf.php
More file actions
33 lines (30 loc) · 1.4 KB
/
Copy pathHtmlToPdf.php
File metadata and controls
33 lines (30 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
// ========================================================================
// Author: DynamicPDF.COM CETE www.dynamicpdf.com
// Copyright: (c) 2021 DynamicPDF Cloud API
// License: MIT - for additional information see ./LICENSE in this project.
// Errors: Please report any errors in software to support@dynamicpdf.com
// ========================================================================
use DynamicPDF\Api\HtmlResource;
use DynamicPDF\Api\Pdf;
include_once("constants.php");
require __DIR__ . '/vendor/autoload.php';
class HtmlToPdf {
public static function Run(string $apikey, string $path, string $output_path){
$pdf = new Pdf();
$pdf->ApiKey =$apikey;
$pdf->AddHtml("<html>An example HTML fragment.</html>");
$pdf->AddHtml("<html><p>HTML with basepath.</p><img src='./images/logo.png'></img></html>", "https://www.dynamicpdf.com");
$file = Utility::GetFileData($path . "products.html");
$htmlResource = new HtmlResource($file);
$pdf->AddHtml($htmlResource);
$pdfResponse = $pdf->Process();
if($pdfResponse->IsSuccessful)
{
file_put_contents($output_path . "html-pdf-output-php.pdf", $pdfResponse->Content);
} else {
echo($pdfResponse->ErrorMessage);
}
}
}
HtmlToPdf::Run(CLIENT_EXAMPLES_API_KEY, CLIENT_EXAMPLES_BASE_PATH . "users-guide/", CLIENT_EXAMPLES_OUTPUT_PATH);