Skip to content

Generate a Presentation from a PDF

This guide demonstrates how to use the SlideSpeak 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/v1';
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
});
const result = await response.json();
return result;
}
{
"task_id": "353509d6-8efe-401c-a8a9-53ca64b520a3"
}

After uploading, poll the document processing task using the task_id until the status is SUCCESS.

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;
} else if (result.task_status === 'FAILED') {
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",
"task_info": "e1f3ea4d-39f0-45e4-9cce-044ec63f8a5b"
}

Step 3: Generate a Presentation from the Document

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

Once the document is processed, use the document to generate a presentation.

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({
document_uuids: [documentId],
length: 15,
template: "default",
language: "ORIGINAL",
fetch_images: true,
tone: "professional",
verbosity: "concise",
custom_user_instructions: "Make sure to include a thank you slide at the end.",
use_branded_logo: true
})
});
const result = await response.json();
return result;
}
{
"task_id": "f0db8d6c-6378-4df4-8585-ec3c434b2614"
}

Step 4: Poll the Presentation Generation Task

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

Here we can reuse the pollTask function from above.

const presResult = await pollTask(genResult.task_id);
{
"task_id": "f0db8d6c-6378-4df4-8585-ec3c434b2614",
"task_status": "SUCCESS",
"task_result": {
"url": "https://slidespeak-files.s3.us-east-2.amazonaws.com/24d89111-71a1-4c05-a909-2d84123c9ba9.pptx"
},
"task_info": {
"url": "https://slidespeak-files.s3.us-east-2.amazonaws.com/24d89111-71a1-4c05-a909-2d84123c9ba9.pptx"
}
}

Once the presentation is ready, download it using the download_url from the previous step.

async function downloadPresentation(downloadUrl, filename = 'presentation.pptx') {
const response = await fetch(downloadUrl);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}

async function handlePDFUpload(file) {
try {
// Step 1: Upload
const uploadTask = await uploadPDF(file);
console.log('Uploaded Task:', uploadTask);
// Step 2: Poll document processing
const uploadResult = await pollTask(uploadTask.task_id);
console.log('Document uploaded:', uploadResult);
// Step 3: Generate presentation
const genTask = await generatePresentation(uploadResult.task_result);
console.log('Presentation generation started:', genTask);
// Step 4: Poll presentation generation
const presResult = await pollTask(genTask.task_id);
console.log('Presentation ready:', presResult.task_result.url);
// Step 5: Download
await downloadPresentation(presResult.task_result.url);
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.