Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { filetopdfAuth } from '../common/auth';
import { filetopdfApiCall } from '../common/client';
import { CHROMIUM_OPTION_PROPS } from '../common/props';
import {
  stringifyOptions,
  buildConversionOutput,
  PdfJsonEnvelope,
} from '../common/conversion';

export const convertHtml = createAction({
  auth: filetopdfAuth,
  name: 'convert_html',
  classification: 'READ',
  displayName: 'Convert HTML',
  description: 'Render a raw HTML string (with optional CSS) to PDF using Chromium.',
  audience: 'both',
  aiMetadata: {
    description:
      'Renders a raw HTML string (with optional injected CSS) to PDF via Chromium. Choose this when the agent holds HTML markup it generated or assembled in memory, rather than a file or URL. Requires the HTML content as input. Not idempotent: each call performs a fresh remote render on the FileToPDF service that produces a new file and consumes account credits.',
    idempotent: false,
  },
  props: {
    html: Property.LongText({
      displayName: 'HTML',
      description: 'The HTML markup to render.',
      required: true,
    }),
    css: Property.LongText({
      displayName: 'CSS',
      description: 'Optional CSS, injected into the document head.',
      required: false,
    }),
    ...CHROMIUM_OPTION_PROPS,
  },
  async run(context) {
    const { html, css, ...rawOptions } = context.propsValue;
    const options = stringifyOptions(rawOptions);
    const body: Record<string, unknown> = { html, ...options };
    if (css) body['css'] = css;

    const envelope = await filetopdfApiCall<PdfJsonEnvelope>({
      apiKey: context.auth.secret_text,
      method: HttpMethod.POST,
      resourceUri: '/html',
      body,
    });

    return buildConversionOutput(context.files, envelope);
  },
});