40 lines
812 B
Go
40 lines
812 B
Go
|
package pdf
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log/slog"
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"path/filepath"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// Generate generates the CV PDF document from the JSON file.
|
||
|
func Generate(tempDir, input string, historyLimit time.Time, verbose bool) (string, error) {
|
||
|
texFileName, err := tex(input, tempDir, historyLimit)
|
||
|
if err != nil {
|
||
|
return "", fmt.Errorf("unable to create the tex file; %w", err)
|
||
|
}
|
||
|
|
||
|
slog.Info("Creating the PDF document.")
|
||
|
|
||
|
pathArg := "--path=" + tempDir
|
||
|
|
||
|
command := exec.Command("mtxrun", pathArg, "--script", "context", texFileName)
|
||
|
|
||
|
if verbose {
|
||
|
command.Stderr = os.Stderr
|
||
|
command.Stdout = os.Stdout
|
||
|
}
|
||
|
|
||
|
if err := command.Run(); err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
output := filepath.Join(tempDir, "cv.pdf")
|
||
|
|
||
|
slog.Info("PDF document successfully created.", "filename", output)
|
||
|
|
||
|
return output, nil
|
||
|
}
|