### Install Presa Go Package Source: https://docs.presa.dev/llms-full.txt Installs the Presa Go library using the go get command. This is necessary before using Presa for PDF generation in Go projects. ```bash go get github.com/faiscadev/presa-go ``` -------------------------------- ### Install Presa Python Package Source: https://docs.presa.dev/llms-full.txt Installs the Presa Python library using pip. This is the first step to using Presa for PDF generation in Python. ```bash pip install presa ``` -------------------------------- ### Python PDF Generation Source: https://docs.presa.dev/llms-full.txt This section details how to generate PDFs using the Presa Python library, both directly and via a client. It includes installation instructions and usage examples. ```APIDOC ## Python PDF Generation ### Description Generate PDFs from HTML content using the Presa Python library. Examples are provided for direct generation and using the Presa client for more advanced configurations. ### Installation ```bash pip install presa ``` ### Direct Generation ```python from presa import PDF result = PDF.generate(html="

Hello

") # result.buffer (bytes), result.size (int) ``` ### Client Generation ```python from presa import Presa, PresaConfig, GenerateOptions, Margins client = Presa(PresaConfig(api_key="...", base_url="...", timeout=30.0)) html = "

Hello

" result = client.generate(GenerateOptions(html=html, format="A4", margins=Margins(top="1cm"))) ``` ### Errors - `AuthenticationError` - `ApiError` (.code, .status) - `TimeoutError` ``` -------------------------------- ### Go PDF Generation Source: https://docs.presa.dev/llms-full.txt This section outlines how to generate PDFs using the Presa Go library, including installation, direct generation, and client usage with error handling. ```APIDOC ## Go PDF Generation ### Description Generate PDFs from HTML content using the Presa Go library. Examples cover direct generation and utilizing the Presa client for API interactions. ### Installation ```bash go get github.com/faiscadev/presa-go ``` ### Direct Generation ```go import ( "context" "github.com/faiscadev/presa-go" ) ctx := context.Background() result, err := presa.Generate(ctx, presa.Options{HTML: "

Hello

"}) // result.Buffer ([]byte), result.Size (int) ``` ### Client Generation ```go import ( "context" "time" "github.com/faiscadev/presa-go" ) ctx := context.Background() client, _ := presa.NewClient(&presa.Config{APIKey: "...", BaseURL: "...", Timeout: 30*time.Second}) html := "

Hello

" result, err := client.Generate(ctx, presa.Options{HTML: html, Format: "A4"}) ``` ### Errors - `*AuthenticationError` - `*APIError` (.Code, .Status, .Message) - `*TimeoutError` ``` -------------------------------- ### Generate PDF with Presa Go Client Source: https://docs.presa.dev/llms-full.txt Illustrates PDF generation using a Presa client in Go, enabling configuration of format and other options. Client initialization requires API key, base URL, and timeout settings. ```go client, _ := presa.NewClient(&presa.Config{APIKey: "...", BaseURL: "...", Timeout: 30*time.Second}) result, err := client.Generate(ctx, presa.Options{HTML: html, Format: "A4"}) ``` -------------------------------- ### Generate PDF with Presa Python Client Source: https://docs.presa.dev/llms-full.txt Shows how to generate a PDF using a Presa client instance in Python, allowing for more configuration options like format and margins. Requires API key and base URL for client initialization. ```python from presa import Presa, PresaConfig, GenerateOptions, Margins client = Presa(PresaConfig(api_key="...", base_url="...", timeout=30.0)) result = client.generate(GenerateOptions(html=html, format="A4", margins=Margins(top="1cm"))) ``` -------------------------------- ### Node.js/TypeScript SDK - PDF Generation Source: https://docs.presa.dev/llms-full.txt Demonstrates how to use the Presa SDK for Node.js/TypeScript to generate a PDF from HTML. It shows both a direct generation method and initialization with a client for more options. ```bash npm install presa-sdk ``` ```typescript import { PDF } from "presa-sdk"; const { buffer, size } = await PDF.generate({ html: "

Hello

" }); ``` ```typescript import { Presa } from "presa-sdk"; const client = new Presa({ apiKey: "...", baseUrl: "...", timeout: 30000 }); const result = await client.generate({ html, format: "A4", margins: { top: "1cm" } }); ``` -------------------------------- ### Generate PDF from HTML in Go Source: https://docs.presa.dev/llms-full.txt Demonstrates generating a PDF from an HTML string using the Presa Go library. The function returns the PDF data as a byte slice and an error if one occurred. ```go result, err := presa.Generate(ctx, presa.Options{HTML: "

Hello

"}) # result.Buffer ([]byte), result.Size (int) ``` -------------------------------- ### Generate PDF from HTML in Python Source: https://docs.presa.dev/llms-full.txt Demonstrates how to generate a PDF directly from an HTML string using the Presa Python library. The result object contains the PDF buffer and its size. ```python from presa import PDF result = PDF.generate(html="

Hello

