Skip to content

Instantly share code, notes, and snippets.

@RolandWarburton
Created May 27, 2024 04:29
Show Gist options
  • Save RolandWarburton/b2cbd15d0173e1250fd1e6f637a469f8 to your computer and use it in GitHub Desktop.
Save RolandWarburton/b2cbd15d0173e1250fd1e6f637a469f8 to your computer and use it in GitHub Desktop.
bulk generate PDF files for testing
package main
import (
"fmt"
"os"
"sync"
"github.com/go-pdf/fpdf"
)
func main() {
os.Mkdir("output", os.FileMode(0755))
var wg sync.WaitGroup
for i := 0; i < 300; i++ {
wg.Add(1)
go func(index int) {
defer wg.Done()
pdf := fpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
content := fmt.Sprintf("Document #%d", index+1)
pdf.Cell(40, 10, content)
err := pdf.OutputFileAndClose(fmt.Sprintf("./output/document-%d.pdf", index+1))
if err != nil {
fmt.Printf("failed to generate PDF %d\n", index)
os.Exit(1)
}
fmt.Printf("created document %d\n", index)
}(i)
}
wg.Wait()
fmt.Println("created all the PDFs")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment