feat(libreoffice): add showTrackedChanges form field (#1743)

This commit is contained in:
Philip Ngo
2026-11-24 17:54:33 +01:00
committed by GitHub
parent dbbad420b6
commit 3aa5866b1b
7 changed files with 50 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ body:multipart-form {
~exportNotesPages: false
~exportOnlyNotesPages: false
~exportNotesInMargin: false
~showTrackedChanges: false
~convertOooTargetToPdfTarget: false
~exportLinksRelativeFsys: false
~exportHiddenSlides: false

View File

@@ -163,6 +163,11 @@ type Options struct {
// PDF.
ExportNotesInMargin bool
// ShowTrackedChanges exports tracked changes (insertions and deletions)
// as marked up. When false, the document is exported as if every change
// were accepted.
ShowTrackedChanges bool
// ConvertOooTargetToPdfTarget specifies that the target documents with
// .od[tpgs] extension will have that extension changed to .pdf when the
// link is exported to PDF. The source document remains untouched.
@@ -335,6 +340,7 @@ func DefaultOptions() Options {
ExportNotesPages: false,
ExportOnlyNotesPages: false,
ExportNotesInMargin: false,
ShowTrackedChanges: false,
ConvertOooTargetToPdfTarget: false,
ExportLinksRelativeFsys: false,
ExportHiddenSlides: false,

View File

@@ -98,6 +98,7 @@ type lokRequest struct {
ExportNotesPages bool `json:"exportNotesPages"`
ExportOnlyNotesPages bool `json:"exportOnlyNotesPages"`
ExportNotesInMargin bool `json:"exportNotesInMargin"`
ShowTrackedChanges bool `json:"showTrackedChanges"`
ConvertOooTargetToPdfTarget bool `json:"convertOooTargetToPdfTarget"`
ExportLinksRelativeFsys bool `json:"exportLinksRelativeFsys"`
ExportHiddenSlides bool `json:"exportHiddenSlides"`
@@ -219,6 +220,7 @@ func newLokRequest(inputPath, outputPath string, options Options) (lokRequest, e
ExportNotesPages: options.ExportNotesPages,
ExportOnlyNotesPages: options.ExportOnlyNotesPages,
ExportNotesInMargin: options.ExportNotesInMargin,
ShowTrackedChanges: options.ShowTrackedChanges,
ConvertOooTargetToPdfTarget: options.ConvertOooTargetToPdfTarget,
ExportLinksRelativeFsys: options.ExportLinksRelativeFsys,
ExportHiddenSlides: options.ExportHiddenSlides,

View File

@@ -140,6 +140,7 @@ func TestLibreOfficeProcess(t *testing.T) {
output := filepath.Join(dir, "out.pdf")
options := DefaultOptions()
options.PdfFormats = PdfFormats{PdfA: PdfA2b}
options.ShowTrackedChanges = true
err = p.pdf(context.Background(), logger, filepath.Join(dir, "ok.csv"), output, options)
if err != nil {
@@ -152,8 +153,8 @@ func TestLibreOfficeProcess(t *testing.T) {
t.Fatalf("the fake lok wrote no request: %v", err)
}
if sent.PdfVersion != 2 || !sent.EmbedStandardFonts || !sent.DisableCalcHeader || !sent.UpdateIndexes {
t.Errorf("request = %+v, want PDF/A-2b with embedded fonts, the CSV header off and indexes updated", sent)
if sent.PdfVersion != 2 || !sent.EmbedStandardFonts || !sent.DisableCalcHeader || !sent.UpdateIndexes || !sent.ShowTrackedChanges {
t.Errorf("request = %+v, want PDF/A-2b with embedded fonts, the CSV header off, indexes updated and tracked changes shown", sent)
}
for _, tc := range []struct {

View File

@@ -61,6 +61,7 @@ func convertRoute(libreOffice libreofficeapi.Converter, processor *pdf.Processor
Bool("exportNotesPages", &options.ExportNotesPages).
Bool("exportOnlyNotesPages", &options.ExportOnlyNotesPages).
Bool("exportNotesInMargin", &options.ExportNotesInMargin).
Bool("showTrackedChanges", &options.ShowTrackedChanges).
Bool("convertOooTargetToPdfTarget", &options.ConvertOooTargetToPdfTarget).
Bool("exportLinksRelativeFsys", &options.ExportLinksRelativeFsys).
Bool("exportHiddenSlides", &options.ExportHiddenSlides).

View File

@@ -65,6 +65,41 @@ Feature: /forms/libreoffice/convert
"""
Then the "foo.pdf" PDF should NOT have content matching "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" at page 1
Scenario: POST /forms/libreoffice/convert (Tracked Changes Accepted By Default)
Given I have a default Gotenberg container
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
| files | testdata/tracked_changes.docx | file |
| Gotenberg-Output-Filename | foo | header |
Then the response status code should be 200
Then the response header "Content-Type" should be "application/pdf"
Then there should be 1 PDF(s) in the response
Then the "foo.pdf" PDF should have the following content at page 1:
"""
Inserted text.
"""
Then the "foo.pdf" PDF should NOT have the following content at page 1:
"""
Deleted text.
"""
Scenario: POST /forms/libreoffice/convert (Show Tracked Changes)
Given I have a default Gotenberg container
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
| files | testdata/tracked_changes.docx | file |
| showTrackedChanges | true | field |
| Gotenberg-Output-Filename | foo | header |
Then the response status code should be 200
Then the response header "Content-Type" should be "application/pdf"
Then there should be 1 PDF(s) in the response
Then the "foo.pdf" PDF should have the following content at page 1:
"""
Deleted text.
"""
Then the "foo.pdf" PDF should have the following content at page 1:
"""
Inserted text.
"""
Scenario: POST /forms/libreoffice/convert (Many Documents)
Given I have a default Gotenberg container
When I make a "POST" request to Gotenberg at the "/forms/libreoffice/convert" endpoint with the following form data and header(s):
@@ -361,6 +396,7 @@ Feature: /forms/libreoffice/convert
| exportNotesPages | foo | field |
| exportOnlyNotesPages | foo | field |
| exportNotesInMargin | foo | field |
| showTrackedChanges | foo | field |
| convertOooTargetToPdfTarget | foo | field |
| exportLinksRelativeFsys | foo | field |
| exportHiddenSlides | foo | field |
@@ -403,6 +439,7 @@ Feature: /forms/libreoffice/convert
form field 'exportNotesPages' is invalid (got 'foo', want true or false)
form field 'exportOnlyNotesPages' is invalid (got 'foo', want true or false)
form field 'exportNotesInMargin' is invalid (got 'foo', want true or false)
form field 'showTrackedChanges' is invalid (got 'foo', want true or false)
form field 'convertOooTargetToPdfTarget' is invalid (got 'foo', want true or false)
form field 'exportLinksRelativeFsys' is invalid (got 'foo', want true or false)
form field 'exportHiddenSlides' is invalid (got 'foo', want true or false)

Binary file not shown.