feat(libreoffice): add singlePageSheets option

This commit is contained in:
Martin
2024-03-25 14:46:15 +01:00
committed by Julien Neuhart
parent 8454d163eb
commit 43a13ff2c5
4 changed files with 40 additions and 0 deletions

View File

@@ -54,6 +54,10 @@ type Options struct {
// Optional.
ExportFormFields bool
// SinglePageSheets allows to output each sheet as a single page in the resulting PDF.
// Optional
SinglePageSheets bool
// PdfFormats allows to convert the resulting PDF to PDF/A-1b, PDF/A-2b,
// PDF/A-3b and PDF/UA.
// Optional.

View File

@@ -277,6 +277,10 @@ func (p *libreOfficeProcess) pdf(ctx context.Context, logger *zap.Logger, inputP
args = append(args, "--export", "ExportFormFields=false")
}
if options.SinglePageSheets {
args = append(args, "--export", "SinglePageSheets=true")
}
switch options.PdfFormats.PdfA {
case "":
case gotenberg.PdfA1b:

View File

@@ -393,6 +393,35 @@ func TestLibreOfficeProcess_pdf(t *testing.T) {
start: true,
expectError: false,
},
{
scenario: "success (single page sheets)",
libreOffice: newLibreOfficeProcess(
libreOfficeArguments{
binPath: os.Getenv("LIBREOFFICE_BIN_PATH"),
unoBinPath: os.Getenv("UNOCONVERTER_BIN_PATH"),
startTimeout: 5 * time.Second,
},
),
fs: func() *gotenberg.FileSystem {
fs := gotenberg.NewFileSystem()
err := os.MkdirAll(fs.WorkingDirPath(), 0o755)
if err != nil {
t.Fatalf(fmt.Sprintf("expected no error but got: %v", err))
}
err = os.WriteFile(fmt.Sprintf("%s/document.txt", fs.WorkingDirPath()), []byte("SinglePageSheets"), 0o755)
if err != nil {
t.Fatalf("expected no error but got: %v", err)
}
return fs
}(),
options: Options{SinglePageSheets: true},
cancelledCtx: false,
start: true,
expectError: false,
},
{
scenario: "success (page ranges)",
libreOffice: newLibreOfficeProcess(

View File

@@ -29,6 +29,7 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
landscape bool
nativePageRanges string
exportFormFields bool
singlePageSheets bool
pdfa string
pdfua bool
nativePdfFormats bool
@@ -41,6 +42,7 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
Bool("landscape", &landscape, false).
String("nativePageRanges", &nativePageRanges, "").
Bool("exportFormFields", &exportFormFields, true).
Bool("singlePageSheets", &singlePageSheets, false).
String("pdfa", &pdfa, "").
Bool("pdfua", &pdfua, false).
Bool("nativePdfFormats", &nativePdfFormats, true).
@@ -72,6 +74,7 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
Landscape: landscape,
PageRanges: nativePageRanges,
ExportFormFields: exportFormFields,
SinglePageSheets: singlePageSheets,
}
if nativePdfFormats {