Nim + FastAPI experiment
dev.to·19h·
Discuss: DEV
🤖Archive Automation
Preview
Report Post

Why use one language when you can use two?

I’ve been experimenting with FastAPI and Nim lately, and I decided to bridge them together to build a simple PDF merger.

The goal? Offload the possible heavy binary lifting of PDF generation to Nim (which compiles to C) while keeping the web layer comfy with Python.

Nim process:

import nimpdf
import nimpdf/image
import os

proc makePDF(outputPath: string, files: seq[string]): bool =
let factorX = 20.0
let factorY = 200.0
var pdf = newPDF()

for file in files:
discard pdf.addPage("A4")
let img = loadImage(file)
if img == nil:
echo "Warning: Could not load ", file
continue
pdf.drawImage(factorX, factorY, img)

return pdf.writePDF(outputPath)

when isMainModule:
if paramCount() < 2:
quit "Usage: pdf_merger <output.pdf> <images....

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help