Export PDF, Image & ZIP

Generate high-fidelity PDFs, images, and ZIP archives from the current design. All three use server-side headless Chromium rendering.

React
tsx


function ExportDemo() {
  const editorRef = useRef<DragbleEditorRef>(null);

  const handleExportImage = async () => {
    const result = await editorRef.current?.editor?.exportImage({
      format: "png",
      width: 640,
      fullPage: true,
    });
    if (result?.imageData) {
      // imageData is a base64 data-URL: "data:image/png;base64,..."
      window.open(result.imageData);
    }
  };

  const handleExportPdf = async () => {
    const result = await editorRef.current?.editor?.exportPdf({
      pageSize: "a4",
      orientation: "portrait",
    });
    if (result?.pdfData) {
      const a = document.createElement("a");
      a.href = result.pdfData;
      a.download = "template.pdf";
      a.click();
    }
  };

  const handleExportZip = async () => {
    const result = await editorRef.current?.editor?.exportZip({
      imageFolder: "images",
    });
    if (result?.zipData) {
      const a = document.createElement("a");
      a.href = result.zipData;
      a.download = "template.zip";
      a.click();
    }
  };

  return (
    <>
      <DragbleEditor
        ref={editorRef}
        editorKey="db_your_key"
        editorMode="email"
      />
      <button onClick={handleExportImage}>Export Image</button>
      <button onClick={handleExportPdf}>Export PDF</button>
      <button onClick={handleExportZip}>Export ZIP</button>
    </>
  );
}
Vue
plaintext
<template>
  <DragbleEditor ref="editorRef" editor-key="db_your_key" editor-mode="email" />
  <button @click="handleExportImage">Export Image</button>
  <button @click="handleExportPdf">Export PDF</button>
  <button @click="handleExportZip">Export ZIP</button>
</template>

<script setup lang="ts">


const editorRef = ref<InstanceType<typeof DragbleEditor>>();

async function handleExportImage() {
  const result = await editorRef.value?.exportImage({
    format: "png",
    width: 640,
    fullPage: true,
  });
  if (result?.imageData) {
    window.open(result.imageData);
  }
}

async function handleExportPdf() {
  const result = await editorRef.value?.exportPdf({
    pageSize: "a4",
    orientation: "portrait",
  });
  if (result?.pdfData) {
    const a = document.createElement("a");
    a.href = result.pdfData;
    a.download = "template.pdf";
    a.click();
  }
}

async function handleExportZip() {
  const result = await editorRef.value?.exportZip({ imageFolder: "images" });
  if (result?.zipData) {
    const a = document.createElement("a");
    a.href = result.zipData;
    a.download = "template.zip";
    a.click();
  }
}
</script>
Angular
typescript



@Component({
  selector: "app-export-demo",
  standalone: true,
  imports: [DragbleEditorComponent],
  template: `
    <dragble-editor
      #editor
      editorKey="db_your_key"
      editorMode="email"
      (ready)="onReady($event)"
    ></dragble-editor>
    <button (click)="handleExportImage()">Export Image</button>
    <button (click)="handleExportPdf()">Export PDF</button>
    <button (click)="handleExportZip()">Export ZIP</button>
  `,
})
export class ExportDemoComponent {
  @ViewChild("editor") editorComp!: DragbleEditorComponent;
  private sdk: DragbleSDK | null = null;

  onReady(sdk: DragbleSDK) {
    this.sdk = sdk;
  }

  async handleExportImage() {
    const result = await this.sdk?.exportImage({
      format: "png",
      width: 640,
      fullPage: true,
    });
    if (result?.imageData) {
      window.open(result.imageData);
    }
  }

  async handleExportPdf() {
    const result = await this.sdk?.exportPdf({
      pageSize: "a4",
      orientation: "portrait",
    });
    if (result?.pdfData) {
      const a = document.createElement("a");
      a.href = result.pdfData;
      a.download = "template.pdf";
      a.click();
    }
  }

  async handleExportZip() {
    const result = await this.sdk?.exportZip({ imageFolder: "images" });
    if (result?.zipData) {
      const a = document.createElement("a");
      a.href = result.zipData;
      a.download = "template.zip";
      a.click();
    }
  }
}
Vanilla JS
typescript
// Export as PNG
const imageResult = await dragble.exportImage({
  format: "png",
  width: 640,
  fullPage: true,
});
if (imageResult.imageData) {
  window.open(imageResult.imageData);
}

