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.9 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { iloveapiAuth } from '../common/auth';
import { iloveSchemas } from '../common/schemas';
import { fileToUploadInput, regionOf, sharedProps, webhookOf } from '../common/props';
import { runAndStoreResult } from '../common/runner';

export const pdfToJpgAction = createAction({
  auth: iloveapiAuth,
  name: 'pdf_to_jpg',
  classification: 'READ',
  displayName: 'PDF to JPG',
  description:
    'Convert PDF pages to JPG images, or extract images embedded in the PDF.',
  audience: 'both',
  outputSchema: iloveSchemas.toolResult,
  aiMetadata: {
    description:
      'Turn a PDF into JPG images. Choose the "pages" mode to render each page as a full JPG, or the "extract" mode to pull out only the raster images already embedded inside the PDF. Each run produces a new converted output, so re-running creates a fresh result rather than reusing a prior one.',
    idempotent: false,
  },
  props: {
    file: Property.File({
      displayName: 'PDF File',
      required: true,
    }),
    pdfjpg_mode: Property.StaticDropdown({
      displayName: 'Mode',
      required: false,
      defaultValue: 'pages',
      options: {
        disabled: false,
        options: [
          { label: 'Render each page as a JPG', value: 'pages' },
          { label: 'Extract embedded images', value: 'extract' },
        ],
      },
    }),
    ...sharedProps,
  },
  async run(context) {
    const { file, pdfjpg_mode, output_filename, packaged_filename } =
      context.propsValue;

    return await runAndStoreResult({
      auth: context.auth.secret_text,
      region: regionOf(context.propsValue.region),
      webhook: webhookOf(context.propsValue.webhook_url),
      files: context.files,
      tool: 'pdfjpg',
      uploads: [fileToUploadInput({ file: file })],
      options: {
        pdfjpg_mode: pdfjpg_mode ?? 'pages',
      },
      output_filename,
      packaged_filename,
    });
  },
});