This is the documentation of the Java client library for the legacy Pdfcrowd API v1. We strongly recommend the new improved Pdfcrowd API v2 for new integrations.
Install the Pdfcrowd API client library for Java.
In the following examples, do not forget to replace "username"
and "apikey"
with your username and API key.
import com.pdfcrowd.*; import java.io.*; public class PdfcrowdTest { public static void main(String[] args) { try { FileOutputStream fileStream; // create an API client instance Client client = new Client("your_username", "your_apikey"); // convert a web page and save the PDF to a file fileStream = new FileOutputStream("example.pdf"); client.convertURI("http://example.com/", fileStream); fileStream.close(); // convert an HTML string and store the PDF into a byte array ByteArrayOutputStream memStream = new ByteArrayOutputStream(); String html = "<html><body>In-memory HTML.</body></html>"; client.convertHtml(html, memStream); // convert an HTML file fileStream = new FileOutputStream("file.pdf"); client.convertFile("/path/to/local/file.html", fileStream); fileStream.close(); // retrieve the number of credits in your account Integer ncredits = client.numTokens(); } catch(PdfcrowdError why) { System.err.println(why.getMessage()); } catch(IOException exc) { // handle the exception } } }
try { // .. // call the API } catch(PdfcrowdError why) { // why.getMessage() returns an error message }
Provides access to the Pdfcrowd API from your Java applications.
public Client(String username, String apikey)
public void convertHtml(String html, java.io.OutputStream outstream)
public void convertFile(String fpath, java.io.OutputStream outstream)
public void convertURI(String url, java.io.OutputStream outstream)
public void setPageWidth(double/String value)
public void setPageHeight(double/String value)
public void setPageMargins(String top, String right, String bottom, String left)
public void setHorizontalMargin(double/String value)
public void setVerticalMargin(double/String value)
public void setFooterHtml(String html)
public void setFooterUrl(String url)
public void setHeaderHtml(String html)
public void setHeaderUrl(String url)
public void setHeaderFooterPageExcludeList(String exclist)
public void setPageNumberingOffset(int offset)
public void enableImages(boolean value)
public void enableBackgrounds(boolean value)
public void setHtmlZoom(double value)
public void enableJavaScript(boolean value)
public void enableHyperlinks(boolean value)
public void setDefaultTextEncoding(String value)
utf-8
.
public void usePrintMedia(boolean value)
print
CSS media type
is used (if available).
public void setEncrypted(boolean value)
public void setUserPassword(String pwd)
public void setOwnerPassword(String pwd)
public void setNoPrint(boolean value)
public void setNoModify(boolean value)
public void setNoCopy(boolean value)
public void setPageLayout(int value)
SINGLE_PAGE
CONTINUOUS
CONTINUOUS_FACING
public void setPageMode(int value)
FULLSCREEN
- Full-screen mode.public void setInitialPdfZoomType(int value)
FIT_WIDTH
FIT_HEIGHT
FIT_PAGE
public void setInitialPdfExactZoom(double value)
public void setPdfScalingFactor(double value)
public void setPageBackgroundColor(String value)
public void setTransparentBackground(boolean value)
body {background-color:rgba(255,255,255,0.0);}
public void setAuthor(String author)
public void setWatermark(String url, String offset_x, String offset_y)
public void setWatermarkRotation(double angle)
public void setWatermarkInBackground(boolean value)
public void useSSL(boolean use_ssl)
public int numTokens()
public void setMaxPages(int npages)
public void setFailOnNon200(boolean value)
Derived from RuntimeException
. It is thrown when an error
occurs. Use getMessage()
method to get the error message.
Page dimensions and margins can be specified in inches (in), millimeters (mm),
centimeters (cm), or points (pt). If no units are specified, points are
assumed. Examples: "210mm"
, "8.5in"
.