Constructor
func NewPdfToPdfClient(userName string, apiKey string) PdfToPdfClient
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:
-
-
userName- Your username at PDFCrowd. -
apiKey- Your API key.
-
PDF Manipulation
func (client *PdfToPdfClient) SetAction(action string) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) Convert() ([]byte, error)
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:
- []byte - Byte array containing the output PDF.
func (client *PdfToPdfClient) ConvertToStream(outStream io.Writer) error
Execute the configured PDF manipulation operation and write the resulting PDF directly to an output stream.
- Parameter:
-
-
outStream(OutputStream) - The output stream that will contain the output PDF.
-
func (client *PdfToPdfClient) ConvertToFile(filePath string) error
Execute the configured PDF manipulation operation and save the resulting PDF to a file.
- Parameter:
-
-
filePath- The output file path.
-
func (client *PdfToPdfClient) AddPdfFile(filePath string) *PdfToPdfClient
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:
-
-
filePath- The file path to a local PDF file.- Constraint:
-
- The file must exist and not be empty.
-
func (client *PdfToPdfClient) AddPdfRawData(data []byte) *PdfToPdfClient
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.
-
func (client *PdfToPdfClient) SetInputPdfPassword(password string) *PdfToPdfClient
Password for decrypting encrypted input PDFs.
- Availability:
- API client >= 5.4.0, converter >= 20.10. See versioning.
- Parameter:
-
-
password- The input PDF password.
-
func (client *PdfToPdfClient) SetPageRange(pages string) *PdfToPdfClient
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
func (client *PdfToPdfClient) SetPageWatermark(watermark string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetPageWatermarkUrl(url string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetMultipageWatermark(watermark string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetMultipageWatermarkUrl(url string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetPageBackground(background string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetPageBackgroundUrl(url string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetMultipageBackground(background string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetMultipageBackgroundUrl(url string) *PdfToPdfClient
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.
func (client *PdfToPdfClient) SetLinearize(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetEncrypt(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetUserPassword(password string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetOwnerPassword(password string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetNoPrint(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetNoModify(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetNoCopy(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetTitle(title string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetSubject(subject string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetKeywords(keywords string) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetUseMetadataFrom(index int) *PdfToPdfClient
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.
func (client *PdfToPdfClient) SetPageLayout(layout string) *PdfToPdfClient
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.
-
-
func (client *PdfToPdfClient) SetPageMode(mode string) *PdfToPdfClient
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.
-
-
func (client *PdfToPdfClient) SetInitialZoomType(zoomType string) *PdfToPdfClient
Control how the PDF is initially zoomed when opened.
- Parameter:
-
-
zoomType- 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.
-
-
func (client *PdfToPdfClient) SetInitialPage(page int) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetInitialZoom(zoom int) *PdfToPdfClient
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:
func (client *PdfToPdfClient) SetHideToolbar(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetHideWindowUi(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetFitWindow(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetCenterWindow(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetDisplayTitle(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetRightToLeft(value bool) *PdfToPdfClient
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
func (client *PdfToPdfClient) SetDebugLog(value bool) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) GetDebugLogUrl() string
Get the URL of the debug log for the last conversion.
- Returns:
- string - The link to the debug log.
func (client *PdfToPdfClient) GetRemainingCreditCount() int
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:
- int - The number of credits.
func (client *PdfToPdfClient) GetConsumedCreditCount() int
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:
- int - The number of credits.
func (client *PdfToPdfClient) GetJobId() 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.
func (client *PdfToPdfClient) GetPageCount() int
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:
- int - The page count.
func (client *PdfToPdfClient) GetOutputSize() int
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:
- int - The count of bytes.
func (client *PdfToPdfClient) GetVersion() 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.
func (client *PdfToPdfClient) SetTag(tag string) *PdfToPdfClient
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
func (client *PdfToPdfClient) SetConverterVersion(version string) *PdfToPdfClient
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
-
func (client *PdfToPdfClient) SetUseHttp(value bool) *PdfToPdfClient
Specify whether to use HTTP or HTTPS when connecting to the PDFCrowd API.
- Parameter:
-
-
value(bool) - Set totrueto use HTTP.- Default:
-
false
-
func (client *PdfToPdfClient) SetClientUserAgent(agent string) *PdfToPdfClient
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.
-
func (client *PdfToPdfClient) SetUserAgent(agent string) *PdfToPdfClient
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_go_client/6.5.4 (https://pdfcrowd.com)
-
func (client *PdfToPdfClient) SetProxy(host string, port int, userName string, password string) *PdfToPdfClient
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. -
userName- The username. -
password- The password.
-
func (client *PdfToPdfClient) SetRetryCount(count int) *PdfToPdfClient
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: