Skip to content

Commit 6388a3f

Browse files
committed
feat: expose simple API to generate PDFs
1 parent 6ec4109 commit 6388a3f

File tree

18 files changed

+213
-26
lines changed

18 files changed

+213
-26
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/rwxrob/bonzai v0.56.6
77
github.com/rwxrob/bonzai/cmds/help v0.8.2
88
github.com/rwxrob/bonzai/comp v0.10.0
9+
github.com/rwxrob/bonzai/futil v0.4.0
910
github.com/rwxrob/bonzai/persisters/inyaml v0.3.0
1011
github.com/rwxrob/bonzai/vars v0.12.0
1112
gopkg.in/yaml.v3 v3.0.1
@@ -31,7 +32,6 @@ require (
3132
github.com/rwxrob/bonzai/ds v0.1.1 // indirect
3233
github.com/rwxrob/bonzai/edit v0.1.1 // indirect
3334
github.com/rwxrob/bonzai/fn v0.9.0 // indirect
34-
github.com/rwxrob/bonzai/futil v0.4.0 // indirect
3535
github.com/rwxrob/bonzai/is v0.3.0 // indirect
3636
github.com/rwxrob/bonzai/mark v0.12.0 // indirect
3737
github.com/rwxrob/bonzai/mark/funcs v0.8.6 // indirect

internal/autopdf/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ package autopdf
77
import (
88
"fmt"
99

10-
"github.com/BuddhiLW/AutoPDF/internal/config"
1110
"github.com/BuddhiLW/AutoPDF/internal/converter"
1211
"github.com/BuddhiLW/AutoPDF/internal/tex"
12+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1313
"github.com/rwxrob/bonzai"
1414
"github.com/rwxrob/bonzai/cmds/help"
1515
"github.com/rwxrob/bonzai/comp"

internal/converter/converter.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"os/exec"
88
"path/filepath"
99
"strings"
10-
11-
"github.com/BuddhiLW/AutoPDF/internal/config"
10+
11+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1212
)
1313

1414
// Converter handles PDF to image conversion
@@ -53,18 +53,18 @@ func (c *Converter) ConvertPDFToImages(pdfFile string) ([]string, error) {
5353
// ImageMagick approach
5454
for _, format := range formats {
5555
outputPath := filepath.Join(dir, fmt.Sprintf("%s.%s", baseName, format))
56-
cmd := exec.Command("convert",
57-
"-density", "300",
58-
pdfFile,
56+
cmd := exec.Command("convert",
57+
"-density", "300",
58+
pdfFile,
5959
outputPath)
60-
60+
6161
if err := cmd.Run(); err != nil {
6262
return outputFiles, fmt.Errorf("image conversion failed for %s: %w", format, err)
6363
}
64-
64+
6565
outputFiles = append(outputFiles, outputPath)
6666
}
67-
67+
6868
return outputFiles, nil
6969
}
7070

@@ -75,7 +75,7 @@ func (c *Converter) ConvertPDFToImages(pdfFile string) ([]string, error) {
7575
// pdftoppm has specific flags for different formats
7676
var outputPrefix string
7777
var args []string
78-
78+
7979
switch format {
8080
case "png":
8181
outputPrefix = filepath.Join(dir, baseName)
@@ -86,20 +86,20 @@ func (c *Converter) ConvertPDFToImages(pdfFile string) ([]string, error) {
8686
default:
8787
continue // Skip unsupported formats
8888
}
89-
89+
9090
cmd := exec.Command("pdftoppm", args...)
91-
91+
9292
if err := cmd.Run(); err != nil {
9393
return outputFiles, fmt.Errorf("image conversion failed for %s: %w", format, err)
9494
}
95-
95+
9696
// pdftoppm adds numeric suffixes to outputs for multi-page documents
9797
// For simplicity, we'll just note the base name
9898
outputFiles = append(outputFiles, fmt.Sprintf("%s-*.%s", outputPrefix, format))
9999
}
100-
100+
101101
return outputFiles, nil
102102
}
103103

104104
return nil, errors.New("no suitable conversion tool found (tried 'convert' and 'pdftoppm')")
105-
}
105+
}

internal/converter/converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"testing"
1010

11-
"github.com/BuddhiLW/AutoPDF/internal/config"
11+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1212
)
1313

1414
func TestNewConverter(t *testing.T) {

internal/template/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"text/template"
88

9-
"github.com/BuddhiLW/AutoPDF/internal/config"
9+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1010
)
1111

1212
// Engine represents the template processing engine

internal/template/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"testing"
1010

11-
"github.com/BuddhiLW/AutoPDF/internal/config"
11+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1212
)
1313

1414
// TestProcess creates a temporary LaTeX template with custom delimiters, processes

internal/tex/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"path/filepath"
88

99
"github.com/BuddhiLW/AutoPDF/configs"
10-
"github.com/BuddhiLW/AutoPDF/internal/config"
1110
"github.com/BuddhiLW/AutoPDF/internal/converter"
1211
"github.com/BuddhiLW/AutoPDF/internal/template"
12+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1313
"github.com/rwxrob/bonzai"
1414
"github.com/rwxrob/bonzai/cmds/help"
1515
"github.com/rwxrob/bonzai/comp"

internal/tex/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/BuddhiLW/AutoPDF/configs"
15-
"github.com/BuddhiLW/AutoPDF/internal/config"
15+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1616
"github.com/rwxrob/bonzai"
1717
"github.com/rwxrob/bonzai/futil"
1818
)

internal/tex/compile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77
"testing"
88

9-
"github.com/BuddhiLW/AutoPDF/internal/config"
9+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1010
)
1111

1212
func TestReplaceExt(t *testing.T) {

internal/tex/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77

88
"github.com/BuddhiLW/AutoPDF/configs"
9-
"github.com/BuddhiLW/AutoPDF/internal/config"
9+
"github.com/BuddhiLW/AutoPDF/pkg/config"
1010
)
1111

1212
func Default(texFilePath string) error {

0 commit comments

Comments
 (0)