NAME
SelectPdf::HtmlToPdfClient - Html To Pdf Conversion with SelectPdf Online API.
SYNOPSIS
Convert URL to PDF and save result into a file on disk.
use SelectPdf;
print "This is SelectPdf-$SelectPdf::VERSION\n";
my $url = "https://selectpdf.com/";
my $local_file = "Test.pdf";
my $apiKey = "Your API key here";
eval {
my $client = SelectPdf::HtmlToPdfClient->new($apiKey);
$client
->setPageSize("A4")
->setMargins(0)
->setShowPageNumbers('False')
->setPageBreaksEnhancedAlgorithm('True')
;
$client->convertUrlToFile($url, $local_file);
};
if ($@) {
print "An error occurred: $@\n";
}
Convert raw HTML string to PDF and save result into a file on disk.
use SelectPdf;
print "This is SelectPdf-$SelectPdf::VERSION\n";
my $html = "This is a <b>test HTML</b>.";
my $local_file = "Test.pdf";
my $apiKey = "Your API key here";
eval {
my $client = SelectPdf::HtmlToPdfClient->new($apiKey);
$client
->setPageSize("A4")
->setMargins(0)
->setShowPageNumbers('False')
->setPageBreaksEnhancedAlgorithm('True')
;
$client->convertHtmlStringToFile($html, $local_file);
};
if ($@) {
print "An error occurred: $@\n";
}
Keyless demo mode (no API key; output is watermarked and capped at 5 pages).
use SelectPdf;
eval {
my $client = SelectPdf::HtmlToPdfClient->new(); # undef, "" or "demo" selects the demo endpoint
$client->convertUrlToFile("https://selectpdf.com/", "Test.pdf");
print "Demo response: " . $client->isDemoResponse() . ", mode: " . $client->getMode() . "\n";
print "Dropped fields: " . join(", ", $client->getDroppedFields()) . "\n" if $client->wasAnyFieldDropped();
};
if (my $err = $@) {
if (ref $err && $err->isa("SelectPdf::DemoRateLimitException")) {
print "Demo rate limit reached. Retry after " . $err->retryAfter() . "s.\n";
}
else {
print "An error occurred: $err\n";
}
}
For more details and full list of parameters see Html To Pdf API.
METHODS
new( $apiKey )
Construct the Html To Pdf Client.
my $client = SelectPdf::HtmlToPdfClient->new($apiKey);
Pass a paid API key for production use. Pass undef, an empty string, or "demo" (case-insensitive) to use the keyless demo endpoint - output is watermarked and capped at 5 pages, but no signup is required.
my $demoClient = SelectPdf::HtmlToPdfClient->new(); # keyless demo mode
Parameters:
- $apiKey API Key. Undef, empty or "demo" selects the keyless demo endpoint.
isDemoMode
True if the client was constructed for the keyless demo endpoint (the API key was undef, empty, or "demo"). Set at construction time and stable for the lifetime of the client. Calling setApiEndpoint does not change it.
if ($client->isDemoMode()) { ... }
Returns:
- 1 for demo mode, 0 otherwise.
isDemoResponse
True if the most recent response was tagged X-SelectPdf-Mode: demo (the request actually landed on a demo endpoint).
if ($client->isDemoResponse()) { ... }
Returns:
- 1 if the most recent response came from the demo endpoint, 0 otherwise.
getClampedFields
Names of the parameters the demo endpoint clamped on the most recent conversion (e.g. "max_load_time", "engine"). "Clamped" means the value was modified (capped, force-set), not discarded. Empty if nothing was clamped or for non-demo responses.
my @clamped = $client->getClampedFields();
Returns:
- List of parameter names (an array reference in scalar context).
wasClamped
True if the most recent response had any clamped fields.
Returns:
- 1 or 0.
getDroppedFields
Names of the parameters the demo endpoint silently dropped on the most recent conversion (e.g. "auth_username", "cookies"). The demo endpoint refuses to honor a small set of fields for safety reasons - auth credentials, cookies, raw_parameters, pdf_name, async - and reports any caller-supplied value via the X-SelectPdf-Demo-Dropped response header. Empty if nothing was dropped or for non-demo responses. Clamped = value modified, dropped = value thrown away.
my @dropped = $client->getDroppedFields();
Returns:
- List of parameter names (an array reference in scalar context).
wasAnyFieldDropped
True if the most recent response reported any dropped fields.
Returns:
- 1 or 0.
convertUrl( $url )
Convert the specified url to PDF. SelectPdf online API can convert http:// and https:// publicly available urls.
$content = $client->convertUrl($url);
Parameters:
- $url Address of the web page being converted.
Returns:
- Byte array containing the resulted PDF.
convertUrlToFile( $url, $filePath )
Convert the specified url to PDF and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls.
$client->convertUrlToFile($url, $filePath);
Parameters:
- $url Address of the web page being converted.
- $filePath Local file including path if necessary.
convertUrlAsync( $url )
Convert the specified url to PDF using an asynchronous call. SelectPdf online API can convert http:// and https:// publicly available urls. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$content = $client->convertUrlAsync($url);
Parameters:
- $url Address of the web page being converted.
Returns:
- Byte array containing the resulted PDF.
convertUrlToFileAsync( $url, $filePath )
Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$client->convertUrlToFileAsync($url, $filePath);
Parameters:
- $url Address of the web page being converted.
- $filePath Local file including path if necessary.
convertHtmlStringWithBaseUrl( $htmlString, $baseUrl )
Convert the specified HTML string to PDF. Use a base url to resolve relative paths to resources.
$content = $client->convertHtmlStringWithBaseUrl($htmlString, $baseUrl);
Parameters:
- $htmlString HTML string with the content being converted.
- $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
Returns:
- Byte array containing the resulted PDF.
convertHtmlStringWithBaseUrlToFile( $htmlString, $baseUrl, $filePath )
Convert the specified HTML string to PDF and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.
$client->convertHtmlStringWithBaseUrlToFile($htmlString, $baseUrl, $filePath);
Parameters:
- $htmlString HTML string with the content being converted.
- $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
- $filePath: Local file including path if necessary.
convertHtmlStringWithBaseUrlAsync( $htmlString, $baseUrl )
Convert the specified HTML string to PDF with an asynchronous call. Use a base url to resolve relative paths to resources. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$content = $client->convertHtmlStringWithBaseUrlAsync($htmlString, $baseUrl);
Parameters:
- $htmlString HTML string with the content being converted.
- $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
Returns:
- Byte array containing the resulted PDF.
convertHtmlStringWithBaseUrlToFileAsync( $htmlString, $baseUrl, $filePath )
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$client->convertHtmlStringWithBaseUrlToFileAsync($htmlString, $baseUrl, $filePath);
Parameters:
- $htmlString HTML string with the content being converted.
- $baseUrl Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.
- $filePath: Local file including path if necessary.
convertHtmlString( $htmlString )
Convert the specified HTML string to PDF.
$content = $client->convertHtmlString($htmlString);
Parameters:
- $htmlString HTML string with the content being converted.
Returns:
- Byte array containing the resulted PDF.
convertHtmlStringToFile( $htmlString, $filePath )
Convert the specified HTML string to PDF and writes the resulted PDF to a local file.
$client->convertHtmlStringToFile($htmlString, $filePath);
Parameters:
- $htmlString HTML string with the content being converted.
- $filePath: Local file including path if necessary.
convertHtmlStringAsync( $htmlString )
Convert the specified HTML string to PDF with an asynchronous call. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$content = $client->convertHtmlStringAsync($htmlString);
Parameters:
- $htmlString HTML string with the content being converted.
Returns:
- Byte array containing the resulted PDF.
convertHtmlStringToFileAsync( $htmlString, $filePath )
Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Not available in demo mode (dies with a SelectPdf::DemoUnsupportedException).
$client->convertHtmlStringToFileAsync($htmlString, $filePath);
Parameters:
- $htmlString HTML string with the content being converted.
- $filePath: Local file including path if necessary.
setPageSize( $pageSize )
Set PDF page size. Default value is A4. If page size is set to Custom, use setPageWidth and setPageHeight methods to set the custom width/height of the PDF pages.
Parameters:
- $pageSize: PDF page size. Possible values: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal.
Returns:
- Reference to the current object.
setPageWidth( $pageWidth )
Set PDF page width in points. Default value is 595pt (A4 page width in points). 1pt = 1/72 inch. This is taken into account only if page size is set to Custom using setPageSize method.
Parameters:
- $pageWidth: Page width in points.
Returns:
- Reference to the current object.
setPageHeight( $pageHeight )
Set PDF page height in points. Default value is 842pt (A4 page height in points). 1pt = 1/72 inch. This is taken into account only if page size is set to Custom using setPageSize method.
Parameters:
- $pageHeight: Page height in points.
Returns:
- Reference to the current object.
setPageOrientation( $pageOrientation )
Set PDF page orientation. Default value is Portrait.
Parameters:
- $pageOrientation: PDF page orientation. Possible values: Portrait, Landscape.
Returns:
- Reference to the current object.
setMarginTop( $marginTop )
Set top margin of the PDF pages. Default value is 5pt.
Parameters:
- $marginTop: Margin value in points. 1pt = 1/72 inch.
Returns:
- Reference to the current object.
setMarginRight( $marginRight )
Set right margin of the PDF pages. Default value is 5pt.
Parameters:
- $marginRight: Margin value in points. 1pt = 1/72 inch.
Returns:
- Reference to the current object.
setMarginBottom( $marginBottom )
Set bottom margin of the PDF pages. Default value is 5pt.
Parameters:
- $marginBottom: Margin value in points. 1pt = 1/72 inch.
Returns:
- Reference to the current object.
setMarginLeft( $marginLeft )
Set left margin of the PDF pages. Default value is 5pt.
Parameters:
- $marginLeft: Margin value in points. 1pt = 1/72 inch.
Returns:
- Reference to the current object.
setMargins( $margin )
Set all margins of the PDF pages to the same value. Default value is 5pt.
Parameters:
- $margin: Margin value in points. 1pt = 1/72 inch.
Returns:
- Reference to the current object.
setPdfName( $pdfName )
Specify the name of the pdf document that will be created. The default value is Document.pdf.
Parameters:
- $pdfName: Name of the generated PDF document.
Returns:
- Reference to the current object.
setRenderingEngine( $renderingEngine )
Set the rendering engine used for the HTML to PDF conversion. Default value is WebKit.
Parameters:
- $renderingEngine: HTML rendering engine. Possible values: WebKit, Restricted, Blink, Chromium (see SelectPdf::RenderingEngine constants).
Returns:
- Reference to the current object.
setTagged( $tagged )
Produce a tagged, accessible PDF: a logical structure tree covering headings, paragraphs, lists, tables, figures with alternate text, links and reading order. Default is False.
Requires the Blink or Chromium rendering engine - the WebKit engines cannot produce a structure tree. If no engine is set, the API promotes the request to Chromium and reports it in the X-SelectPdf-Engine response header. Setting an explicit WebKit engine together with tagged output is rejected by the API.
A tagged document also needs a title, so set setDocTitle - the converter falls back to the HTML document title when it is not set.
Parameters:
- $tagged: Produce a tagged, accessible PDF.
Returns:
- Reference to the current object.
setPdfStandard( $pdfStandard )
Set the PDF conformance target - PDF/A for archiving, PDF/X for graphics exchange, PDF/SiqQ for digital signatures. Default is Full.
PdfA3A is the accessible level of PDF/A-3: it implies a tagged document, so it carries the same rendering-engine requirement as setTagged.
Parameters:
- $pdfStandard: PDF conformance target. Possible values: Full, PdfA, PdfA2B, PdfA3A, PdfA3B, PdfA3U, PdfX, PdfSiqQ_A, PdfSiqQ_B (see SelectPdf::PdfStandard constants).
Returns:
- Reference to the current object.
setDocumentLanguage( $documentLanguage )
Set the natural language of the document, for example "en-US" or "de-DE". Written as the PDF /Lang entry and onto tagged structure elements. Default is "en-US".
Parameters:
- $documentLanguage: Language tag, for example "en-US".
Returns:
- Reference to the current object.
setUserPassword( $userPassword )
Set PDF user password.
Not available in demo mode: if the client was constructed for the keyless demo endpoint, this method dies with a SelectPdf::DemoUnsupportedException.
Parameters:
- $userPassword: PDF user password.
Returns:
- Reference to the current object.
setOwnerPassword( $ownerPassword )
Set PDF owner password.
Not available in demo mode: if the client was constructed for the keyless demo endpoint, this method dies with a SelectPdf::DemoUnsupportedException.
Parameters:
- $ownerPassword: PDF owner password.
Returns:
- Reference to the current object.
setWebPageWidth( $webPageWidth )
Set the width used by the converter's internal browser window in pixels. The default value is 1024px.
Parameters:
- $webPageWidth: Browser window width in pixels.
Returns:
- Reference to the current object.
setWebPageHeight( $webPageHeight )
Set the height used by the converter's internal browser window in pixels. The default value is 0px and it means that the page height is automatically calculated by the converter.
Parameters:
- $webPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
Returns:
- Reference to the current object.
setWebPageFixedSize( $webPageFixedSize )
Leave out the content below the web page height (set with setWebPageHeight) instead of letting the page flow onto further pages.
When not set, each rendering engine keeps its own behavior: WebKit and WebKit Restricted leave the content out whenever a web page height is set, Blink and Chromium convert the whole page. Set it to True or False to choose explicitly. It needs a non-zero web page height; with 0 there is no height to fix the page at and the setting is ignored. With WebKit, a fixed size also cuts off content wider than the web page width.
Parameters:
- $webPageFixedSize: True to cut the page at the web page height, False to convert the whole page.
Returns:
- Reference to the current object.
setMinLoadTime( $minLoadTime )
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setConversionDelay. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.
Parameters:
- $minLoadTime: Delay in seconds.
Returns:
- Reference to the current object.
setConversionDelay( $delay )
Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for setMinLoadTime. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.
Parameters:
- $delay: Delay in seconds.
Returns:
- Reference to the current object.
setMaxLoadTime( $maxLoadTime )
Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setNavigationTimeout. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.
Parameters:
- $maxLoadTime: Timeout in seconds.
Returns:
- Reference to the current object.
setNavigationTimeout( $timeout )
Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for setMaxLoadTime. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.
Parameters:
- $timeout: Timeout in seconds.
Returns:
- Reference to the current object.
setSecureProtocol( $secureProtocol )
Set the protocol used for secure (HTTPS) connections. Set this only if you have an older server that only works with older SSL connections.
Parameters:
- $secureProtocol: Secure protocol. Possible values: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only).
Returns:
- Reference to the current object.
setUseCssPrint( $useCssPrint )
Specify if the CSS Print media type is used instead of the Screen media type. The default value is False.
Parameters:
- $useCssPrint: Use CSS Print media or not.
Returns:
- Reference to the current object.
setBackgroundColor( $backgroundColor )
Specify the background color of the PDF page in RGB html format. The default is #FFFFFF.
Parameters:
- $backgroundColor: Background color in #RRGGBB format.
Returns:
- Reference to the current object.
setDrawHtmlBackground( $drawHtmlBackground )
Set a flag indicating if the web page background is rendered in PDF. The default value is True.
Parameters:
- $drawHtmlBackground: Draw the HTML background or not.
Returns:
- Reference to the current object.
setDisableJavascript( $disableJavascript )
Do not run JavaScript in web pages. The default value is False and javascript is executed.
Parameters:
- $disableJavascript: Disable javascript or not.
Returns:
- Reference to the current object.
setDisableInternalLinks( $disableInternalLinks )
Do not create internal links in the PDF. The default value is False and internal links are created.
Parameters:
- $disableInternalLinks: Disable internal links or not.
Returns:
- Reference to the current object.
setDisableExternalLinks( $disableExternalLinks )
Do not create external links in the PDF. The default value is False and external links are created.
Parameters:
- $disableExternalLinks: Disable external links or not.
Returns:
- Reference to the current object.
setRenderOnTimeout( $renderOnTimeout )
Try to render the PDF even in case of the web page loading timeout. The default value is False and an exception is raised in case of web page navigation timeout.
Parameters:
- $renderOnTimeout: Render in case of timeout or not.
Returns:
- Reference to the current object.
setKeepImagesTogether( $keepImagesTogether )
Avoid breaking images between PDF pages. The default value is False and images are split between pages if larger.
Parameters:
- $keepImagesTogether: Try to keep images on same page or not.
Returns:
- Reference to the current object.
setDocTitle( $docTitle )
Set the PDF document title.
Parameters:
- $docTitle: Document title.
Returns:
- Reference to the current object.
setDocSubject( $docSubject )
Set the PDF document subject.
Parameters:
- $docSubject: Document subject.
Returns:
- Reference to the current object.
setDocKeywords( $docKeywords )
Set the PDF document keywords.
Parameters:
- $docKeywords: Document keywords.
Returns:
- Reference to the current object.
setDocAuthor( $docAuthor )
Set the PDF document author.
Parameters:
- $docAuthor: Document author.
Returns:
- Reference to the current object.
setDocAddCreationDate( $docAddCreationDate )
Add the date and time when the PDF document was created to the PDF document information. The default value is False.
Parameters:
- $docAddCreationDate: Add creation date to the document metadata or not.
Returns:
- Reference to the current object.
setViewerPageLayout( $pageLayout )
Set the page layout to be used when the document is opened in a PDF viewer. The default value is 1 - OneColumn.
Parameters:
- $pageLayout: Page layout. Possible values: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).
Returns:
- Reference to the current object.
setViewerPageMode( $pageMode )
Set the document page mode when the pdf document is opened in a PDF viewer. The default value is 0 - UseNone.
Parameters:
- $pageMode: Page mode. Possible values: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).
Returns:
- Reference to the current object.
setViewerCenterWindow( $viewerCenterWindow )
Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.
Parameters:
- $viewerCenterWindow: Center window or not.
Returns:
- Reference to the current object.
setViewerDisplayDocTitle( $viewerDisplayDocTitle )
Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.
Parameters:
- $viewerDisplayDocTitle: Display title or not.
Returns:
- Reference to the current object.
setViewerFitWindow( $viewerFitWindow )
Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.
Parameters:
- $viewerFitWindow: Fit window or not.
Returns:
- Reference to the current object.
setViewerHideMenuBar( $viewerHideMenuBar )
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.
Parameters:
- $viewerHideMenuBar: Hide menu bar or not.
Returns:
- Reference to the current object.
setViewerHideToolbar( $viewerHideToolbar )
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.
Parameters:
- $viewerHideToolbar: Hide tool bars or not.
Returns:
- Reference to the current object.
setViewerHideWindowUI( $viewerHideWindowUI )
Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.
Parameters:
- $viewerHideWindowUI: Hide window UI or not.
Returns:
- Reference to the current object.
setShowHeader( $showHeader )
Control if a custom header is displayed in the generated PDF document. The default value is False.
Parameters:
- $showHeader: Show header or not.
Returns:
- Reference to the current object.
setHeaderHeight( $height )
The height of the pdf document header. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
Parameters:
- $height: Header height.
Returns:
- Reference to the current object.
setHeaderUrl( $url )
Set the url of the web page that is converted and rendered in the PDF document header.
Parameters:
- $url: The url of the web page that is converted and rendered in the pdf document header.
Returns:
- Reference to the current object.
setHeaderHtml( $html )
Set the raw html that is converted and rendered in the pdf document header.
Parameters:
- $html: The raw html that is converted and rendered in the pdf document header.
Returns:
- Reference to the current object.
setHeaderBaseUrl( $baseUrl )
Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.
Parameters:
- $baseUrl: Header base url.
Returns:
- Reference to the current object.
setHeaderDisplayOnFirstPage( $displayOnFirstPage )
Control the visibility of the header on the first page of the generated pdf document. The default value is True.
Parameters:
- $displayOnFirstPage: Display header on the first page or not.
Returns:
- Reference to the current object.
setHeaderDisplayOnOddPages( $displayOnOddPages )
Control the visibility of the header on the odd numbered pages of the generated pdf document. The default value is True.
Parameters:
- $displayOnOddPages: Display header on odd pages or not.
Returns:
- Reference to the current object.
setHeaderDisplayOnEvenPages( $displayOnEvenPages )
Control the visibility of the header on the even numbered pages of the generated pdf document. The default value is True.
Parameters:
- $displayOnEvenPages: Display header on even pages or not.
Returns:
- Reference to the current object.
setHeaderWebPageWidth( $headerWebPageWidth )
Set the width in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 1024px.
Parameters:
- $headerWebPageWidth: Browser window width in pixels.
Returns:
- Reference to the current object.
setHeaderWebPageHeight( $headerWebPageHeight )
Set the height in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 0px and it means that the page height is automatically calculated by the converter.
Parameters:
- $headerWebPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
Returns:
- Reference to the current object.
setShowFooter( $showFooter )
Control if a custom footer is displayed in the generated PDF document. The default value is False.
Parameters:
- $showFooter: Show footer or not.
Returns:
- Reference to the current object.
setFooterHeight( $height )
The height of the pdf document footer. This height is specified in points. 1 point is 1/72 inch. The default value is 50.
Parameters:
- $height: Footer height.
Returns:
- Reference to the current object.
setFooterUrl( $url )
Set the url of the web page that is converted and rendered in the PDF document footer.
Parameters:
- $url: The url of the web page that is converted and rendered in the pdf document footer.
Returns:
- Reference to the current object.
setFooterHtml( $html )
Set the raw html that is converted and rendered in the pdf document footer.
Parameters:
- $html: The raw html that is converted and rendered in the pdf document footer.
Returns:
- Reference to the current object.
setFooterBaseUrl( $baseUrl )
Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.
Parameters:
- $baseUrl: Footer base url.
Returns:
- Reference to the current object.
setFooterDisplayOnFirstPage( $displayOnFirstPage )
Control the visibility of the footer on the first page of the generated pdf document. The default value is True.
Parameters:
- $displayOnFirstPage: Display footer on the first page or not.
Returns:
- Reference to the current object.
setFooterDisplayOnOddPages( $displayOnOddPages )
Control the visibility of the footer on the odd numbered pages of the generated pdf document. The default value is True.
Parameters:
- $displayOnOddPages: Display footer on odd pages or not.
Returns:
- Reference to the current object.
setFooterDisplayOnEvenPages( $displayOnEvenPages )
Control the visibility of the footer on the even numbered pages of the generated pdf document. The default value is True.
Parameters:
- $displayOnEvenPages: Display footer on even pages or not.
Returns:
- Reference to the current object.
setFooterDisplayOnLastPage( $displayOnLastPage )
Add a special footer on the last page of the generated pdf document only. The default value is False. Use setFooterUrl or setFooterHtml and setFooterBaseUrl to specify the content of the last page footer. Use setFooterHeight to specify the height of the special last page footer.
Parameters:
- $displayOnLastPage: Display special footer on the last page or not.
Returns:
- Reference to the current object.
setFooterWebPageWidth( $footerWebPageWidth )
Set the width in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 1024px.
Parameters:
- $footerWebPageWidth: Browser window width in pixels.
Returns:
- Reference to the current object.
setFooterWebPageHeight( $footerWebPageHeight )
Set the height in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 0px and it means that the page height is automatically calculated by the converter.
Parameters:
- $footerWebPageHeight: Browser window height in pixels. Set it to 0px to automatically calculate page height.
Returns:
- Reference to the current object.
setShowPageNumbers( $showPageNumbers )
Show page numbers. Default value is True. Page numbers will be displayed in the footer of the PDF document.
Parameters:
- $showPageNumbers: Show page numbers or not.
Returns:
- Reference to the current object.
setPageNumbersFirst( $firstPageNumber )
Control the page number for the first page being rendered. The default value is 1.
Parameters:
- $firstPageNumber: First page number.
Returns:
- Reference to the current object.
setPageNumbersOffset( $totalPagesOffset )
Control the total number of pages offset in the generated pdf document. The default value is 0.
Parameters:
- $totalPagesOffset: Offset for the total number of pages in the generated pdf document.
Returns:
- Reference to the current object.
setPageNumbersTemplate( $template )
Set the text that is used to display the page numbers. It can contain the placeholder {page_number} for the current page number and {total_pages} for the total number of pages. The default value is "Page: {page_number} of {total_pages}".
Parameters:
- $template: Page numbers template.
Returns:
- Reference to the current object.
setPageNumbersFontName( $fontName )
Set the font used to display the page numbers text. The default value is "Helvetica".
Parameters:
- $fontName: The font used to display the page numbers text.
Returns:
- Reference to the current object.
setPageNumbersFontSize( $fontSize )
Set the size of the font used to display the page numbers. The default value is 10 points.
Parameters:
- $fontSize: The size in points of the font used to display the page numbers.
Returns:
- Reference to the current object.
setPageNumbersAlignment( $alignment )
Set the alignment of the page numbers text. The default value is "2" - Right.
Parameters:
- $alignment: The alignment of the page numbers text. Possible values: 1 (Left), 2 (Center), 3 (Right).
Returns:
- Reference to the current object.
setPageNumbersColor( $color )
Specify the color of the page numbers text in #RRGGBB html format. The default value is #333333.
Parameters:
- $color: Page numbers color.
Returns:
- Reference to the current object.
setPageNumbersVerticalPosition( $position )
Specify the position in points on the vertical where the page numbers text is displayed in the footer. The default value is 10 points.
Parameters:
- $position: Page numbers Y position in points.
Returns:
- Reference to the current object.
setPdfBookmarksSelectors( $selectors )
Generate automatic bookmarks in pdf. The elements that will be bookmarked are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors <a href="http://www.w3schools.com/cssref/css_selectors.asp" target="_blank">here</a>.
Parameters:
- $selectors: CSS selectors used to identify HTML elements, comma separated.
Returns:
- Reference to the current object.
setPdfHideElements( $selectors )
Exclude page elements from the conversion. The elements that will be excluded are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors <a href="http://www.w3schools.com/cssref/css_selectors.asp" target="_blank">here</a>.
Parameters:
- $selectors: CSS selectors used to identify HTML elements, comma separated.
Returns:
- Reference to the current object.
setPdfShowOnlyElementID( $elementID )
Convert only a specific section of the web page to pdf. The section that will be converted to pdf is specified by the html element ID. The element can be anything (image, table, table row, div, text, etc).
Parameters:
- $elementID: HTML element ID.
Returns:
- Reference to the current object.
setPdfWebElementsSelectors( $selectors )
Get the locations of page elements from the conversion. The elements that will have their locations retrieved are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors <a href="http://www.w3schools.com/cssref/css_selectors.asp" target="_blank">here</a>.
Parameters:
- $selectors: CSS selectors used to identify HTML elements, comma separated.
Returns:
- Reference to the current object.
setStartupMode( $startupMode )
Set converter startup mode. The default value is Automatic and the conversion is started immediately. By default this is set to Automatic and the conversion is started as soon as the page loads (and conversion delay set with setConversionDelay elapses). If set to Manual, the conversion is started only by a javascript call to SelectPdf.startConversion() from within the web page.
Parameters:
- $startupMode: Converter startup mode. Possible values: Automatic, Manual.
Returns:
- Reference to the current object.
setSkipDecoding( $skipDecoding )
Internal use only.
Parameters:
- $skipDecoding: The default value is True.
Returns:
- Reference to the current object.
setScaleImages( $scaleImages )
Set a flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.
Parameters:
- $scaleImages: Scale images or not.
Returns:
- Reference to the current object.
setSinglePagePdf( $generateSinglePagePdf )
Generate a single page PDF. The converter will automatically resize the PDF page to fit all the content in a single page. The default value of this property is False and the PDF will contain several pages if the content is large.
Parameters:
- $generateSinglePagePdf: Generate a single page PDF or not.
Returns:
- Reference to the current object.
setPageBreaksEnhancedAlgorithm( $enableEnhancedPageBreaksAlgorithm )
Get or set a flag indicating if an enhanced custom page breaks algorithm is used. The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used. The default value for this property is False.
Parameters:
- $enableEnhancedPageBreaksAlgorithm: Enable enhanced page breaks algorithm or not.
Returns:
- Reference to the current object.
setCookies( $cookies )
Set HTTP cookies for the web page being converted.
Parameters:
- $cookies: Dictionary with HTTP cookies that will be sent to the page being converted.
Returns:
- Reference to the current object.
setAuthUsername( $authUsername )
Set the user name for HTTP Basic authentication on the web page being converted.
Use it together with setAuthPassword. The demo endpoint does not send credentials; it reports the value in getDroppedFields.
Parameters:
- $authUsername: User name for HTTP Basic authentication.
Returns:
- Reference to the current object.
setAuthPassword( $authPassword )
Set the password for HTTP Basic authentication on the web page being converted.
Use it together with setAuthUsername. The demo endpoint does not send credentials; it reports the value in getDroppedFields.
Parameters:
- $authPassword: Password for HTTP Basic authentication.
Returns:
- Reference to the current object.
setCustomParameter( $parameterName, $parameterValue )
Set a custom parameter. Do not use this method unless advised by SelectPdf.
Parameters:
- $parameterName: Parameter name.
- $parameterValue: Parameter value.
Returns:
- Reference to the current object.
getWebElements
Get the locations of certain web elements. This is retrieved if pdf_web_elements_selectors parameter is set and elements were found to match the selectors.
Returns:
- Json with web elements locations.