Skip to content

Generate a Presentation from a PDF

This guide demonstrates how to use the SlideSpeak v2 API to generate a presentation from a PDF document, using only JavaScript. The process is broken down into clear, numbered steps.

Upload your PDF file to SlideSpeak. This returns a task_id for tracking processing status.

const API_KEY = 'your-api-key';
const API_BASE = 'https://api.slidespeak.co/api/v2';
async function uploadPDF(file) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch(`${API_BASE}/document/upload`, {
method: 'POST',
headers: { 'X-API-Key': API_KEY },
body: formData
});
return response.json();
}
{
"task_id": "353509d6-8efe-401c-a8a9-53ca64b520a3"
}

After uploading, poll the task using the task_id until the status is SUCCESS. The task_result holds the document ID to use for generation.

async function pollTask(taskId) {
const response = await fetch(`${API_BASE}/task_status/${taskId}`, {
headers: { 'X-API-Key': API_KEY, 'Content-Type': 'application/json' }
});
const result = await response.json();
if (result.task_status === 'SUCCESS') return result;
if (result.task_status === 'FAILURE') throw new Error('Task failed');
await new Promise(res => setTimeout(res, 2000)); // Wait 2 seconds
return pollTask(taskId); // Recursive call
}
{
"task_id": "353509d6-8efe-401c-a8a9-53ca64b520a3",
"task_status": "SUCCESS",
"task_result": "e1f3ea4d-39f0-45e4-9cce-044ec63f8a5b"
}

Step 3: Generate a Presentation from the Document

Section titled “Step 3: Generate a Presentation from the Document”

Generate a presentation with a prompt, the uploaded document_ids, and optional settings such as a design_kit_id (see Design Kits).

async function generatePresentation(documentId) {
const response = await fetch(`${API_BASE}/presentation/generate`, {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'Summarize the attached document into a concise deck.',
document_ids: [documentId],
settings: {
design_kit_id: 'dk_acme',
length: 15,
language: 'ORIGINAL',
tone: 'professional',
verbosity: 'concise'
}
})
});
return response.json();
}
{
"task_id": "f0db8d6c-6378-4df4-8585-ec3c434b2614"
}

Step 4: Poll the Presentation Generation Task

Section titled “Step 4: Poll the Presentation Generation Task”

Reuse the pollTask function from above. When generation succeeds, the response includes a request_id used to download the file.

const presResult = await pollTask(genTask.task_id);
{
"task_id": "f0db8d6c-6378-4df4-8585-ec3c434b2614",
"task_status": "SUCCESS",
"request_id": "cr5abc123..."
}

Exchange the request_id for a short-lived download URL, then download the PowerPoint file.

async function downloadPresentation(requestId, filename = 'presentation.pptx') {
const res = await fetch(`${API_BASE}/presentation/download/${requestId}`, {
headers: { 'X-API-Key': API_KEY }
});
const { url } = await res.json();
const fileResponse = await fetch(url);
const blob = await fileResponse.blob();
const objectUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = objectUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(objectUrl);
}

async function handlePDFUpload(file) {
try {
// Step 1: Upload
const uploadTask = await uploadPDF(file);
// Step 2: Poll document processing
const uploadResult = await pollTask(uploadTask.task_id);
// Step 3: Generate presentation
const genTask = await generatePresentation(uploadResult.task_result);
// Step 4: Poll presentation generation
const presResult = await pollTask(genTask.task_id);
// Step 5: Download
await downloadPresentation(presResult.request_id);
console.log('Download started');
} catch (err) {
console.error('Error:', err);
}
}

  • All API requests require your X-API-Key header.
  • The process is asynchronous: always poll the task_id for status.
  • Each API call consumes credits based on the number of slides generated.