├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── apiserver-test.php ├── composer.json ├── makefile ├── pdfcrowd.php └── test.php /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*~ 3 | \#*\# 4 | .\#* 5 | 6 | dist/ 7 | test_files -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | 6.5.0 5 | ----- 6 | 7 | - NEW: The error handling system has been updated. This includes revised status codes and messages, as well as the addition of new methods to the error class: getStatusCode, getReasonCode, and getDocumentationLink. The getCode method is deprecated and should be replaced with getStatusCode. 8 | 9 | 6.4.0 10 | ----- 11 | 12 | - NEW: setConverterUserAgent method for HtmlToPdf and HtmlToImage API client 13 | 14 | 6.3.0 15 | ----- 16 | 17 | - NEW: setHtmlNamespace method for PdfToHtml API client 18 | - NEW: setConverterVersion method for PdfToHtml API client 19 | - fix a crash in PdfToHtml API client when PDF file contains a specific type3 font 20 | 21 | 6.2.1 22 | ----- 23 | 24 | - fix setContentViewportWidth and setContentViewportHeight accepts a numeric value followed by the "px" unit to specify pixels 25 | 26 | 6.2.0 27 | ----- 28 | 29 | - NEW: setType3Mode and setCustomCss methods for PdfToHtml API client 30 | - NEW: the conversion config JSON supports `odd`, `even`, and `last` for page definition 31 | - NEW: setPrintPageRange supports `odd`, `even`, and `last` for page selection 32 | 33 | 6.1.0 34 | ----- 35 | 36 | - NEW: setConversionConfig and setConversionConfigFile methods for configuring HtmlToPdf API client 37 | 38 | 6.0.1 39 | ----- 40 | 41 | - minor reorder of methods 42 | 43 | 6.0.0 44 | ----- 45 | 46 | - NEW: the converter version 24.04 is used by default for the HtmlToPdf and HtmlToImage API client 47 | - NEW: setContentViewportWidth method for the HtmlToPdf API client 48 | - NEW: setContentViewportHeight method for the HtmlToPdf API client 49 | - NEW: setContentFitMode method for the HtmlToPdf API client 50 | - NEW: option `all` for the HtmlToPdf API client `setRemoveBlankPages` method 51 | 52 | 5.20.0 53 | ------ 54 | 55 | - NEW: PdftoImage API client for the converion from PDF to image 56 | 57 | 5.19.0 58 | ------ 59 | 60 | - NEW: `setConverterVersion` can now be switched to the beta version of converter 24.04 61 | 62 | 5.18.0 63 | ------ 64 | 65 | - NEW: setSplitLigatures method for the PdfToHtml API client 66 | 67 | 5.17.0 68 | ------ 69 | 70 | - NEW: setImageFormat method for the PdfToHtml API client 71 | - NEW: mode value 'none' for setImageMode method for the PdfToHtml API client 72 | 73 | 5.16.0 74 | ------ 75 | 76 | - NEW: setDpi method for the PdfToHtml API client 77 | 78 | 5.15.0 79 | ------ 80 | 81 | - NEW: setMaxLoadingTime method for the HtmlToPdf and HtmlToImage API clients 82 | 83 | 5.14.0 84 | ------ 85 | 86 | - NEW: setCustomCss method for the HtmlToPdf and HtmlToImage API clients 87 | 88 | 5.13.1 89 | ------ 90 | 91 | - FIX: resolve deprecation warnings for PHP 8.2.7 92 | 93 | 5.13.0 94 | ------ 95 | 96 | - NEW: setRemoveBlankPages method for the HtmlToPdf API client 97 | 98 | 5.12.1 99 | ------ 100 | 101 | - FIX: replace deprecated string interpolation 102 | 103 | 5.12.1 104 | ------ 105 | 106 | - FIX: retry conversion on error 503 107 | 108 | 5.12.0 109 | ------ 110 | 111 | - NEW: setCropAreaX, setCropAreaY, setCropAreaWidth, setCropAreaHeight and setRemoveBorders methods for ImageToImage and ImageToPdf API client 112 | 113 | 5.11.0 114 | ------ 115 | 116 | - NEW: canvas setup options for ImageToImage API client 117 | - NEW: page setup, watermark/background and output options for ImageToPdf API client 118 | - FIX: rotation for ImageToPdf API client 119 | 120 | 5.10.0 121 | ------ 122 | 123 | - NEW: PdftoText API client for the converion from PDF to plain text 124 | - NEW: ImageToPdf API client supports watermarks, backgrounds and PDF format options 125 | - NEW: single-page-fit-ex mode for setSmartScalingMode API method 126 | 127 | 5.9.0 128 | ----- 129 | 130 | - NEW: getTotalPageCount to get the total page count of the source document 131 | - NEW: readability-v4 mode for setReadabilityEnhancements API method 132 | 133 | 5.8.0 134 | ----- 135 | 136 | - images can be used as a watermark and a background in HTML to PDF and PDF to PDF converter 137 | 138 | 5.7.0 139 | ----- 140 | 141 | - NEW: readability-v2 and readability-v3 modes for setReadabilityEnhancements API method 142 | 143 | 5.6.2 144 | ----- 145 | 146 | - minor update of documentation links 147 | 148 | 5.6.1 149 | ----- 150 | 151 | - minor update of the text of the error message 152 | 153 | 5.6.0 154 | ----- 155 | 156 | - NEW: setEnablePdfForms to convert HTML forms to fillable PDF forms 157 | - minor update of the text of the error message 158 | 159 | 5.5.0 160 | ----- 161 | 162 | - NEW: setAutodetectElementToConvert to detect the main HTML element for conversion 163 | - NEW: setReadabilityEnhancements to enhance the input HTML to improve the readability 164 | - NEW: pdfcrowd-source-title CSS class available for header and footer HTML 165 | 166 | 5.4.0 167 | ----- 168 | 169 | - NEW: PDF to HTML converter 170 | - NEW: setInputPdfPassword for PDF to PDF converter 171 | 172 | 5.3.0 173 | ----- 174 | 175 | - NEW: setUseMobileUserAgent for HTML to PDF and HTML to Image 176 | 177 | 5.2.2 178 | ----- 179 | 180 | - FIX: the hyperlinks to the Pdfcrowd API documentation have been updated 181 | 182 | 5.2.1 183 | ----- 184 | 185 | - FIX: methods for getting conversion info (e.g. getRemainingCreditCount) 186 | 187 | 5.2.0 188 | ----- 189 | 190 | - NEW: setZipMainFilename 191 | - NEW: setZipHeaderFilename 192 | - NEW: setZipFooterFilename 193 | - NEW: setExtractMetaTags 194 | - NEW: setTitle for PDF to PDF 195 | - NEW: setSubject for PDF to PDF 196 | - NEW: setAuthor for PDF to PDF 197 | - NEW: setKeywords for PDF to PDF 198 | 199 | 5.1.1 200 | ----- 201 | 202 | - minor documentation updates 203 | 204 | 5.1.0 205 | ----- 206 | 207 | - NEW: convertStream 208 | - NEW: convertStreamToStream 209 | - NEW: convertStreamToFile 210 | - FIX: The main window scrollbar is not rendered in HTML to Image outputs. 211 | 212 | 5.0.0 213 | ----- 214 | 215 | - NEW: converter version 20.10 supported 216 | - NEW: setConverterVersion 217 | - NEW: setLoadIframes 218 | - NEW: setLocale 219 | - NEW: setNoHeaderFooterHorizontalMargins 220 | - NEW: setCssPageRuleMode 221 | - NEW: setLayoutDpi 222 | - NEW: setContentsMatrix 223 | - NEW: setHeaderMatrix 224 | - NEW: setFooterMatrix 225 | - NEW: setDisablePageHeightOptimization 226 | - NEW: setHeaderFooterCssAnnotation 227 | - NEW: setMainDocumentCssAnnotation 228 | - NEW: setBackgroundColor for the HtmlToImage API client 229 | 230 | Older versions 231 | -------------- 232 | 233 | - Details on the [Pdfcrowd blog](https://pdfcrowd.com/blog/). 234 | 235 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 pdfcrowd.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pdfcrowd API - PHP client library 2 | 3 | The Pdfcrowd API lets you easily convert between HTML, PDF and various image 4 | formats in your PHP applications. 5 | 6 | To use the API, you need an account on 7 | [http://pdfcrowd.com](https://pdfcrowd.com). If you don't have one, you 8 | can sign up [here](https://pdfcrowd.com/pricing/api/). 9 | 10 | ## Installation 11 | 12 | To install via Packagist: 13 | 14 | $ composer require pdfcrowd/pdfcrowd 15 | 16 | ## Learn more 17 | 18 | * API Home: 19 | * API Reference: 20 | * Interactive API Playground: 21 | * PHP: 22 | * PHP web site: 23 | * Laravel: 24 | * Symfony: 25 | 26 | ## License 27 | 28 | This client library is licensed under the MIT License. 29 | -------------------------------------------------------------------------------- /apiserver-test.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | convertURI('https://storage.googleapis.com/pdfcrowd-legacy-tests/tests/webtopdfcom.html'); 16 | $c->convertHtml('raw html'); 17 | $c->convertFile('../test_files/in/simple.html'); 18 | 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pdfcrowd/pdfcrowd", 3 | "type": "library", 4 | "version": "6.5.0", 5 | "description": "A client library for the Pdfcrowd API. It lets you convert between HTML, PDF and various image formats", 6 | "keywords": ["html", "pdf", "web service", "api", "client", "convert", "web page"], 7 | "homepage": "https://pdfcrowd.com/api/", 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "Pdfcrowd Team", 12 | "email": "support@pdfcrowd.com", 13 | "homepage": "https://pdfcrowd.com/api/" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.3.10", 18 | "ext-curl": "*" 19 | }, 20 | "autoload": { 21 | "classmap": ["pdfcrowd.php"] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | VERSION = 6.5.0 2 | PHP ?= php 3 | DIR_NAME := pdfcrowd-6.5.0 4 | 5 | dist: dist/pdfcrowd-$(VERSION)-php.zip 6 | 7 | dist/pdfcrowd-$(VERSION)-php.zip: 8 | @mkdir -p dist 9 | @cd dist && mkdir -p $(DIR_NAME) && cp ../pdfcrowd.php $(DIR_NAME) && zip pdfcrowd-$(VERSION)-php.zip $(DIR_NAME)/* 10 | 11 | publish: 12 | curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=Pdfcrowd&apiToken=$(API_TOKEN)" -d'{"repository":{"url":"https://github.com/pdfcrowd/pdfcrowd-php"}}' 13 | 14 | .PHONY: clean 15 | clean: 16 | rm -rf dist/* ./test_files/out/php_*.pdf 17 | -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | 3) { 15 | Pdfcrowd::$api_host = $argv[3]; 16 | } 17 | 18 | if ($argv == 6) { 19 | Pdfcrowd::$http_port = $argv[4]; 20 | Pdfcrowd::$https_port = $argv[5]; 21 | } 22 | 23 | $api_host = Pdfcrowd::$api_host; 24 | $http_port = Pdfcrowd::$http_port; 25 | $https_port = Pdfcrowd::$https_port; 26 | echo "using {$api_host} ports {$http_port} {$https_port}\n"; 27 | 28 | 29 | chdir(dirname($argv[0])); 30 | $test_dir = './test_files'; 31 | 32 | function out_stream($name, $use_ssl) 33 | { 34 | $fname = "./test_files/out/php_client_{$name}"; 35 | if ($use_ssl) 36 | $fname .= "_ssl"; 37 | return fopen($fname . '.pdf', 'wb'); 38 | } 39 | 40 | $html = "Uploaded content!"; 41 | $client = new Pdfcrowd($argv[1], $argv[2]); 42 | foreach(array(False, True) as $i => $use_ssl) { 43 | $client->useSSL($use_ssl); 44 | try 45 | { 46 | $ntokens = $client->numTokens(); 47 | $client->convertURI('https://storage.googleapis.com/pdfcrowd-legacy-tests/tests/webtopdfcom.html', out_stream('uri', $use_ssl)); 48 | $client->convertHtml($html, out_stream('content', $use_ssl)); 49 | $client->convertFile($test_dir . '/in/simple.html', out_stream('upload', $use_ssl)); 50 | $client->convertFile($test_dir . '/in/archive.tar.gz', out_stream('archive', $use_ssl)); 51 | $after_tokens = $client->numTokens(); 52 | echo "remaining tokens: {$after_tokens}\n"; 53 | if ($ntokens - 4 != $after_tokens) { 54 | throw new Exception("Mismatch in the number of tokens."); 55 | } 56 | } 57 | catch(PdfcrowdException $e) 58 | { 59 | echo "EXCEPTION: " . $e->getMessage(); 60 | exit(1); 61 | } 62 | } 63 | 64 | 65 | $tests = array( 66 | 'setPageWidth' => 500, 67 | 'setPageHeight' => -1, 68 | 'setHorizontalMargin' => 0, 69 | 'setVerticalMargin' => 72, 70 | 'setEncrypted' => True, 71 | 'setUserPassword' => 'userpwd', 72 | 'setOwnerPassword' => 'ownerpwd', 73 | 'setNoPrint' => True, 74 | 'setNoModify' => True, 75 | 'setNoCopy' => True, 76 | 'setPageLayout' => Pdfcrowd::CONTINUOUS, 77 | 'setPageMode' => Pdfcrowd::FULLSCREEN, 78 | 'setFooterText' => '%p/%n | source %u', 79 | 'enableImages' => False, 80 | 'enableBackgrounds' => False, 81 | 'setHtmlZoom' => 300, 82 | 'enableJavaScript' => False, 83 | 'enableHyperlinks' => False, 84 | 'setDefaultTextEncoding' => 'iso-8859-1', 85 | 'usePrintMedia' => True, 86 | 'setMaxPages' => 1, 87 | 'enablePdfcrowdLogo' => True, 88 | 'setInitialPdfZoomType' => Pdfcrowd::FIT_PAGE, 89 | 'setInitialPdfExactZoom' => 113, 90 | 'setPdfScalingFactor' => 0.5, 91 | 'setFooterHtml' => 'bold and italic ', 92 | 'setFooterUrl' => 'http://s3.pdfcrowd.com/test-resources/footer.html', 93 | 'setHeaderHtml' => 'page %p out of %n', 94 | 'setHeaderUrl' => 'http://s3.pdfcrowd.com/test-resources/header.html', 95 | 'setAuthor' => 'Custom Author', 96 | 'setPageBackgroundColor' => 'ee82EE', 97 | 'setTransparentBackground' => True, 98 | 'setUserAgent' => "test user agent" 99 | ); 100 | 101 | try 102 | { 103 | foreach($tests as $method => $arg) 104 | { 105 | $client = new Pdfcrowd($argv[1], $argv[2]); 106 | $client->$method($arg); 107 | $client->setVerticalMargin('1in'); 108 | $client->convertFile($test_dir . '/in/simple.html', out_stream(strtolower($method), False)); 109 | } 110 | } 111 | catch(PdfcrowdException $e) 112 | { 113 | echo "EXCEPTION: " . $e->getMessage(); 114 | exit(1); 115 | } 116 | 117 | // margins 118 | $client = new Pdfcrowd($argv[1], $argv[2]); 119 | $client->setPageMargins('0.25in', '0.5in', '0.75in', '1.0in'); 120 | $client->convertHtml('
4 margins
', out_stream('4margins', False)); 121 | 122 | 123 | // expected failures 124 | $failures = array( 125 | array("convertHtml", "", "must not be empty"), 126 | array("convertFile", "does-not-exist.html", "not found"), 127 | array("convertFile", "/", "not a directory"), 128 | array("convertFile", $test_dir."/in/empty.html", "must not be empty"), 129 | array("convertURI", "domain.com", "must start with"), 130 | array("convertURI", "HtTp://s3.pdfcrowd.com/this/url/does/not/exist/", "Received a non-2xx response") 131 | ); 132 | $client = new Pdfcrowd($argv[1], $argv[2]); 133 | $client->setFailOnNon200(True); 134 | foreach($failures as $failure) { 135 | try { 136 | $client->$failure[0]($failure[1]); 137 | echo "FAILED expected an exception: ${failure}\n"; 138 | exit(1); 139 | } catch(PdfcrowdException $e) { 140 | if (!strstr($e->getMessage(), $failure[2])) { 141 | echo "error message [". $e->getMessage() ."] is expected to contain [".$failure[2]."]\n"; 142 | exit(1); 143 | } 144 | } 145 | } 146 | 147 | 148 | 149 | ?> --------------------------------------------------------------------------------