Constructor
function __construct($user_name, $api_key)
Constructor for the PDFCrowd API client. Initialize a new instance of the conversion client with your PDFCrowd account credentials.
You must provide both your username and API key. This establishes the authenticated connection for all subsequent conversion operations.
- Parameters:
-
-
user_name- Your username at PDFCrowd. -
api_key- Your API key.
-
PDF Manipulation
function setAction($action)
Specify the PDF manipulation operation to perform on input files.
- Parameter:
-
-
action- Allowed Values:
-
-
join— Merge multiple input PDFs into a single document in the order they were added. -
shuffle— Interleave pages from input PDFs into a single document, taking one page at a time from each PDF in rotation. -
extract— Create a new PDF containing only the specified pages from the input PDF. -
delete— Remove the specified pages from the input PDF and output the remaining pages.
-
- Default:
-
join
-
function convert() { return string; }
Execute the configured PDF manipulation operation and return the resulting PDF as a byte array. Processes all added input PDFs according to the selected action and returns the manipulated document in memory.
- Returns:
- string - Byte array containing the output PDF.
function convertToStream($out_stream)
Execute the configured PDF manipulation operation and write the resulting PDF directly to an output stream.
- Parameter:
-
-
out_stream(OutputStream) - The output stream that will contain the output PDF.
-
function convertToFile($file_path)
Execute the configured PDF manipulation operation and save the resulting PDF to a file.
- Parameter:
-
-
file_path- The output file path.
-
function addPdfFile($file_path)
Add a PDF file from the local filesystem to the input list. This method can be called multiple times to add multiple input files. Files are processed in the order they were added.
- Parameter:
-
-
file_path- The file path to a local PDF file.- Constraint:
-
- The file must exist and not be empty.
-
function addPdfRawData($data)
Add in-memory PDF data (byte array) to the input list. This method can be called multiple times to add multiple input PDFs.
Example in PHP:
$clientPdf2Pdf->addPdfRawData($clientHtml2Pdf->convertUrl('http://www.example.com'));
- Parameter:
-
-
data(byte[]) - The raw PDF data.- Constraint:
-
- The input data must be PDF content.
-
function setInputPdfPassword($password)
Password for decrypting encrypted input PDFs.
- Availability:
- API client >= 5.4.0, converter >= 20.10. See versioning.
- Parameter:
-
-
password- The input PDF password.
-
function setPageRange($pages)
Specify which pages to target. Supports individual pages, ranges, open-ended ranges, and combinations. The keyword "last" can be used to reference the final page.
- Parameter:
-
-
pages- Constraint:
-
- A comma separated list of page numbers or ranges.
-
- Examples:
-
-
Just the second page is selected:
setPageRange("2") -
The first and the third page are selected:
setPageRange("1,3") -
Everything except the first page is selected:
setPageRange("2-") -
Just the first 3 pages are selected:
setPageRange("-3") -
Pages 3, 6, 7, 8 and 9 are selected:
setPageRange("3,6-9")
-
Just the second page is selected:
Watermark & Background
function setPageWatermark($watermark)
Apply the first page of a watermark PDF to every page of the output PDF. Use this to add transparent overlays like "DRAFT" stamps, security markings, or branding elements that appear on top of content. Ideal for confidential document marking or adding protective overlays.
- Parameter:
-
-
watermark- The file path to a local file.- Constraint:
-
- The file must exist and not be empty.
-
- Examples:
-
-
Multi-page PDF for watermarking:
setPageWatermark("/home/user/john/watermark.pdf") -
Transparent PNG overlay:
setPageWatermark("/home/user/john/watermark.png")
-
Multi-page PDF for watermarking:
function setPageWatermarkUrl($url)
Load a file from the specified URL and apply the file as a watermark to each page of the output PDF. A watermark can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the watermark.
- Parameter:
-
-
url- Constraint:
-
- Supported protocols are http:// and https://.
-
- Examples:
-
-
Download watermark from server:
setPageWatermarkUrl("http://myserver.com/watermark.pdf") -
Remote logo watermark:
setPageWatermarkUrl("http://myserver.com/watermark.png")
-
Download watermark from server:
function setMultipageWatermark($watermark)
Apply each page of a watermark PDF to the corresponding page of the output PDF. Use this for page-specific watermarks where different pages need different overlays - for example, different approval stamps per department.
If the watermark has fewer pages than the output, the last watermark page is repeated for remaining pages.
- Parameter:
-
-
watermark- The file path to a local file.- Constraint:
-
- The file must exist and not be empty.
-
- Examples:
-
-
Multi-page PDF for watermarking:
setMultipageWatermark("/home/user/john/watermark.pdf") -
Transparent PNG overlay:
setMultipageWatermark("/home/user/john/watermark.png")
-
Multi-page PDF for watermarking:
function setMultipageWatermarkUrl($url)
Load a file from the specified URL and apply each page of the file as a watermark to the corresponding page of the output PDF. A watermark can be either a PDF or an image.
- Parameter:
-
-
url- Constraint:
-
- Supported protocols are http:// and https://.
-
- Examples:
-
-
Download watermark from server:
setMultipageWatermarkUrl("http://myserver.com/watermark.pdf") -
Remote logo watermark:
setMultipageWatermarkUrl("http://myserver.com/watermark.png")
-
Download watermark from server:
function setPageBackground($background)
Apply the first page of a background PDF to every page of the output PDF. Use this to add letterheads, branded templates, or decorative backgrounds that appear behind your content. Backgrounds appear beneath content, while watermarks layer on top.
Perfect for adding company letterheads to reports or applying branded templates to dynamically generated content.
- Parameter:
-
-
background- The file path to a local file.- Constraint:
-
- The file must exist and not be empty.
-
- Examples:
-
-
PDF template background:
setPageBackground("/home/user/john/background.pdf") -
Image texture background:
setPageBackground("/home/user/john/background.png")
-
PDF template background:
function setPageBackgroundUrl($url)
Load a file from the specified URL and apply the file as a background to each page of the output PDF. A background can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the background.
- Parameter:
-
-
url- Constraint:
-
- Supported protocols are http:// and https://.
-
- Examples:
-
-
Download template background:
setPageBackgroundUrl("http://myserver.com/background.pdf") -
Remote background pattern:
setPageBackgroundUrl("http://myserver.com/background.png")
-
Download template background:
function setMultipageBackground($background)
Apply each page of a background PDF to the corresponding page of the output PDF. Use this for page-specific backgrounds where each page needs a different template - for example, different letterheads for front and back pages.
If the background has fewer pages than the output, the last background page is repeated for remaining pages.
- Parameter:
-
-
background- The file path to a local file.- Constraint:
-
- The file must exist and not be empty.
-
- Examples:
-
-
PDF template background:
setMultipageBackground("/home/user/john/background.pdf") -
Image texture background:
setMultipageBackground("/home/user/john/background.png")
-
PDF template background:
function setMultipageBackgroundUrl($url)
Load a file from the specified URL and apply each page of the file as a background to the corresponding page of the output PDF. A background can be either a PDF or an image.
- Parameter:
-
-
url- Constraint:
-
- Supported protocols are http:// and https://.
-
- Examples:
-
-
Download template background:
setMultipageBackgroundUrl("http://myserver.com/background.pdf") -
Remote background pattern:
setMultipageBackgroundUrl("http://myserver.com/background.png")
-
Download template background:
PDF Format
Miscellaneous values for PDF output.
function setLinearize($value)
Create linearized PDF. This is also known as Fast Web View. Use this to optimize PDFs for progressive download, allowing users to start viewing the first page while the rest downloads.
- Parameter:
-
-
value(bool) - Set totrueto create linearized PDF.- Default:
-
false
-
function setEncrypt($value)
Encrypt the PDF to prevent search engines from indexing the contents and add an extra layer of security. Use this for confidential documents, internal reports, or any content you do not want appearing in search results.
Combine with a password to require authentication for viewing, or just use encryption alone to prevent indexing while keeping the PDF publicly readable.
- Parameter:
-
-
value(bool) - Set totrueto enable PDF encryption.- Default:
-
false
-
function setUserPassword($password)
Protect the PDF with a user password to restrict who can open and view the document. Recipients must enter this password to view the PDF. Use this for confidential documents, sensitive data, or content distribution where you want to control access.
Combine with permission flags to restrict what users can do after opening.
- Parameter:
-
-
password- The user password.
-
- Example:
-
-
Simple document password:
setUserPassword("123456")
-
Simple document password:
function setOwnerPassword($password)
Protect the PDF with an owner password for administrative control. This password allows changing permissions, passwords, and document restrictions - like a master key. Use different user and owner passwords to give recipients restricted access while retaining full control.
The owner password should be kept confidential and different from the user password.
- Parameter:
-
-
password- The owner password.
-
- Example:
-
-
Admin access password:
setOwnerPassword("123456")
-
Admin access password:
function setNoPrint($value)
Disallow printing of the output PDF to protect sensitive content. Use this for confidential documents, copyrighted materials, or preview versions you want to restrict.
- Parameter:
-
-
value(bool) - Set totrueto set the no-print flag in the output PDF.- Default:
-
false
-
function setNoModify($value)
Disallow modification of the output PDF to maintain document integrity. Use this for official documents, contracts, or records that should not be altered after creation. Prevents recipients from editing content, adding annotations, or extracting pages.
- Parameter:
-
-
value(bool) - Set totrueto set the read-only only flag in the output PDF.- Default:
-
false
-
function setNoCopy($value)
Disallow text and graphics extraction from the output PDF to protect copyrighted content. Use this for ebooks, proprietary documents, or materials where you want to prevent easy copying and redistribution.
- Parameter:
-
-
value(bool) - Set totrueto set the no-copy flag in the output PDF.- Default:
-
false
-
function setTitle($title)
Set the title of the PDF that appears in PDF reader title bars and document properties. Use descriptive titles for better organization and searchability in document management systems.
This metadata helps users identify documents when multiple PDFs are open and improves accessibility for screen readers.
- Parameter:
-
-
title- The title.
-
- Example:
-
-
Personal CV title:
setTitle("My Resume")
-
Personal CV title:
function setSubject($subject)
Set the subject of the PDF to categorize or summarize the document content. Use this to add searchable metadata for document management systems, improve organization in large PDF libraries, or provide context about the document's purpose.
Appears in PDF properties dialog.
- Parameter:
-
-
subject- The subject.
-
- Example:
-
-
Technical position subject:
setSubject("CV - Software Developer")
-
Technical position subject:
function setKeywords($keywords)
Associate keywords with the document to improve searchability in document management systems. Use relevant terms that describe the content, making it easier to find documents later.
Separate multiple keywords with commas. Particularly useful for large document repositories or DAM systems.
- Parameter:
-
-
keywords- The string with the keywords.
-
- Example:
-
-
Technical skills for searchability:
setKeywords("software developer, Unix, databases")
-
Technical skills for searchability:
function setUseMetadataFrom($index)
Use metadata (title, subject, author and keywords) from the n-th input PDF when merging multiple PDFs. Set to 1 to use the first PDF's metadata, 2 for the second, etc. Use this when combining PDFs and you want to preserve the metadata from a specific document rather than starting with blank metadata.
Set to 0 for no metadata.
- Parameter:
-
-
index(int) - Set the index of the input PDF file from which to use the metadata. 0 means no metadata.- Constraint:
-
- Must be a positive integer or 0.
-
- Example:
-
-
Use metadata from the first input PDF:
setUseMetadataFrom(1)
-
Use metadata from the first input PDF:
Viewer Preferences
These preferences specify how a PDF viewer should present the document. The preferences may be ignored by some PDF viewers.
function setPageLayout($layout)
Control how pages appear when the PDF opens in viewers that respect these preferences. "single-page" for focused reading one page at a time. "one-column" for continuous scrolling like a web page. "two-column-left" for book-like layouts with odd pages on left (international standard). "two-column-right" for magazines with odd pages on right.
- Parameter:
-
-
layout- Allowed Values:
-
-
single-page— Display one page at a time. -
one-column— Display the pages in one column. -
two-column-left— Display the pages in two columns, with odd-numbered pages on the left. -
two-column-right— Display the pages in two columns, with odd-numbered pages on the right.
-
-
function setPageMode($mode)
Control the initial display mode when the PDF opens. "full-screen" for presentations and kiosk displays where you want an immersive experience. "thumbnails" for long documents where visual page navigation is helpful. "outlines" for structured documents with bookmarks/table of contents.
- Parameter:
-
-
mode- Allowed Values:
-
-
full-screen— Full-screen mode. -
thumbnails— Thumbnail images are visible. -
outlines— Document outline is visible.
-
-
function setInitialZoomType($zoom_type)
Control how the PDF is initially zoomed when opened.
- Parameter:
-
-
zoom_type- Allowed Values:
-
-
fit-width— The page content is magnified just enough to fit the entire width of the page within the window. -
fit-height— The page content is magnified just enough to fit the entire height of the page within the window. -
fit-page— The page content is magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension.
-
-
function setInitialPage($page)
Display the specified page when the document is opened.
- Parameter:
-
-
page(int)- Constraint:
-
- Must be a positive integer.
-
- Example:
-
-
Start at second page:
setInitialPage(2)
-
Start at second page:
function setInitialZoom($zoom)
Specify the initial page zoom in percents when the document is opened.
- Parameter:
-
-
zoom(int)- Constraint:
-
- Must be a positive integer.
-
- Example:
-
-
Half-size zoom level:
setInitialZoom(50)
-
Half-size zoom level:
function setHideToolbar($value)
Hide the viewer's toolbar when the PDF is opened to provide a cleaner, more focused reading experience. Use this for presentations, kiosk displays, or immersive reading where you want minimal UI distractions.
- Parameter:
-
-
value(bool) - Set totrueto hide tool bars.- Default:
-
false
-
function setHideWindowUi($value)
Hide user interface elements like scroll bars and navigation controls when the PDF opens. Use this for presentation mode, digital signage, or embedded PDFs where you want the most minimal interface possible.
Combines with other UI hiding options for full-screen immersive viewing.
- Parameter:
-
-
value(bool) - Set totrueto hide ui elements.- Default:
-
false
-
function setFitWindow($value)
Resize the PDF viewer window to fit the size of the first displayed page when opened. Use this to ensure the PDF opens at an appropriate size rather than filling the entire screen.
Particularly useful for small documents, forms, or certificates that look better at actual size.
- Parameter:
-
-
value(bool) - Set totrueto resize the window.- Default:
-
false
-
function setCenterWindow($value)
Position the PDF viewer window in the center of the screen when opened. Use this with window resizing to create a professional, centered display for forms, certificates, or small documents.
Improves the initial viewing experience by avoiding corner-positioned windows.
- Parameter:
-
-
value(bool) - Set totrueto center the window.- Default:
-
false
-
function setDisplayTitle($value)
Display the title of the HTML document in the PDF viewer's title bar instead of the filename. Use this to show more descriptive titles when PDFs are opened - particularly useful when the filename is cryptic or auto-generated.
Improves user experience by showing meaningful document names.
- Parameter:
-
-
value(bool) - Set totrueto display the title.- Default:
-
false
-
function setRightToLeft($value)
Set the predominant reading order for text to right-to-left. This option has no direct effect on the document's contents or page numbering but can be used to determine the relative positioning of pages when displayed side by side or printed n-up.
- Parameter:
-
-
value(bool) - Set totrueto set right-to-left reading order.- Default:
-
false
-
Miscellaneous
function setDebugLog($value)
Turn on debug logging to troubleshoot conversion issues. Details about the conversion process, including resource loading, rendering steps, and error messages are stored in the debug log. Use this when conversions fail or produce unexpected results. The URL of the log can be obtained from the getDebugLogUrl method or available in conversion statistics.
- Parameter:
-
-
value(bool) - Set totrueto enable debug logging.- Default:
-
false
-
function getDebugLogUrl() { return string; }
Get the URL of the debug log for the last conversion.
- Returns:
- string - The link to the debug log.
function getRemainingCreditCount() { return integer; }
Get the number of conversion credits available in your account. Use this to monitor your credit usage and implement alerts before running out of credits.
This method can only be called after a call to one of the convertXtoY methods.
The returned value can differ from the actual count if you run parallel conversions.
The special value 999999 is returned if the information is not available.
- Returns:
- integer - The number of credits.
function getConsumedCreditCount() { return integer; }
Get the number of credits consumed by the last conversion. Use this to track costs per conversion, especially for complex documents or operations that may consume multiple credits.
- Returns:
- integer - The number of credits.
function getJobId() { return string; }
Get the unique job ID for the conversion. Use this to track conversions in your logs, correlate with debug logs, or reference specific conversions when contacting support.
- Returns:
- string - The unique job identifier.
function getPageCount() { return integer; }
Get the number of pages in the output document. Use this to validate conversion results, calculate pagination for user interfaces, or track document complexity metrics.
- Returns:
- integer - The page count.
function getOutputSize() { return integer; }
Get the size of the output document in bytes. Use this to check file sizes before delivery, implement size-based quotas, or optimize storage allocation.
- Returns:
- integer - The count of bytes.
function getVersion() { return string; }
Get the version details including API version, converter version, and client library version. Use this for debugging, logging, or ensuring compatibility when reporting issues.
- Returns:
- string - API version, converter version, and client version.
function setTag($tag)
Tag the conversion with a custom value for tracking and analytics. Use this to categorize conversions by customer ID, document type, or business unit. The tag appears in conversion statistics. A value longer than 32 characters is cut off.
- Parameter:
-
-
tag- A string with the custom tag.
-
- Example:
-
-
Track job in analytics:
setTag("client-1234")
-
Track job in analytics:
API Client Options
function setConverterVersion($version)
Set the converter version. Different versions may produce different output. Choose which one provides the best output for your case.
- Availability:
- API client >= 5.0.0. See versioning.
- Parameter:
-
-
version- The version identifier.- Allowed Values:
-
-
24.04— Version 24.04. -
20.10— Version 20.10. -
18.10— Version 18.10. -
latest— Version 20.10 is used.
-
- Default:
-
24.04
-
function setUseHttp($value)
Specify whether to use HTTP or HTTPS when connecting to the PDFCrowd API.
- Parameter:
-
-
value(bool) - Set totrueto use HTTP.- Default:
-
false
-
function setClientUserAgent($agent)
Specify the User-Agent HTTP header that the client library will use when interacting with the API.
- Availability:
- API client >= 6.4.0 See versioning.
- Parameter:
-
-
agent- The user agent string.
-
function setUserAgent($agent)
Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.
- Parameter:
-
-
agent- The user agent string.- Default:
-
pdfcrowd_php_client/6.5.4 (https://pdfcrowd.com)
-
function setProxy($host, $port, $user_name, $password)
Specify an HTTP proxy that the API client library will use to connect to the internet.
- Parameters:
-
-
host- The proxy hostname. -
port(int) - The proxy port. -
user_name- The username. -
password- The password.
-
function setUseCurl($value)
Use cURL for the conversion request instead of the file_get_contents() PHP function.
- Parameter:
-
-
value(bool) - Set totrueto use PHP's cURL.- Default:
-
false
-
function setRetryCount($count)
Specify the number of automatic retries when a 502 or 503 HTTP status code is received. The status code indicates a temporary network issue. This feature can be disabled by setting to 0.
- Parameter:
-
-
count(int) - Number of retries.- Default:
-
1
-
- Example:
-
-
Retry failed requests three times:
setRetryCount(3)
-
Retry failed requests three times: