Learn how to convert web pages and HTML documents to PDF in Ruby using the Pdfcrowd API v2. The API is easy to use and the integration takes only a couple of lines of code.
gem install pdfcrowd
Learn more about other install options.
Authentication is needed in order to use the Pdfcrowd API. The credentials
used for accessing the API are your Pdfcrowd username and the API key.
Sign up for a Free Trial
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'example.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and store the result into the "pdf" variable pdf = client.convertUrl("http://www.example.com") # at this point the "pdf" variable contains PDF raw data and # can be sent in an HTTP response, saved to a file, etc. rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # create output stream for conversion result output_stream = open("example.pdf", "wb") # run the conversion and write the result into the output stream client.convertUrlToStream("http://www.example.com", output_stream) # close the output stream output_stream.close() rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and write the result to a file client.convertFileToFile("/path/to/MyLayout.html", 'MyLayout.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and store the result into the "pdf" variable pdf = client.convertFile("/path/to/MyLayout.html") # at this point the "pdf" variable contains PDF raw data and # can be sent in an HTTP response, saved to a file, etc. rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # create output stream for conversion result output_stream = open("MyLayout.pdf", "wb") # run the conversion and write the result into the output stream client.convertFileToStream("/path/to/MyLayout.html", output_stream) # close the output stream output_stream.close() rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and write the result to a file client.convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", 'HelloWorld.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # run the conversion and store the result into the "pdf" variable pdf = client.convertString("<html><body><h1>Hello World!</h1></body></html>") # at this point the "pdf" variable contains PDF raw data and # can be sent in an HTTP response, saved to a file, etc. rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # create output stream for conversion result output_stream = open("HelloWorld.pdf", "wb") # run the conversion and write the result into the output stream client.convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", output_stream) # close the output stream output_stream.close() rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setDebugLog(true) # run the conversion and write the result to a file client.convertFileToFile("/path/to/MyLayout.html", 'MyLayout.pdf') # print URL to the debug log puts "Debug log url: #{client.getDebugLogUrl()}" # print the number of available conversion credits in your account puts "Remaining credit count: #{client.getRemainingCreditCount()}" # print the number of credits consumed by the conversion puts "Consumed credit count: #{client.getConsumedCreditCount()}" # print the unique ID of the conversion puts "Job id: #{client.getJobId()}" # print the total number of pages in the output document puts "Page count: #{client.getPageCount()}" # print the size of the output in bytes puts "Output size: #{client.getOutputSize()}" rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setPageSize("Letter") client.setOrientation("landscape") client.setNoMargins(true) # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'letter_landscape.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setHeaderHeight("15mm") client.setFooterHeight("10mm") client.setHeaderHtml("<a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a>") client.setFooterHtml("<center><span class='pdfcrowd-page-number'></span></center>") client.setMarginTop("0") client.setMarginBottom("0") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'header_footer.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setScaleFactor(300) # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'zoom_300.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setAuthor("Pdfcrowd") client.setTitle("Hello") client.setSubject("Demo") client.setKeywords("Pdfcrowd,demo") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'with_metadata.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setPageLayout("single-page") client.setPageMode("full-screen") client.setInitialZoomType("fit-page") client.setOrientation("landscape") client.setNoMargins(true) # run the conversion and write the result to a file client.convertUrlToFile("https://pdfcrowd.com/doc/api/", 'slide_show.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setElementToConvert("#main") # run the conversion and write the result to a file client.convertUrlToFile("https://pdfcrowd.com/doc/api/", 'html_part.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setCustomJavascript("el=document.createElement('h2'); el.textContent='Hello from Pdfcrowd API'; el.style.color='red'; el_before=document.getElementsByTagName('h1')[0]; el_before.parentNode.insertBefore(el, el_before.nextSibling)") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'html_inject.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setViewportWidth(992) client.setRenderingMode("viewport") client.setSmartScalingMode("viewport-fit") client.setNoMargins(true) # run the conversion and write the result to a file client.convertUrlToFile("https://getbootstrap.com/", 'bootstrap.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setCustomJavascript("libPdfcrowd.highlightHtmlElements({backgroundColor: 'rgba(255, 191, 0, 0.1)', borderColor:null})") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'highlight_background.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("demo", "ce544b6ea52a5621fb9d55f8b542d14d") # configure the conversion client.setCustomJavascript("libPdfcrowd.highlightHtmlElements({borderColor: 'orange', backgroundColor: null, padding: '4px', margin: '4px'})") # run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", 'highlight_borders.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
The API can be easily integrated into your environment. You can have our interactive API Playground autogenerate the integration code for you:
You can also check out a complete example in our pdfcrowd-examples Github repository:
The API lets you convert a web page, a local HTML file, or a string containing HTML. The result of the conversion can be stored to a local file, to a stream object or to a variable. See the conversion input section for more details.
The best way to start with the API is to choose one of the examples and once you get it working, you can further customize the code. You can find the most common customizations in the table below.
Page size | Change the page size with setPageSize or setPageDimensions. Pass -1 to setPageHeight to get a single page PDF containing the whole document. |
Page orientation | Change the page orientation to landscape with setOrientation. |
Page margins | Adjust the page margins with setPageMargins. |
Headers and footers | Add headers and footers with setHeaderHtml and setFooterHtml. Set the height with setFooterHeight and setHeaderHeight. |
Zoom | Scale the HTML contents with setScaleFactor. |
Hide or remove elements |
You can use the following classes in your HTML code to hide or remove elements from the output:
|
Use @media print | You can switch to the print version of the page (if it exists) with setUsePrintMedia. |
Force page break |
You can force a page break with<div style="page-break-before:always"></div>
|
Avoid page break |
You can avoid a page break inside an element with the following CSSth, td, img { page-break-inside:avoid }
|
Run custom JavaScript | You can use setOnLoadJavascript or setCustomJavascript to alter the HTML contents with a custom JavaScript. In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library. |
The API enables rendering of HTML templates. The template syntax is based on the Jinja template rendering engine.
The most common constructs are:
Invoice: {{ invoice.number }}
{% for invoice in invoices %} ... {% endfor %}
{% if invoice.total > 100 %} ... {% endif %}
{{ invoice.to.first_name|capitalize }}
The supported input data formats are JSON, XML, CSV and YAML. The data can be uploaded from a file or from a string variable.
Supported template filters: capitalize, center, default, escape, first, forceescape, format, indent, join, last, length, list, lower, replace, reverse, safe, slice, sort, string, striptags, title, trim, truncate, unique, upper, wordcount, wordwrap.
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("{{ user_name }}", "{{ api_key }}") # configure the conversion client.setDataString('{ "name": "World", "product": "Pdfcrowd API" }') # run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", 'output.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("{{ user_name }}", "{{ api_key }}") # configure the conversion client.setDataString('<?xml version="1.0" encoding="UTF-8"?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>') # run the conversion and write the result to a file client.convertStringToFile("Hello {{ data.name }} from {{ data.product }}", 'output.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("{{ user_name }}", "{{ api_key }}") # configure the conversion client.setDataString("name: World product: Pdfcrowd API") # run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", 'output.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
require 'pdfcrowd' begin # create the API client instance client = Pdfcrowd::HtmlToPdfClient.new("{{ user_name }}", "{{ api_key }}") # configure the conversion client.setDataString("name,product World,Pdfcrowd API") # run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", 'output.pdf') rescue Pdfcrowd::Error => why # report the error STDERR.puts "Pdfcrowd Error: #{why}" # rethrow or handle the exception raise end
begin # call the API rescue Pdfcrowd::Error => why # print error STDERR.puts "Pdfcrowd Error: #{why}" # print just error code STDERR.puts "Pdfcrowd Error Code: #{why.getCode()}" # print just error message STDERR.puts "Pdfcrowd Error Message: #{why.getMessage()}" # or handle the error in your way end
libPdfcrowd.highlightHtmlElements
method call to visualize all HTML elements. See the example and helper JavaScript library documentation.
Conversion from HTML to PDF. All setter methods return HtmlToPdfClient object unless otherwise specified.
def initialize(user_name, api_key)
user_name
Your username at Pdfcrowd.
|
api_key
Your API key.
|
def convertUrl(url)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
def convertUrlToStream(url, out_stream)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
out_stream
The output stream that will contain the conversion output.
|
def convertUrlToFile(url, file_path)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
file_path
The output file path.
The string must not be empty.
|
def convertFile(file)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
def convertFileToStream(file, out_stream)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
out_stream
The output stream that will contain the conversion output.
|
def convertFileToFile(file, file_path)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
file_path
The output file path.
The string must not be empty.
|
def convertString(text)
text
The string content to convert.
The string must not be empty.
|
def convertStringToStream(text, out_stream)
text
The string content to convert.
The string must not be empty.
|
out_stream
The output stream that will contain the conversion output.
|
def convertStringToFile(text, file_path)
text
The string content to convert.
The string must not be empty.
|
file_path
The output file path.
The string must not be empty.
|
def setPageSize(size)
size
Allowed values:
Default: A4
|
def setPageWidth(width)
width
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
setPageWidth("300mm")
setPageWidth("9.5in")
def setPageHeight(height)
height
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageHeight("350mm")
setPageHeight("15.25in")
setPageHeight("-1")
def setPageDimensions(width, height)
width
Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
height
Set the output page height. Use -1 for a single page PDF. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageDimensions("300mm", "350mm")
setPageDimensions("9.5in", "15.25in")
setPageDimensions("372mm", "520pt")
def setOrientation(orientation)
orientation
Allowed values:
Default: portrait
|
def setMarginTop(top)
top
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginTop("1in")
setMarginTop("2.5cm")
def setMarginRight(right)
right
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginRight("1in")
setMarginRight("2.5cm")
def setMarginBottom(bottom)
bottom
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginBottom("1in")
setMarginBottom("2.5cm")
def setMarginLeft(left)
left
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginLeft("1in")
setMarginLeft("2.5cm")
def setNoMargins(value)
value
Set to true to disable margins.
Default: false
|
def setPageMargins(top, right, bottom, left)
top
Set the output page top margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
right
Set the output page right margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
bottom
Set the output page bottom margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
left
Set the output page left margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
def setHeaderUrl(url)
url
The supported protocols are http:// and https://.
|
setHeaderUrl("http://myserver.com/header.html")
def setHeaderHtml(html)
html
The string must not be empty.
|
setHeaderHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
def setHeaderHeight(height)
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setHeaderHeight("30mm")
setHeaderHeight("1in")
url
The supported protocols are http:// and https://.
|
setFooterUrl("http://myserver.com/header.html")
html
The string must not be empty.
|
setFooterHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setFooterHeight("30mm")
setFooterHeight("1in")
value
Set to true to disable horizontal margins for header and footer.
Default: false
|
def setPrintPageRange(pages)
pages
A comma separated list of page numbers or ranges.
|
setPrintPageRange("2")
setPrintPageRange("1,3")
setPrintPageRange("2-")
setPrintPageRange("-3")
setPrintPageRange("3,6-9")
def setExcludeHeaderOnPages(pages)
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeHeaderOnPages("2")
setExcludeHeaderOnPages("1,-1")
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeFooterOnPages("2")
setExcludeFooterOnPages("1,-1")
def setPageNumberingOffset(offset)
offset
Integer specifying page offset.
Default: 0
|
setPageNumberingOffset(1)
setPageNumberingOffset(-10)
def setContentAreaX(x)
x
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaX("-1in")
setContentAreaX("2.5cm")
def setContentAreaY(y)
y
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaY("-1in")
setContentAreaY("2.5cm")
def setContentAreaWidth(width)
width
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
setContentAreaWidth("8in")
setContentAreaWidth("25cm")
def setContentAreaHeight(height)
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
setContentAreaHeight("8in")
setContentAreaHeight("25cm")
def setContentArea(x, y, width, height)
x
Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
y
Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
width
Set the width of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
height
Set the height of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
def setCssPageRuleMode(mode)
mode
The page rule mode.
Allowed values:
Default: default
|
Methods related to HTML template rendering.
def setDataString(data_string)
data_string
The input data string.
|
def setDataFile(data_file)
data_file
The file path to a local file containing the input data.
|
def setDataFormat(data_format)
data_format
The data format.
Allowed values:
Default: auto
|
def setDataEncoding(encoding)
encoding
The data file encoding.
Default: utf-8
|
def setDataIgnoreUndefined(value)
value
Set to true to ignore undefined variables.
Default: false
|
def setDataAutoEscape(value)
value
Set to true to turn auto escaping on.
Default: false
|
def setDataTrimBlocks(value)
value
Set to true to turn auto trimming on.
Default: false
|
def setDataOptions(options)
options
Comma separated list of options.
|
setDataOptions("csv_delimiter=;")
setDataOptions("data_root=rows")
setDataOptions("xml_remove_root=1")
def setPageWatermark(watermark)
watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
def setPageWatermarkUrl(url)
url
The supported protocols are http:// and https://.
|
setPageWatermarkUrl("http://myserver.com/watermark.pdf")
def setMultipageWatermark(watermark)
watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
def setMultipageWatermarkUrl(url)
url
The supported protocols are http:// and https://.
|
setMultipageWatermarkUrl("http://myserver.com/watermark.pdf")
def setPageBackground(background)
background
The file path to a local background PDF file.
The file must exist and not be empty.
|
def setPageBackgroundUrl(url)
url
The supported protocols are http:// and https://.
|
setPageBackgroundUrl("http://myserver.com/background.pdf")
def setMultipageBackground(background)
background
The file path to a local background PDF file.
The file must exist and not be empty.
|
def setMultipageBackgroundUrl(url)
url
The supported protocols are http:// and https://.
|
setMultipageBackgroundUrl("http://myserver.com/background.pdf")
def setPageBackgroundColor(color)
color
The value must be in RRGGBB or RRGGBBAA hexadecimal format.
|
setPageBackgroundColor("FF0000")
setPageBackgroundColor("00ff00")
setPageBackgroundColor("00ff0080")
def setUsePrintMedia(value)
value
Set to true to use the print version of the page.
Default: false
|
def setNoBackground(value)
value
Set to true to disable the background graphics.
Default: false
|
def setDisableJavascript(value)
value
Set to true to disable JavaScript in web pages.
Default: false
|
def setDisableImageLoading(value)
value
Set to true to disable loading of images.
Default: false
|
def setDisableRemoteFonts(value)
value
Set to true disable loading remote fonts.
Default: false
|
def setLoadIframes(iframes)
iframes
Allowed values:
Default: all
|
def setBlockAds(value)
value
Set to true to block ads in web pages.
Default: false
|
def setDefaultEncoding(encoding)
encoding
The text encoding of the HTML content.
Default: auto detect
|
def setLocale(locale)
locale
The locale code according to ISO 639.
Default: en-US
|
def setHttpAuth(user_name, password)
user_name
Set the HTTP authentication user name.
|
password
Set the HTTP authentication password.
|
def setCookies(cookies)
cookies
The cookie string.
|
setCookies("session=6d7184b3bf35;token=2710")
def setVerifySslCertificates(value)
value
Set to true to enable SSL certificate verification.
Default: false
|
def setFailOnMainUrlError(fail_on_error)
fail_on_error
Set to true to abort the conversion.
Default: false
|
def setFailOnAnyUrlError(fail_on_error)
fail_on_error
Set to true to abort the conversion.
Default: false
|
def setNoXpdfcrowdHeader(value)
value
Set to true to disable sending X-Pdfcrowd HTTP header.
Default: false
|
def setCustomJavascript(javascript)
javascript
A string containing a JavaScript code.
The string must not be empty.
|
def setOnLoadJavascript(javascript)
javascript
A string containing a JavaScript code.
The string must not be empty.
|
def setCustomHttpHeader(header)
header
A string containing the header name and value separated by a colon.
|
setCustomHttpHeader("X-My-Client-ID:k2017-12345")
def setJavascriptDelay(delay)
delay
The number of milliseconds to wait.
Must be a positive integer number or 0.
Default: 200
|
def setElementToConvert(selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setElementToConvert("#main-content")
setElementToConvert(".main-content")
setElementToConvert("table")
setElementToConvert("table, #main-content")
setElementToConvert("div.user-panel.main p.article")
def setElementToConvertMode(mode)
mode
Allowed values:
Default: cut-out
|
def setWaitForElement(selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setWaitForElement("#main-content")
setWaitForElement(".main-content")
setWaitForElement("table")
setWaitForElement("table, #main-content")
setWaitForElement("div.user-panel.main p.article")
def setViewportWidth(width)
width
The value must be in the range 96-65000.
Default: 1024
|
def setViewportHeight(height)
height
Must be a positive integer number.
Default: 768
|
def setViewport(width, height)
width
Set the viewport width in pixels. The viewport is the user's visible area of the page.
The value must be in the range 96-65000.
Default: 1024
|
height
Set the viewport height in pixels. The viewport is the user's visible area of the page.
Must be a positive integer number.
Default: 768
|
def setRenderingMode(mode)
mode
The rendering mode.
Allowed values:
Default: default
|
def setSmartScalingMode(mode)
mode
The smart scaling mode.
Allowed values:
Default: default
|
def setScaleFactor(factor)
factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
def setDisableSmartShrinking(value)
value
Set to true to disable the intelligent shrinking strategy.
Default: false
|
def setJpegQuality(quality)
quality
The percentage value.
The value must be in the range 1-100.
Default: 100
|
def setConvertImagesToJpeg(images)
images
The image category.
Allowed values:
Default: none
|
def setImageDpi(dpi)
dpi
The DPI value.
Must be a positive integer number or 0.
Default: 0
|
setImageDpi(0)
setImageDpi(72)
setImageDpi(96)
setImageDpi(150)
setImageDpi(300)
Miscellaneous values for PDF output.
def setLinearize(value)
value
Set to true to create linearized PDF.
Default: false
|
def setEncrypt(value)
value
Set to true to enable PDF encryption.
Default: false
|
def setUserPassword(password)
password
The user password.
|
def setOwnerPassword(password)
password
The owner password.
|
def setNoPrint(value)
value
Set to true to set the no-print flag in the output PDF.
Default: false
|
def setNoModify(value)
value
Set to true to set the read-only only flag in the output PDF.
Default: false
|
def setNoCopy(value)
value
Set to true to set the no-copy flag in the output PDF.
Default: false
|
def setTitle(title)
title
The title.
|
def setSubject(subject)
subject
The subject.
|
def setAuthor(author)
author
The author.
|
def setKeywords(keywords)
keywords
The string with the keywords.
|
These preferences specify how a PDF viewer should present the document. The preferences may be ignored by some PDF viewers.
def setPageLayout(layout)
layout
Allowed values:
|
def setPageMode(mode)
mode
Allowed values:
|
def setInitialZoomType(zoom_type)
zoom_type
Allowed values:
|
def setInitialPage(page)
page
Must be a positive integer number.
|
def setInitialZoom(zoom)
zoom
Must be a positive integer number.
|
def setHideToolbar(value)
value
Set to true to hide tool bars.
Default: false
|
value
Set to true to hide the menu bar.
Default: false
|
def setHideWindowUi(value)
value
Set to true to hide ui elements.
Default: false
|
def setFitWindow(value)
value
Set to true to resize the window.
Default: false
|
def setCenterWindow(value)
value
Set to true to center the window.
Default: false
|
def setDisplayTitle(value)
value
Set to true to display the title.
Default: false
|
def setRightToLeft(value)
value
Set to true to set right-to-left reading order.
Default: false
|
def setDebugLog(value)
value
Set to true to enable the debug logging.
Default: false
|
def getDebugLogUrl()
def getRemainingCreditCount()
def getConsumedCreditCount()
def getJobId()
def getPageCount()
def getOutputSize()
def getVersion()
def setTag(tag)
tag
A string with the custom tag.
|
def setHttpProxy(proxy)
proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpProxy("myproxy.com:8080")
setHttpProxy("113.25.84.10:33333")
def setHttpsProxy(proxy)
proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpsProxy("myproxy.com:443")
setHttpsProxy("113.25.84.10:44333")
def setClientCertificate(certificate)
certificate
The file must be in PKCS12 format.
The file must exist and not be empty.
|
def setClientCertificatePassword(password)
password
|
Expert options for fine-tuning PDF output.
def setLayoutDpi(dpi)
dpi
The DPI value.
The value must be in the range of 72-600.
Default: 300
|
def setContentsMatrix(matrix)
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setContentsMatrix("1,0,0,0,1.001,0")
setContentsMatrix("1,0,-10,0,1,-10")
def setHeaderMatrix(matrix)
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setHeaderMatrix("1,0,0,0,1.001,0")
setHeaderMatrix("1,0,-10,0,1,-10")
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setFooterMatrix("1,0,0,0,1.001,0")
setFooterMatrix("1,0,-10,0,1,-10")
def setDisablePageHeightOptimization(value)
value
Set to true to disable automatic height scale.
Default: false
|
def setMainDocumentCssAnnotation(value)
value
Set to true to add the special CSS classes.
Default: false
|
Warning
If your custom styling affects the contents area size (e.g. by using different margins, padding, border width), the resulting PDF may contain duplicit contents or some contents may be missing.
CSS styling by page number in API Playground
value
Set to true to add the special CSS classes.
Default: false
|
Different headers in API Playground
def setConverterVersion(version)
version
The version identifier.
Allowed values:
Default: 20.10
|
def setUseHttp(value)
value
Set to true to use HTTP.
Default: false
|
Warning
Using HTTP is insecure as data sent over HTTP is not encrypted. Enable this option only if you know what you are doing.
def setUserAgent(agent)
agent
The user agent string.
Default: pdfcrowd_ruby_client/5.0.0 (http://pdfcrowd.com)
|
def setProxy(host, port, user_name, password)
host
The proxy hostname.
|
port
The proxy port.
|
user_name
The username.
|
password
The password.
|
def setRetryCount(count)
count
Number of retries wanted.
Default: 1
|