feat (generate-file): control letter done

This commit is contained in:
dpurbosakti
2025-11-20 13:18:33 +07:00
parent a5ea881e1f
commit ffb8c4e413
5 changed files with 185 additions and 145 deletions
+16 -3
View File
@@ -47,9 +47,9 @@ func (r *RequestPdf) ParseTemplate(templatePath string, data interface{}) error
return nil
}
func (r *RequestPdf) GenerateByCommand(pdfPath string, templatePath string) (bool, error) {
// wkhtmltopdf -L 0 -R 0 -B 0 -s Legal --enable-local-file-access resultAntigen2.html out.pdf
func (r *RequestPdf) GenerateByCommand(pdfPath string, templatePath string, useA5Lanscape bool) (bool, error) {
t := time.Now().Unix()
var cmd *exec.Cmd
if _, err := os.Stat("cloneTemplate/"); os.IsNotExist(err) {
errDir := os.Mkdir("cloneTemplate/", 0777)
@@ -63,7 +63,20 @@ func (r *RequestPdf) GenerateByCommand(pdfPath string, templatePath string) (boo
panic(err)
}
cmd := exec.Command("wkhtmltopdf", "--enable-local-file-access", "-L", "0", "-R", "0", "-B", "0", "-s", "A4", "cloneTemplate/"+htmlName, pdfPath)
if !useA5Lanscape {
cmd = exec.Command("wkhtmltopdf", "--enable-local-file-access", "-L", "0", "-R", "0", "-B", "0", "-s", "A4", "cloneTemplate/"+htmlName, pdfPath)
} else {
cmd = exec.Command("wkhtmltopdf",
"--enable-local-file-access",
"-L", "0", // left margin
"-R", "0", // right margin
"-B", "0", // bottom margin
"-T", "0", // top margin
"-s", "A5", // page size A5
"-O", "Landscape", // landscape mode
"cloneTemplate/"+htmlName,
pdfPath)
}
if err := cmd.Run(); err != nil {
return false, err