Skip to content

Generate pdf from templateID and name

saiverma requested to merge vectorvarma0303/pdfprocessor:main into main

Modified API Design

Request:

POST /generate-certificate?template_id=event123&name=Rebel%20Star
  • template_id: Refers to a stored SVG template file (e.g., event123.svg)
  • name: The student's name to be inserted into the template

🛠️ Steps to Implement

1. Organize Templates

Store your certificate SVG templates in a known folder, e.g., ./templates/.

Example files:

./templates/event123.svg
./templates/event_sports.svg
./templates/hackathon2025.svg

2. Update API Handler

Replace the convertSVGToPDF logic with:

  • Load the SVG file from disk based on template_id
  • Replace a placeholder (e.g., {{NAME}}) in the SVG with the student's name
  • Convert the final SVG to PDF as before

3. SVG Template Placeholder

Your templates should contain a placeholder for the name, like:

<text x="100" y="200" font-size="24" fill="#000">{{NAME}}</text>

🧪 Test Example

curl -X POST "http://localhost:8080/generate-certificate?template_id=event123&name=Rebel%20Star" \
  -o certificate.pdf
Edited by saiverma

Merge request reports

Loading