Génère un document PDF à partir de contenu HTML. Le HTML peut inclure des styles inline
ou dans une balise <style>. CSS additionnel peut être fourni via le paramètre css.
En cas de succès, l'API retourne le fichier PDF binaire avec le header Content-Type: application/pdf.
En cas d'erreur, elle retourne un JSON avec un objet error.
curl -X POST https://web2print.studio-variable.com/generate \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"html": "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><style>@page { size: A4; margin: 2cm; } body { font-family: Arial; } h1 { color: #333; }</style></head><body><h1>Mon Document</h1><p>Contenu du document.</p></body></html>"
}' \
--output document.pdf
const response = await fetch('https://web2print.studio-variable.com/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({
html: `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
@page { size: A4; margin: 2cm; }
body { font-family: Arial; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Mon Document</h1>
<p>Contenu du document.</p>
</body>
</html>`
})
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'document.pdf';
a.click();
} else {
const error = await response.json();
console.error('Erreur:', error);
}
import requests
url = 'https://web2print.studio-variable.com/generate'
headers = {
'Content-Type': 'application/json',
'X-API-Key': 'YOUR_API_KEY'
}
data = {
'html': '''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
@page { size: A4; margin: 2cm; }
body { font-family: Arial; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Mon Document</h1>
<p>Contenu du document.</p>
</body>
</html>'''
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
with open('document.pdf', 'wb') as f:
f.write(response.content)
print('PDF généré avec succès')
else:
print('Erreur:', response.json())
$ch = curl_init('https://web2print.studio-variable.com/generate');
$html = '<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
@page { size: A4; margin: 2cm; }
body { font-family: Arial; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Mon Document</h1>
<p>Contenu du document.</p>
</body>
</html>';
$data = json_encode(['html' => $html]);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: YOUR_API_KEY'
],
CURLOPT_POSTFIELDS => $data
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
file_put_contents('document.pdf', $response);
echo 'PDF généré avec succès';
} else {
$error = json_decode($response, true);
echo 'Erreur: ' . $error['error'];
}