Dan Anglin
c53978cd91
- feat: add a field for the type of work location (e.g. hybrid) - refactor: move the Tex and PDF generating code to a new internal package which also moves the templates there as well. - fix: add a default value for the --output field for the generate command. - fix: add an error for when the user does not specify an input file when generating the PDF. - fix: the package name for each of the files in the templateFuncs package.
39 lines
812 B
Go
39 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
|
|
}
|