initial commit

This commit is contained in:
2025-12-23 12:17:27 +01:00
commit 8b73c86796
21 changed files with 2279 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package lib
import (
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/pdfcpu/pdfcpu/pkg/api"
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model"
)
func AppendToPdf(inputPdfFilePath string, inputXmlFilePath string, outputFilePath string) error {
logger := GetDebugLogger()
logger.Log(fmt.Sprintf("enter appendToPdf(%s, %s, %s)", inputPdfFilePath, inputXmlFilePath, outputFilePath))
defer func() {
logger.Log("leave appendToPdf")
}()
if inputPdfFilePath == "" {
return errors.New("no input pdf file specified")
}
if inputXmlFilePath == "" {
inputXmlFilePath = strings.TrimSuffix(inputPdfFilePath, filepath.Ext(inputPdfFilePath)) + ".xml"
}
if outputFilePath == "" {
outputFilePath = strings.TrimSuffix(
inputPdfFilePath,
filepath.Ext(inputPdfFilePath),
) + "_xml.pdf"
}
logger.Log(
fmt.Sprintf(
"pdfInput: '%s' xmlInput: '%s' output: '%s'",
inputPdfFilePath,
inputXmlFilePath,
outputFilePath,
),
)
err := api.AddAttachmentsFile(
inputPdfFilePath,
outputFilePath,
[]string{inputXmlFilePath},
true,
model.NewDefaultConfiguration(),
)
if err != nil {
return err
}
return nil
}