# Authorization Source: https://docs.htmldocs.com/api-reference/authorization ### Getting Started API requests to htmldocs require an API key which can be obtained from the API tokens section in the [Dashboard](https://htmldocs.com/dashboard). API keys are scoped to your team. Each API key provides access only to documents and resources owned by that team. ### Headers API keys should be included in the `Authorization` header of your requests using the Bearer token format: ``` Authorization: Bearer YOUR_API_KEY ``` ### Content Type All requests should set the `Content-Type` header to `application/json`. # Generate Document Source: https://docs.htmldocs.com/api-reference/generate-document POST /api/documents/{documentId} Generates a PDF document from a published document template. This endpoint is for generating a document based on a template you've published to a team. To publish a document, see the [publish command](a/cli#htmldocs-publish-file). You can find the ids of your published documents in the [dashboard](https://htmldocs.com/dashboard). # Generate from HTML Source: https://docs.htmldocs.com/api-reference/generate-html POST /api/generate Generates a PDF document from raw HTML content and/or a URL. If both are provided, the HTML content will be injected into the page at the specified URL. This endpoint allows you to generate a PDF document directly from HTML content, without needing to publish a template first. For generating documents from published templates, see the [Generate Document](/api/generate-document) endpoint instead. # CLI Source: https://docs.htmldocs.com/cli After installing the htmldocs package, you can start using the command line interface (CLI). ## `init` Initializes a new htmldocs project in the current directory. ```bash npm theme={null} npx htmldocs@latest init ``` ```bash pnpm theme={null} pnpx htmldocs@latest init ``` ```bash yarn theme={null} yarn dlx htmldocs@latest init ``` ```bash bun theme={null} bunx htmldocs@latest init ``` ## `login` Authenticates the CLI with the cloud. This allows you to publish your documents to the cloud. ```bash npm theme={null} npx htmldocs@latest login ``` ```bash pnpm theme={null} pnpx htmldocs@latest login ``` ```bash yarn theme={null} yarn dlx htmldocs@latest login ``` ```bash bun theme={null} bunx htmldocs@latest login ``` ## `dev` Starts a local development server that will watch your files and automatically rebuild your document template when you make changes. Login not required. ```bash npm theme={null} npx htmldocs@latest dev ``` ```bash pnpm theme={null} pnpx htmldocs@latest dev ``` ```bash yarn theme={null} yarn dlx htmldocs@latest dev ``` ```bash bun theme={null} bunx htmldocs@latest dev ``` **Options** Change the directory of your document templates. Port to run dev server on ## `publish ` Publishes the document to the cloud for API use. Must be [authenticated](/cli#login). Be sure to run this from the root of your project. ```bash npm theme={null} npx htmldocs@latest publish ``` ```bash pnpm theme={null} pnpx htmldocs@latest publish ``` ```bash yarn theme={null} yarn dlx htmldocs@latest publish ``` ```bash bun theme={null} bunx htmldocs@latest publish ``` **Options** The file path of the document to publish. ## `--help` Shows all available commands and options. ```bash npm theme={null} npx htmldocs@latest --help ``` ```bash pnpm theme={null} pnpx htmldocs@latest --help ``` ```bash yarn theme={null} yarn dlx htmldocs@latest --help ``` ```bash bun theme={null} bunx htmldocs@latest --help ``` **Options** Enable verbose logging **F.A.Q** You can define preview props for your document by adding a `PreviewProps` property to your default export. For example: ```jsx theme={null} export default function Document(props) { return (

{props.title}

{props.content}

); } Document.PreviewProps = { title: "Preview Title", content: "This is preview content", }; ``` These props will be used when previewing the document in the development server.
To publish documents, you need to authenticate with the cloud service. Use the `htmldocs login` command to start the authentication process. This will open a browser window where you can select a team and complete the authentication. Once authenticated, your tokens will be securely stored for future use. By default, built files are stored in a `dist` directory in your project root. You can customize this location by setting the `NEXT_PUBLIC_USER_PROJECT_LOCATION` environment variable.
# Comparing htmldocs Source: https://docs.htmldocs.com/comparison See how htmldocs compares to other document creation solutions | Feature | Traditional Documents
(Word, Google Docs) | LaTeX Documents
(Overleaf, TeXStudio) | Freeform Documents
(Figma, Sketch) | Web Documents
(htmldocs) | | -------------------- | :--------------------------------------------: | :----------------------------------------: | :-------------------------------------: | :---------------------------: | | Content Structure | Semi-Structured | Highly Structured | Freeform | Highly Structured | | Learning Curve | ✅ Simple | ❌ Complex | ✅ Simple | ✅ Simple | | Template Variables | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported | | Styling | ✅ Basic | ❌ Complex | ✅ Advanced | ✅ Advanced | | Version Control | ❌ Limited | ✅ Supported | ❌ Limited | ✅ Supported | | Document Consistency | ❌ Limited | ✅ Supported | ✅ Supported | ✅ Supported | | External Libraries | ❌ Limited | ✅ Supported | ❌ Limited | ✅ Supported | | Automation / API | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported | | Developer Plugins | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported | | Live Preview | ✅ Supported | ❌ Limited | ✅ Supported | ✅ Supported | | CI/CD Integration | ❌ Limited | ⚠️ Partial | ❌ Limited | ✅ Supported | | Type Safety | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported | | AI Integrations | ❌ Limited | ❌ Limited | ❌ Limited | ✅ Supported | ## When to Choose htmldocs htmldocs is the ideal choice when you need: * **Programmatic Generation**: Create documents dynamically using data and code * **Consistent Branding**: Maintain uniform styling across all documents through components * **Modern Development**: Leverage React, TypeScript, and the npm ecosystem * **CI/CD**: Push new document versions with CI/CD pipelines * **Version Control**: Track changes and collaborate using Git * **Developer-First**: Use familiar tools and workflows in a code-first environment * **Integrated AI Workflow**: Generate document content seamlessly with AI tools like Cursor/Copilot * **Structured Documents**: Create structured documents with precise typesetting and predictable layouts While traditional tools like Word or LaTeX have their place, htmldocs brings document creation into the modern web development ecosystem, offering powerful features for teams that need more than just basic word processing. # Document Source: https://docs.htmldocs.com/components/document A component for creating document layouts The `Document` component is used to create a layout for document pages. It provides a structured way to set the size, orientation, and margin of the document. ## Usage ```jsx Document Example theme={null} import Document from './Document'; const MyDocument = () => (

My Document Content

This is the content of my document.

); ```
## Props The size of the document. Must be one of: "A3", "A4", "A5", "letter", or "legal". The orientation of the document. Must be either "portrait" or "landscape". The margin of the document. Can be a string (e.g., "0.39in") or a valid CSS margin value. The content of the document. ## Examples ### A4 Portrait Document ```jsx A4 Portrait theme={null} import Document from './Document'; const A4Portrait = () => (

A4 Portrait Document

This is an A4 portrait document with 1 inch margins.

); ```
### Legal Landscape Document ```jsx Legal Landscape theme={null} import Document from './Document'; const LegalLandscape = () => (

Legal Landscape Document

This is a legal size landscape document with 0.5 inch margins.

); ```
# Footer Source: https://docs.htmldocs.com/components/footer Add page numbers and custom footers to your documents The `Footer` component provides an easy way to add page numbers and custom footers to your documents. It's built on top of the [MarginBox](/components/margin-box) component with additional features for page numbering. ## Usage ```jsx Basic Example theme={null} import { Footer } from "@htmldocs/react"; export default function Document() { return (