") # result.buffer (bytes), result.size (int) ``` -------------------------------- ### POST /v1/pdf/from-html Source: https://docs.presa.dev/llms-full.txt Converts HTML content to a PDF document. Supports various options for formatting, margins, and background printing. ```APIDOC ## POST /v1/pdf/from-html ### Description Converts HTML content to a PDF document. Supports various options for formatting, margins, and background printing. ### Method POST ### Endpoint /v1/pdf/from-html ### Parameters #### Query Parameters None #### Request Body - **html** (string) - Required - HTML content, max 5MB - **format** (string | object) - Optional - Specifies the page format. Can be a predefined string like "A4" or "Letter", or a custom object `{ "width": "210mm", "height": "297mm" }`. - **landscape** (boolean) - Optional - Set to `true` for landscape orientation. Defaults to `false`. - **margins** (object) - Optional - Defines page margins using CSS units (cm, mm, in, px). Example: `{ "top": "1cm", "right": "1cm", "bottom": "1cm", "left": "1cm" }`. - **printBackground** (boolean) - Optional - Whether to print the background. Defaults to `true`. - **scale** (number) - Optional - Scales the rendering. Range: 0.1–2.0. Defaults to `1.0`. ### Request Example ```json { "html": "

Hello

", "format": "A4", "landscape": false, "margins": { "top": "1cm", "right": "1cm", "bottom": "1cm", "left": "1cm" }, "printBackground": true, "scale": 1.0 } ``` ### Response #### Success Response (200) - **Content-Type**: `application/pdf` - The response body contains the raw PDF bytes. #### Error Responses - **400 INVALID_HTML**: Restricted protocols (file://, javascript:, data:) used in HTML. - **400 BAD_REQUEST**: Malformed request body. - **403 QUOTA_EXCEEDED**: Monthly quota exceeded (for free tier users). - **408 GENERATION_TIMEOUT**: PDF generation process timed out. - **413 PAYLOAD_TOO_LARGE**: The provided HTML content exceeds the 5MB limit. - **401 UNAUTHORIZED**: Missing or invalid authentication credentials. ### Error Envelope ```json { "error": { "code": "ERROR_CODE", "message": "Description", "status": 400 } } ``` ``` -------------------------------- ### Authentication API Source: https://docs.presa.dev/llms-full.txt Endpoints for user authentication, including signup, login, logout, and managing the current user's session. ```APIDOC ## Authentication API ### POST /auth/signup #### Description Creates a new user account. #### Method POST #### Endpoint /auth/signup #### Request Body - **email** (string) - Required - User's email address. - **password** (string) - Required - User's chosen password. #### Response - **data** (object) - Contains user, team, and API key information. - **user** (object) - Details of the created user. - **team** (object) - Details of the user's team. - **apiKey** (string) - The newly generated API key for the user. Sets `access_token` cookie upon successful signup. ### POST /auth/login #### Description Authenticates an existing user. #### Method POST #### Endpoint /auth/login #### Request Body - **email** (string) - Required - User's email address. - **password** (string) - Required - User's password. #### Response - **data** (object) - Contains user and team information. - **user** (object) - Details of the authenticated user. - **team** (object) - Details of the user's team. Sets `access_token` cookie upon successful login. ### POST /auth/logout #### Description Clears the user's session cookie. #### Method POST #### Endpoint /auth/logout #### Authentication Requires session cookie (`access_token`). ### GET /auth/me #### Description Retrieves information about the currently authenticated user. #### Method GET #### Endpoint /auth/me #### Authentication Bearer token or session cookie. #### Response - **data** (object) - User information. - **id** (string) - User's unique identifier. - **email** (string) - User's email address. - **plan** (string) - User's subscription plan. - **createdAt** (string) - Timestamp of account creation. ### PUT /auth/password #### Description Changes the password for the authenticated user. #### Method PUT #### Endpoint /auth/password #### Authentication Requires session cookie (`access_token`). #### Request Body - **currentPassword** (string) - Required - The user's current password. - **newPassword** (string) - Required - The desired new password. ### DELETE /auth/account #### Description Deletes the account of the currently authenticated user. #### Method DELETE #### Endpoint /auth/account #### Authentication Requires session cookie (`access_token`). ``` -------------------------------- ### Generate PDF from HTML (Request Body) Source: https://docs.presa.dev/llms-full.txt Defines the JSON request body structure for the POST /v1/pdf/from-html endpoint. It includes parameters for HTML content, page format, orientation, margins, background printing, and scaling. ```json { "html": "

Hello

", "format": "A4", "landscape": false, "margins": { "top": "1cm", "right": "1cm", "bottom": "1cm", "left": "1cm" }, "printBackground": true, "scale": 1.0 } ``` -------------------------------- ### Usage Statistics Source: https://docs.presa.dev/llms-full.txt Endpoints for retrieving information about PDF generation usage, quotas, and event logs. ```APIDOC ## Usage Statistics ### GET /v1/usage #### Description Retrieves the current billing period's PDF generation usage statistics. #### Method GET #### Endpoint /v1/usage #### Authentication Requires session cookie (`access_token`). #### Response - **data** (object) - Usage details. - **periodStart** (string) - Start date of the current billing period. - **periodEnd** (string) - End date of the current billing period. - **pdfsGenerated** (integer) - Number of PDFs generated in the current period. - **quotaLimit** (integer) - The total quota limit for the period. - **remaining** (integer) - Number of PDF generations remaining in the current period. ### GET /v1/usage/stats #### Description Retrieves extended usage statistics, including performance metrics. #### Method GET #### Endpoint /v1/usage/stats #### Authentication Requires session cookie (`access_token`). #### Response - **data** (object) - Extended usage statistics. - **periodStart** (string) - Start date of the current billing period. - **periodEnd** (string) - End date of the current billing period. - **pdfsGenerated** (integer) - Number of PDFs generated. - **quotaLimit** (integer) - The total quota limit. - **remaining** (integer) - Remaining PDF generations. - **avgLatencyMs** (number) - Average PDF generation latency in milliseconds. - **successRate** (number) - The success rate of PDF generation requests. ### GET /v1/usage/events?limit=20 #### Description Lists recent usage events, providing details about individual PDF generation requests. #### Method GET #### Endpoint /v1/usage/events #### Authentication Requires session cookie (`access_token`). #### Query Parameters - **limit** (integer) - Optional - The maximum number of events to return. Range: 1–100. Defaults to 20. #### Response - **data** (array) - A list of usage event objects. - Each object contains: `id`, `apiKeyId`, `timestamp`, `success`, `statusCode`, `pdfSizeBytes`, `latencyMs`. ``` -------------------------------- ### Authenticate with Bearer Token Source: https://docs.presa.dev/llms-full.txt This snippet shows how to authenticate API requests using a Bearer token, which is typically an API key. This method is used for programmatic access to the Presa API. ```http Authorization: Bearer ``` -------------------------------- ### API Keys Management Source: https://docs.presa.dev/llms-full.txt Endpoints for creating, listing, revealing, and revoking API keys associated with a team. ```APIDOC ## API Keys Management ### POST /v1/api-keys #### Description Creates a new API key for the authenticated team. #### Method POST #### Endpoint /v1/api-keys #### Authentication Requires session cookie (`access_token`). #### Request Body - **name** (string) - Required - A descriptive name for the API key. #### Response - **data** (object) - Information about the newly created API key. - **id** (string) - Unique identifier for the API key. - **name** (string) - The name of the API key. - **prefix** (string) - A prefix of the API key. - **key** (string) - The full API key (shown only once upon creation). - **createdAt** (string) - Timestamp of key creation. ### GET /v1/api-keys #### Description Lists all API keys associated with the authenticated team. #### Method GET #### Endpoint /v1/api-keys #### Authentication Requires session cookie (`access_token`). #### Response - **data** (array) - A list of API key objects. - Each object contains: `id`, `name`, `prefix`, `createdAt`, `lastUsedAt`, `revokedAt`. ### POST /v1/api-keys/:id/reveal #### Description Reveals the full value of a specific API key. #### Method POST #### Endpoint /v1/api-keys/:id/reveal #### Parameters - **id** (string) - Path Parameter - The ID of the API key to reveal. #### Authentication Requires session cookie (`access_token`). #### Response - **data** (object) - Contains the full API key. - **key** (string) - The full API key value. ### DELETE /v1/api-keys/:id #### Description Revokes a specific API key, making it unusable. #### Method DELETE #### Endpoint /v1/api-keys/:id #### Parameters - **id** (string) - Path Parameter - The ID of the API key to revoke. #### Authentication Requires session cookie (`access_token`). #### Response - **data** (object) - Confirmation of revocation. - **id** (string) - The ID of the revoked API key. - **revokedAt** (string) - Timestamp of revocation. ``` -------------------------------- ### Error Response Envelope Source: https://docs.presa.dev/llms-full.txt Illustrates the standard JSON structure for error responses from the Presa API. It includes an error code, a descriptive message, and the HTTP status code. ```json { "error": { "code": "ERROR_CODE", "message": "Description", "status": 400 } } ``` -------------------------------- ### Health Check Source: https://docs.presa.dev/llms-full.txt An endpoint to check the operational status of the Presa service and its dependencies. ```APIDOC ## Health Check ### GET /v1/health #### Description Checks the operational status of the Presa service and its underlying components. #### Method GET #### Endpoint /v1/health #### Authentication No authentication required. #### Response - **status** (string) - Overall service status (`ok` or `degraded`). - **database** (string) - Database connection status (`connected` or `error`). - **gotenberg** (string) - Gotenberg service status (`reachable` or `error`). - **rateLimiter** (string) - Rate limiter status (`healthy` or `error`). - **version** (string) - The current version of the Presa service. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.