summaryrefslogtreecommitdiff
path: root/internal/comic/pdf.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/comic/pdf.go')
-rw-r--r--internal/comic/pdf.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/comic/pdf.go b/internal/comic/pdf.go
new file mode 100644
index 0000000..23a7e11
--- /dev/null
+++ b/internal/comic/pdf.go
@@ -0,0 +1,30 @@
+package comic
+
+import (
+ "fmt"
+ "os/exec"
+ "path/filepath"
+ "strings"
+)
+
+// AssembleComicPDF combines comic pages into a PDF using ImageMagick.
+func AssembleComicPDF(outputDir, titleSlug string, imagePaths []string) (string, error) {
+ if len(imagePaths) == 0 {
+ return "", fmt.Errorf("no comic images to assemble into PDF")
+ }
+ if _, err := exec.LookPath("convert"); err != nil {
+ return "", fmt.Errorf("ImageMagick 'convert' not found — install ImageMagick to generate the PDF")
+ }
+
+ pdfPath := filepath.Join(outputDir, titleSlug+".pdf")
+ args := []string{"-density", "150"}
+ args = append(args, imagePaths...)
+ args = append(args, pdfPath)
+
+ cmd := exec.Command("convert", args...)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ return "", fmt.Errorf("convert failed: %w\n%s", err, strings.TrimSpace(string(out)))
+ }
+ return pdfPath, nil
+}