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. // Optional.
ExportFormFields bool 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, // PdfFormats allows to convert the resulting PDF to PDF/A-1b, PDF/A-2b,
// PDF/A-3b and PDF/UA. // PDF/A-3b and PDF/UA.
// Optional. // Optional.

View File

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

View File

@@ -393,6 +393,35 @@ func TestLibreOfficeProcess_pdf(t *testing.T) {
start: true, start: true,
expectError: false, 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)", scenario: "success (page ranges)",
libreOffice: newLibreOfficeProcess( libreOffice: newLibreOfficeProcess(

View File

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