SDKs overview

CraftMyPDF offers Software Development Kits (SDKs) to facilitate integration with its PDF Generation API. These SDKs are designed to abstract the underlying HTTP requests and JSON payload construction, allowing developers to interact with the API using native language constructs. The primary goal of these libraries is to streamline the process of generating PDFs dynamically from predefined templates and user-supplied data.

The API itself is RESTful, meaning it uses standard HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources, with data typically exchanged in JSON format. The SDKs wrap these interactions, providing methods for common tasks such as creating PDF documents, managing templates, and handling webhooks. CraftMyPDF's approach emphasizes clear code examples and comprehensive documentation to enhance the developer experience, particularly for those integrating automated document generation into their workflows.

Developers can utilize these SDKs to automate tasks like invoice creation, certificate issuance, and various forms of report generation. The SDKs handle authentication, typically using an API key, and manage the serialization and deserialization of data between the application and the CraftMyPDF service. This reduces the boilerplate code required and helps maintain consistency across different programming environments.

Official SDKs by language

CraftMyPDF provides official SDKs across several popular programming languages, ensuring broad compatibility for developers. These SDKs are maintained by CraftMyPDF and are the recommended method for integrating with their API. Each SDK is tailored to the conventions and best practices of its respective language, offering a familiar development experience.

The following table lists the official SDKs, their package names, and typical installation commands:

Language Package Name Installation Command Maturity
Node.js craftmypdf npm install craftmypdf or yarn add craftmypdf Stable
PHP craftmypdf/craftmypdf composer require craftmypdf/craftmypdf Stable
Python craftmypdf-python pip install craftmypdf-python Stable
Ruby craftmypdf-ruby gem install craftmypdf-ruby Stable
Java com.craftmypdf:craftmypdf-java Add to pom.xml or build.gradle Stable
Go github.com/craftmypdf/craftmypdf-go go get github.com/craftmypdf/craftmypdf-go Stable

Installation

Installing a CraftMyPDF SDK typically involves using the package manager specific to your programming language. The process is generally straightforward and follows standard practices for dependency management.

Node.js Installation

For Node.js projects, the craftmypdf package is available via npm or Yarn. Navigate to your project directory and execute one of the following commands:

npm install craftmypdf

or

yarn add craftmypdf

PHP Installation

PHP projects use Composer for dependency management. Add the craftmypdf/craftmypdf package to your project by running:

composer require craftmypdf/craftmypdf

Ensure Composer is installed and accessible in your environment. More details on Composer usage are available in its official documentation.

Python Installation

Python developers can install the craftmypdf-python library using pip:

pip install craftmypdf-python

It is often recommended to install Python packages within a virtual environment to manage project-specific dependencies.

Ruby Installation

For Ruby applications, the craftmypdf-ruby gem is installed using the RubyGems package manager:

gem install craftmypdf-ruby

You may need to add require 'craftmypdf' to your Ruby script to use the library.

Java Installation

Java projects typically use Maven or Gradle. For Maven, add the following dependency to your pom.xml:

<dependency>
    <groupId>com.craftmypdf</groupId>
    <artifactId>craftmypdf-java</artifactId>
    <version>1.0.0</version> <!-- Replace with the latest version -->
</dependency>

For Gradle, add this to your build.gradle file:

implementation 'com.craftmypdf:craftmypdf-java:1.0.0' // Replace with the latest version

Check the CraftMyPDF Java SDK documentation for the most current version number.

Go Installation

Go modules are used to manage dependencies for Go projects. To install the Go SDK, run:

go get github.com/craftmypdf/craftmypdf-go

After fetching, you can import it in your Go source files as "github.com/craftmypdf/craftmypdf-go".

Quickstart example

This example demonstrates how to generate a PDF using the CraftMyPDF Python SDK. The process involves initializing the client with an API key, specifying a template, and providing data to merge into the template. For this example, replace YOUR_API_KEY and YOUR_TEMPLATE_ID with your actual CraftMyPDF credentials and template identifier.

Python Quickstart

First, ensure you have the Python SDK installed (pip install craftmypdf-python). Then, create a Python script similar to the following:

import craftmypdf

def generate_document():
    api_key = "YOUR_API_KEY" # Replace with your CraftMyPDF API key
    template_id = "YOUR_TEMPLATE_ID" # Replace with your template ID

    client = craftmypdf.Client(api_key=api_key)

    # Data to be merged into the PDF template
    data = {
        "customer_name": "Jane Doe",
        "invoice_number": "INV-2026-001",
        "items": [
            {"description": "Product A", "quantity": 2, "price": 10.00},
            {"description": "Product B", "quantity": 1, "price": 25.50}
        ],
        "total_amount": 45.50
    }

    try:
        # Generate the PDF
        response = client.generate_pdf(template_id=template_id, data=data)

        # Save the PDF to a file
        with open("output.pdf", "wb") as f:
            f.write(response.content)
        print("PDF generated successfully: output.pdf")

    except craftmypdf.CraftMyPDFError as e:
        print(f"Error generating PDF: {e}")

if __name__ == "__main__":
    generate_document()

This script initializes the CraftMyPDF client, defines a dictionary of data that matches the placeholders in your chosen template, and then calls the generate_pdf method. The resulting PDF content is saved to a file named output.pdf. More detailed examples and error handling can be found in the CraftMyPDF Python SDK documentation.

Node.js Quickstart

For Node.js, after installing the SDK (npm install craftmypdf), you can use the following code:

const CraftMyPDF = require('craftmypdf');

async function generateDocument() {
  const apiKey = "YOUR_API_KEY"; // Replace with your CraftMyPDF API key
  const templateId = "YOUR_TEMPLATE_ID"; // Replace with your template ID

  const client = new CraftMyPDF.Client(apiKey);

  const data = {
    "customer_name": "John Smith",
    "order_id": "ORD-XYZ-789",
    "products": [
      {"name": "Widget X", "qty": 3, "unit_price": 15.00},
      {"name": "Gadget Y", "qty": 1, "unit_price": 50.00}
    ],
    "grand_total": 95.00
  };

  try {
    const response = await client.generatePdf(templateId, data);

    // Assume response.content is a Buffer containing the PDF data
    // In a real application, you might stream this or save it to disk
    console.log('PDF generated successfully. Content length:', response.content.length, 'bytes');
    // Example: Save to a file (requires 'fs' module)
    // const fs = require('fs');
    // fs.writeFileSync('output-nodejs.pdf', response.content);

  } catch (error) {
    console.error('Error generating PDF:', error.message);
  }
}

generateDocument();

This Node.js example parallels the Python version, demonstrating client initialization and the generatePdf call. The response content, which is the binary PDF data, can then be handled as needed by the application, such as saving to a file or serving directly via a web response.

Community libraries

As of 2026, CraftMyPDF primarily supports official SDKs for the languages listed above. The platform focuses on maintaining these first-party libraries to ensure stability, up-to-date features, and direct compatibility with their API. While official SDKs are the primary recommendation, the underlying RESTful API documentation is comprehensive enough to allow developers to build custom client libraries or integrate directly using standard HTTP clients in any language. This approach provides flexibility for niche use cases or languages not covered by an official SDK.

Developers who prefer to work without an official SDK can consult the CraftMyPDF API Reference to understand the endpoints, request formats, and authentication mechanisms. This enables integration with languages such as Rust, C#, or others by constructing HTTP requests manually or using generic HTTP client libraries. Any community-driven efforts to create third-party libraries would typically emerge from these direct API interactions, though CraftMyPDF's official documentation does not currently highlight a specific list of community-maintained SDKs.