|
1 |
| -# selectpdf-api-perl-client |
2 |
| -Perl client for SelectPdf Online REST API |
| 1 | +# SelectPdf Online REST API - Perl Client |
| 2 | + |
| 3 | +## HTML To PDF API - Perl Client |
| 4 | + |
| 5 | +SelectPdf HTML To PDF Online REST API is a professional solution that lets you create PDF from web pages and raw HTML code in your applications. The API is easy to use and the integration takes only a few lines of code. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +* Create PDF from any web page or html string. |
| 10 | +* Full html5/css3/javascript support. |
| 11 | +* Set PDF options such as page size and orientation, margins, security, web page settings. |
| 12 | +* Set PDF viewer options and PDF document information. |
| 13 | +* Create custom headers and footers for the pdf document. |
| 14 | +* Hide web page elements during the conversion. |
| 15 | +* Automatically generate bookmarks during the html to pdf conversion. |
| 16 | +* Support for partial page conversion. |
| 17 | +* Easy integration, no third party libraries needed. |
| 18 | +* Works in all programming languages. |
| 19 | +* No installation required. |
| 20 | + |
| 21 | +Sign up for for free to get instant API access to SelectPdf [HTML to PDF API](https://selectpdf.com/html-to-pdf-api/). |
| 22 | + |
| 23 | +## Pdf Merge API |
| 24 | + |
| 25 | +SelectPdf offers a REST API that can be used to merge PDF documents from local disk or remote url. |
| 26 | + |
| 27 | +## Pdf To Text API |
| 28 | + |
| 29 | +SelectPdf offers a REST API that can be used to extract text from local or remote PDF documents and search in existing PDF documents. |
| 30 | + |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +Download [selectpdf-api-perl-client-1.4.0.zip](https://github.com/selectpdf/selectpdf-api-perl-client/releases/download/1.4.0/selectpdf-api-python-client-1.4.0.zip), unzip it and run: |
| 35 | + |
| 36 | +``` |
| 37 | +cd selectpdf-api-perl-client-1.4.0 |
| 38 | +perl Makefile.PL |
| 39 | +make |
| 40 | +make test |
| 41 | +make install |
| 42 | +``` |
| 43 | + |
| 44 | +OR |
| 45 | + |
| 46 | +Install SelectPdf Perl Client for Online API via CPAN: [SelectPdf on CPAN](https://metacpan.org/dist/SelectPdf). |
| 47 | + |
| 48 | +``` |
| 49 | +cpanm SelectPdf |
| 50 | +``` |
| 51 | + |
| 52 | +OR |
| 53 | + |
| 54 | +Clone [selectpdf-api-perl-client](https://github.com/selectpdf/selectpdf-api-perl-client) from Github and install the library. |
| 55 | + |
| 56 | +``` |
| 57 | +git clone https://github.com/selectpdf/selectpdf-api-perl-client |
| 58 | +cd selectpdf-api-perl-client |
| 59 | +perl Makefile.PL |
| 60 | +make |
| 61 | +make test |
| 62 | +make install |
| 63 | +``` |
| 64 | + |
| 65 | +## Sample Code |
| 66 | + |
| 67 | +``` |
| 68 | +local $| = 1; |
| 69 | +
|
| 70 | +use strict; |
| 71 | +use JSON; |
| 72 | +use SelectPdf; |
| 73 | +
|
| 74 | +print "This is SelectPdf-$SelectPdf::VERSION.\n"; |
| 75 | +
|
| 76 | +my $url = "https://selectpdf.com/"; |
| 77 | +my $local_file = "Test.pdf"; |
| 78 | +my $apiKey = "Your API key here"; |
| 79 | +
|
| 80 | +eval { |
| 81 | + my $client = new SelectPdf::HtmlToPdfClient($apiKey); |
| 82 | + |
| 83 | + # set parameters - see full list at https://selectpdf.com/html-to-pdf-api/ |
| 84 | + $client |
| 85 | + # main properties |
| 86 | + |
| 87 | + ->setPageSize("A4") # PDF page size |
| 88 | + ->setPageOrientation("Portrait") # PDF page orientation |
| 89 | + ->setMargins(0) # PDF page margins |
| 90 | + ->setRenderingEngine('WebKit') # rendering engine |
| 91 | + ->setConversionDelay(1) # conversion delay |
| 92 | + ->setNavigationTimeout(30) # navigation timeout |
| 93 | + ->setShowPageNumbers('False') # page numbers |
| 94 | + ->setPageBreaksEnhancedAlgorithm('True') # enhanced page break algorithm |
| 95 | +
|
| 96 | + # additional properties |
| 97 | +
|
| 98 | + #->setUseCssPrint('True') # enable CSS media print |
| 99 | + #->setDisableJavascript('True') # disable javascript |
| 100 | + #->setDisableInternalLinks('True') # disable internal links |
| 101 | + #->setDisableExternalLinks('True') # disable external links |
| 102 | + #->setKeepImagesTogether('True') # keep images together |
| 103 | + #->setScaleImages('True') # scale images to create smaller pdfs |
| 104 | + #->setSinglePagePdf('True') # generate a single page PDF |
| 105 | + #->setUserPassword('password') # secure the PDF with a password |
| 106 | +
|
| 107 | + # generate automatic bookmarks |
| 108 | + |
| 109 | + #->setPdfBookmarksSelectors("H1, H2") # create outlines (bookmarks) for the specified elements |
| 110 | + #->setViewerPageMode(1) # 1 (Use Outlines) - display outlines (bookmarks) in viewer |
| 111 | + ; |
| 112 | +
|
| 113 | + print "Starting conversion ...\n"; |
| 114 | +
|
| 115 | + # convert url to file |
| 116 | + $client->convertUrlToFile($url, $local_file); |
| 117 | +
|
| 118 | + # convert url to memory |
| 119 | + # my $pdf = $client->convertUrl($url); |
| 120 | +
|
| 121 | + # convert html string to file |
| 122 | + # $client->convertHtmlStringToFile("This is some <b>html</b>.", $local_file); |
| 123 | +
|
| 124 | + # convert html string to memory |
| 125 | + # my $pdf = $client->convertHtmlString("This is some <b>html</b>."); |
| 126 | +
|
| 127 | + print "Finished! Number of pages: " . $client->getNumberOfPages() . ".\n"; |
| 128 | +
|
| 129 | + # get API usage |
| 130 | + my $usageClient = new SelectPdf::UsageClient($apiKey); |
| 131 | + my $usage = $usageClient->getUsage(); |
| 132 | + print("Usage: " . encode_json($usage) . "\n"); |
| 133 | + print("Conversions remained this month: ". $usage->{"available"}); |
| 134 | +}; |
| 135 | +
|
| 136 | +if ($@) { |
| 137 | + print "An error occurred: $@\n"; |
| 138 | +} |
| 139 | +
|
| 140 | +``` |
0 commit comments