// Export as PDF
const pdfResult = await dragble.exportPdf({
  pageSize: "a4",
  orientation: "portrait",
});
if (pdfResult.pdfData) {
  const a = document.createElement("a");
  a.href = pdfResult.pdfData;
  a.download = "template.pdf";
  a.click();
}

// Export as ZIP
const zipResult = await dragble.exportZip({ imageFolder: "images" });
if (zipResult.zipData) {
  const a = document.createElement("a");
  a.href = zipResult.zipData;
  a.download = "template.zip";
  a.click();
}
Server-side rendering

These exports are rendered server-side by Dragble using headless Chromium. They are not available in popup editor mode. Use exportHtml() instead for popups.

Image export options

typescript
const result = await editor.exportImage({
  format: "png", // 'png' | 'jpg'
  width: 640, // Output width in pixels (100–2000, default 640)
  height: null, // Viewport height, null = auto (default null)
  fullPage: true, // Capture full scrollable page (default true)
  quality: 90, // JPEG quality 1–100, ignored for PNG (default 90)
  deviceScaleFactor: 2, // 1–3, use 2 for retina (default 1)
  saveToStorage: false, // true = upload and return URL, false = base64 data-URL
  mergeTags: {
    // Replace merge tags before rendering
    first_name: "Jane",
  },
});
OptionTypeDefaultDescription
format'png' | 'jpg''png'Output image format
widthnumber640Output width in pixels (100–2000)
heightnumber | nullnullViewport height. null = auto-height
fullPagebooleantrueCapture full scrollable page vs viewport only
qualitynumber90JPEG quality (1–100). Ignored for PNG
deviceScaleFactornumber1Scale factor (1–3). Use 2 for retina displays
saveToStoragebooleanfalseUpload to Dragble storage and return a hosted URL
mergeTagsRecord<string, string>undefinedMerge tag replacements applied before rendering

Return value (ExportImageData):

  • imageData — base64 data-URL when saveToStorage is false (default)
  • url — hosted URL when saveToStorage is true
  • design — the design JSON at the time of export

PDF export options

typescript
const result = await editor.exportPdf({
  pageSize: "a4", // 'full' | 'letter' | 'a4' | 'a3'
  orientation: "portrait", // 'portrait' | 'landscape' (ignored for 'full')
  printBackground: true, // Include CSS backgrounds (default true)
  margin: {
    // Page margins in CSS units
    top: "10mm",
    right: "10mm",
    bottom: "10mm",
    left: "10mm",
  },
  width: 768, // Viewport width in CSS pixels (default 768)
  saveToStorage: false, // true = upload and return URL
  mergeTags: {
    // Replace merge tags before rendering
    company: "Acme Inc.",
  },
});
OptionTypeDefaultDescription
pageSize'full' | 'letter' | 'a4' | 'a3''full'Page size preset. 'full' = single continuous page
orientation'portrait' | 'landscape''portrait'Page orientation. Ignored when pageSize is 'full'
printBackgroundbooleantrueInclude CSS background colors and images
margin{ top?, right?, bottom?, left? }undefinedPage margins in CSS units (e.g. '10mm')
widthnumber768Viewport width in CSS pixels
saveToStoragebooleanfalseUpload to Dragble storage and return a hosted URL
mergeTagsRecord<string, string>undefinedMerge tag replacements applied before rendering

Return value (ExportPdfData):

  • pdfData — base64 data-URL when saveToStorage is false (default)
  • url — hosted URL when saveToStorage is true
  • design — the design JSON at the time of export

ZIP export options

The ZIP archive bundles the HTML template with all referenced images downloaded locally.

typescript
const result = await editor.exportZip({
  imageFolder: "images", // Folder name inside ZIP for images (default 'images')
});
OptionTypeDefaultDescription
imageFolderstring'images'Folder name for images inside the ZIP archive

Return value (ExportZipData):

  • zipData — base64 data-URL of the ZIP archive
  • design — the design JSON at the time of export

Save exports to Dragble storage

Set saveToStorage: true on image and PDF exports to upload the result to Dragble's managed storage. The return value will include a url field with the hosted URL instead of a base64 data-URL:

typescript
const result = await editor.exportImage({
  format: "png",
  saveToStorage: true,
});

console.log(result.url);
// "https://assets.dragble.com/exports/abc123.png"

Method reference

MethodReturnsDescription
exportImage(options?)Promise<ExportImageData>Export as PNG or JPG image (server-side rendered)
exportPdf(options?)Promise<ExportPdfData>Export as PDF document (server-side rendered)
exportZip(options?)Promise<ExportZipData>Export as ZIP with HTML + images

Next steps