Created
May 27, 2024 04:29
-
-
Save RolandWarburton/b2cbd15d0173e1250fd1e6f637a469f8 to your computer and use it in GitHub Desktop.
bulk generate PDF files for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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