SDKs overview

BuildPDF offers a suite of Software Development Kits (SDKs) designed to streamline the integration of its PDF generation and manipulation capabilities into various applications. These SDKs abstract the underlying RESTful API, allowing developers to interact with BuildPDF services using native language constructs rather than direct HTTP requests. The primary objective of these libraries is to reduce development time and complexity when implementing features such as automated report creation, invoice generation, and dynamic document assembly (BuildPDF developer documentation).

SDKs typically include functionalities for authentication, request parameter serialization, response deserialization, and error handling. This standardization helps in maintaining consistency across different programming environments and minimizes the potential for integration errors. BuildPDF provides official SDKs for several popular programming languages, ensuring broader compatibility and ease of adoption for developers working in diverse tech stacks.

Beyond official offerings, community libraries can emerge to support niche use cases or provide alternative interfaces to the API. While official SDKs are maintained by BuildPDF, community contributions are often driven by specific developer needs and open-source collaboration. Utilizing an SDK or library simplifies the process of integrating PDF features into web and desktop applications, enabling developers to focus on application logic rather in-depth API communication protocols (such as those outlined by the W3C for web standards).

Official SDKs by language

BuildPDF provides official SDKs for various programming languages, each maintained to ensure compatibility with the latest API versions and features. These SDKs are designed to offer a consistent and idiomatic interface for developers in their preferred language. The official SDKs cover:

  • Node.js
  • Python
  • Ruby
  • PHP
  • Go

Each SDK typically includes methods for initiating PDF generation, managing templates, handling document storage, and processing callbacks or webhooks. Developers can refer to the BuildPDF API reference documentation for detailed information on available endpoints and data models.

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

Language Package Name (Typical) Installation Command (Example) Maturity
Node.js @buildpdf/buildpdf-node npm install @buildpdf/buildpdf-node Stable
Python buildpdf-python pip install buildpdf-python Stable
Ruby buildpdf-ruby gem install buildpdf-ruby Stable
PHP buildpdf/buildpdf-php composer require buildpdf/buildpdf-php Stable
Go github.com/buildpdf/go-buildpdf go get github.com/buildpdf/go-buildpdf Stable

Installation

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

Node.js

For Node.js projects, the SDK is available via npm. Navigate to your project directory in the terminal and execute:

npm install @buildpdf/buildpdf-node

Alternatively, if you are using Yarn:

yarn add @buildpdf/buildpdf-node

Python

Python developers can install the SDK using pip:

pip install buildpdf-python

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

Ruby

Ruby applications use Bundler to manage gems. Add the BuildPDF gem to your Gemfile:

gem 'buildpdf-ruby'

Then, run bundle install in your terminal:

bundle install

If not using Bundler, you can install it directly:

gem install buildpdf-ruby

PHP

PHP projects typically use Composer for dependency management. To install the BuildPDF SDK, run the following command in your project's root directory:

composer require buildpdf/buildpdf-php

This command adds the library to your composer.json and installs its dependencies.

Go

For Go projects, the SDK can be fetched using the go get command:

go get github.com/buildpdf/go-buildpdf

After fetching, you can import the package into your Go source files.

Quickstart example

This quickstart demonstrates how to use the Node.js SDK to generate a simple PDF document from HTML content. The example assumes you have your BuildPDF API key configured as an environment variable or passed directly.

const BuildPDF = require('@buildpdf/buildpdf-node');

// Initialize the BuildPDF client with your API key
// It's recommended to use environment variables for keys in production
const buildpdf = new BuildPDF(process.env.BUILDPDF_API_KEY);

async function generatePdf() {
  try {
    const htmlContent = `
      <h1>Hello, BuildPDF!</h1>
      <p>This is a simple PDF generated using the BuildPDF Node.js SDK.</p>
      <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
      </ul>
      <p>Current date: ${new Date().toLocaleDateString()}</p>
    `;

    const document = await buildpdf.documents.create({
      html: htmlContent,
      fileName: 'my-first-document.pdf',
      options: {
        // Optional: specify additional PDF options like page size, margins
        pageSize: 'A4',
        marginTop: '1in',
        marginBottom: '1in',
        marginLeft: '1in',
        marginRight: '1in',
      },
    });

    console.log('PDF generation successful!');
    console.log('Document ID:', document.id);
    console.log('Download URL:', document.downloadUrl);
    // In a real application, you would handle saving or streaming the PDF

  } catch (error) {
    console.error('Error generating PDF:', error.message);
    if (error.response) {
      console.error('API Response Error Data:', error.response.data);
    }
  }
}

generatePdf();

This example performs the following steps:

  1. Initializes the BuildPDF client using an API key.
  2. Defines the HTML content that will be converted into a PDF.
  3. Calls the documents.create method with the HTML content and desired file name.
  4. Logs the document ID and a temporary download URL upon successful creation.
  5. Includes error handling for API call failures.

For more detailed examples and advanced features, such as template rendering, form filling, or PDF manipulation, refer to the official BuildPDF documentation.

Community libraries

While BuildPDF maintains a set of official SDKs, the open-source community may also develop and contribute libraries that interact with the BuildPDF API. These community-driven projects can offer alternative interfaces, specialized integrations, or support for languages not covered by official SDKs.

Community libraries are typically found on platforms like GitHub, npm, PyPI, or RubyGems, and their development is often driven by the specific needs of developers who integrate BuildPDF into their projects. Examples of scenarios where community libraries might emerge include:

  • Framework-specific wrappers: Libraries optimized for particular web frameworks (e.g., a Django package for Python, a Laravel package for PHP).
  • Utility functions: Helpers for common tasks that extend beyond the core API functionality.
  • Language support: SDKs for languages where an official client is not provided.
  • Specialized integrations: Connectors for specific third-party services or data sources.

When considering a community library, it is advisable to evaluate its maintenance status, community activity, and compatibility with the current BuildPDF API version. Checking the project's repository for recent commits, issue resolution, and clear documentation can provide insights into its reliability. While official SDKs offer guarantees of support and updates from BuildPDF, community contributions can sometimes offer innovative solutions or highly tailored functionalities.

Developers interested in contributing to the BuildPDF ecosystem or finding community projects can often search public code repositories or developer forums. The Google Open Source initiative highlights the collaborative nature of such development, where community efforts expand the reach and utility of APIs.