mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-10 09:32:13 +01:00
feat(libreoffice): add viewer preference form fields
This commit is contained in:
@@ -140,6 +140,66 @@ type Options struct {
|
||||
// one page.
|
||||
SinglePageSheets bool
|
||||
|
||||
// InitialView specifies how the PDF document should be displayed when
|
||||
// opened. 0 = neither outlines nor thumbnails, 1 = outline pane open,
|
||||
// 2 = thumbnail pane open.
|
||||
InitialView int
|
||||
|
||||
// InitialPage specifies the page on which the PDF document should be
|
||||
// opened in the viewer.
|
||||
InitialPage int
|
||||
|
||||
// Magnification specifies the action to be performed when the PDF document
|
||||
// is opened. 0 = default, 1 = fit entire page, 2 = fit page width,
|
||||
// 3 = fit visible, 4 = use zoom value from Zoom property.
|
||||
Magnification int
|
||||
|
||||
// Zoom specifies the zoom level the PDF document is opened with. Only
|
||||
// used if Magnification is set to 4.
|
||||
Zoom int
|
||||
|
||||
// PageLayout specifies the page layout when the document is opened.
|
||||
// 0 = default, 1 = single page, 2 = one column, 3 = two columns.
|
||||
PageLayout int
|
||||
|
||||
// FirstPageOnLeft is used with PageLayout value 3. If true, the first
|
||||
// page is displayed on the left side.
|
||||
FirstPageOnLeft bool
|
||||
|
||||
// ResizeWindowToInitialPage specifies that the PDF viewer window is
|
||||
// resized to show the whole initial page.
|
||||
ResizeWindowToInitialPage bool
|
||||
|
||||
// CenterWindow specifies that the PDF viewer window is centered on the
|
||||
// screen.
|
||||
CenterWindow bool
|
||||
|
||||
// OpenInFullScreenMode specifies that the PDF viewer window is opened
|
||||
// full screen.
|
||||
OpenInFullScreenMode bool
|
||||
|
||||
// DisplayPDFDocumentTitle specifies that the document title is displayed
|
||||
// in the PDF viewer title bar.
|
||||
DisplayPDFDocumentTitle bool
|
||||
|
||||
// HideViewerMenubar specifies whether to hide the PDF viewer menubar.
|
||||
HideViewerMenubar bool
|
||||
|
||||
// HideViewerToolbar specifies whether to hide the PDF viewer toolbar.
|
||||
HideViewerToolbar bool
|
||||
|
||||
// HideViewerWindowControls specifies whether to hide the PDF viewer
|
||||
// window controls.
|
||||
HideViewerWindowControls bool
|
||||
|
||||
// UseTransitionEffects specifies that slide transitions are exported to
|
||||
// PDF. Only active for Impress documents.
|
||||
UseTransitionEffects bool
|
||||
|
||||
// OpenBookmarkLevels specifies how many bookmark levels should be opened
|
||||
// in the reader. -1 = all levels, 1-10 = specific level.
|
||||
OpenBookmarkLevels int
|
||||
|
||||
// LosslessImageCompression specifies if images are exported to PDF using
|
||||
// a lossless compression format like PNG or compressed using the JPEG
|
||||
// format.
|
||||
@@ -208,6 +268,21 @@ func DefaultOptions() Options {
|
||||
SkipEmptyPages: false,
|
||||
AddOriginalDocumentAsStream: false,
|
||||
SinglePageSheets: false,
|
||||
InitialView: 0,
|
||||
InitialPage: 1,
|
||||
Magnification: 0,
|
||||
Zoom: 100,
|
||||
PageLayout: 0,
|
||||
FirstPageOnLeft: false,
|
||||
ResizeWindowToInitialPage: false,
|
||||
CenterWindow: false,
|
||||
OpenInFullScreenMode: false,
|
||||
DisplayPDFDocumentTitle: true,
|
||||
HideViewerMenubar: false,
|
||||
HideViewerToolbar: false,
|
||||
HideViewerWindowControls: false,
|
||||
UseTransitionEffects: true,
|
||||
OpenBookmarkLevels: -1,
|
||||
LosslessImageCompression: false,
|
||||
Quality: 90,
|
||||
ReduceImageResolution: false,
|
||||
|
||||
@@ -295,6 +295,21 @@ func (p *libreOfficeProcess) pdf(ctx context.Context, logger *slog.Logger, input
|
||||
args = append(args, "--export", fmt.Sprintf("IsSkipEmptyPages=%t", options.SkipEmptyPages))
|
||||
args = append(args, "--export", fmt.Sprintf("IsAddStream=%t", options.AddOriginalDocumentAsStream))
|
||||
args = append(args, "--export", fmt.Sprintf("SinglePageSheets=%t", options.SinglePageSheets))
|
||||
args = append(args, "--export", fmt.Sprintf("InitialView=%d", options.InitialView))
|
||||
args = append(args, "--export", fmt.Sprintf("InitialPage=%d", options.InitialPage))
|
||||
args = append(args, "--export", fmt.Sprintf("Magnification=%d", options.Magnification))
|
||||
args = append(args, "--export", fmt.Sprintf("Zoom=%d", options.Zoom))
|
||||
args = append(args, "--export", fmt.Sprintf("PageLayout=%d", options.PageLayout))
|
||||
args = append(args, "--export", fmt.Sprintf("FirstPageOnLeft=%t", options.FirstPageOnLeft))
|
||||
args = append(args, "--export", fmt.Sprintf("ResizeWindowToInitialPage=%t", options.ResizeWindowToInitialPage))
|
||||
args = append(args, "--export", fmt.Sprintf("CenterWindow=%t", options.CenterWindow))
|
||||
args = append(args, "--export", fmt.Sprintf("OpenInFullScreenMode=%t", options.OpenInFullScreenMode))
|
||||
args = append(args, "--export", fmt.Sprintf("DisplayPDFDocumentTitle=%t", options.DisplayPDFDocumentTitle))
|
||||
args = append(args, "--export", fmt.Sprintf("HideViewerMenubar=%t", options.HideViewerMenubar))
|
||||
args = append(args, "--export", fmt.Sprintf("HideViewerToolbar=%t", options.HideViewerToolbar))
|
||||
args = append(args, "--export", fmt.Sprintf("HideViewerWindowControls=%t", options.HideViewerWindowControls))
|
||||
args = append(args, "--export", fmt.Sprintf("UseTransitionEffects=%t", options.UseTransitionEffects))
|
||||
args = append(args, "--export", fmt.Sprintf("OpenBookmarkLevels=%d", options.OpenBookmarkLevels))
|
||||
args = append(args, "--export", fmt.Sprintf("UseLosslessCompression=%t", options.LosslessImageCompression))
|
||||
args = append(args, "--export", fmt.Sprintf("Quality=%d", options.Quality))
|
||||
args = append(args, "--export", fmt.Sprintf("ReduceImageResolution=%t", options.ReduceImageResolution))
|
||||
|
||||
@@ -67,6 +67,21 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
|
||||
maxImageResolution int
|
||||
nativeWatermarkText string
|
||||
nativeWatermarkColor int
|
||||
initialView int
|
||||
initialPage int
|
||||
magnification int
|
||||
zoom int
|
||||
pageLayout int
|
||||
firstPageOnLeft bool
|
||||
resizeWindowToInitialPage bool
|
||||
centerWindow bool
|
||||
openInFullScreenMode bool
|
||||
displayPDFDocumentTitle bool
|
||||
hideViewerMenubar bool
|
||||
hideViewerToolbar bool
|
||||
hideViewerWindowControls bool
|
||||
useTransitionEffects bool
|
||||
openBookmarkLevels int
|
||||
nativeWatermarkFontHeight int
|
||||
nativeWatermarkRotateAngle int
|
||||
nativeWatermarkFontName string
|
||||
@@ -97,6 +112,105 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
|
||||
Bool("skipEmptyPages", &skipEmptyPages, defaultOptions.SkipEmptyPages).
|
||||
Bool("addOriginalDocumentAsStream", &addOriginalDocumentAsStream, defaultOptions.AddOriginalDocumentAsStream).
|
||||
Bool("singlePageSheets", &singlePageSheets, defaultOptions.SinglePageSheets).
|
||||
Custom("initialView", func(value string) error {
|
||||
if value == "" {
|
||||
initialView = defaultOptions.InitialView
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !slices.Contains([]int{0, 1, 2}, intValue) {
|
||||
return errors.New("value is not 0, 1 or 2")
|
||||
}
|
||||
initialView = intValue
|
||||
return nil
|
||||
}).
|
||||
Custom("initialPage", func(value string) error {
|
||||
if value == "" {
|
||||
initialPage = defaultOptions.InitialPage
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if intValue < 1 {
|
||||
return errors.New("value is inferior to 1")
|
||||
}
|
||||
initialPage = intValue
|
||||
return nil
|
||||
}).
|
||||
Custom("magnification", func(value string) error {
|
||||
if value == "" {
|
||||
magnification = defaultOptions.Magnification
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !slices.Contains([]int{0, 1, 2, 3, 4}, intValue) {
|
||||
return errors.New("value is not 0, 1, 2, 3 or 4")
|
||||
}
|
||||
magnification = intValue
|
||||
return nil
|
||||
}).
|
||||
Custom("zoom", func(value string) error {
|
||||
if value == "" {
|
||||
zoom = defaultOptions.Zoom
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if intValue < 1 {
|
||||
return errors.New("value is inferior to 1")
|
||||
}
|
||||
zoom = intValue
|
||||
return nil
|
||||
}).
|
||||
Custom("pageLayout", func(value string) error {
|
||||
if value == "" {
|
||||
pageLayout = defaultOptions.PageLayout
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !slices.Contains([]int{0, 1, 2, 3}, intValue) {
|
||||
return errors.New("value is not 0, 1, 2 or 3")
|
||||
}
|
||||
pageLayout = intValue
|
||||
return nil
|
||||
}).
|
||||
Bool("firstPageOnLeft", &firstPageOnLeft, defaultOptions.FirstPageOnLeft).
|
||||
Bool("resizeWindowToInitialPage", &resizeWindowToInitialPage, defaultOptions.ResizeWindowToInitialPage).
|
||||
Bool("centerWindow", ¢erWindow, defaultOptions.CenterWindow).
|
||||
Bool("openInFullScreenMode", &openInFullScreenMode, defaultOptions.OpenInFullScreenMode).
|
||||
Bool("displayPDFDocumentTitle", &displayPDFDocumentTitle, defaultOptions.DisplayPDFDocumentTitle).
|
||||
Bool("hideViewerMenubar", &hideViewerMenubar, defaultOptions.HideViewerMenubar).
|
||||
Bool("hideViewerToolbar", &hideViewerToolbar, defaultOptions.HideViewerToolbar).
|
||||
Bool("hideViewerWindowControls", &hideViewerWindowControls, defaultOptions.HideViewerWindowControls).
|
||||
Bool("useTransitionEffects", &useTransitionEffects, defaultOptions.UseTransitionEffects).
|
||||
Custom("openBookmarkLevels", func(value string) error {
|
||||
if value == "" {
|
||||
openBookmarkLevels = defaultOptions.OpenBookmarkLevels
|
||||
return nil
|
||||
}
|
||||
intValue, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if intValue != -1 && (intValue < 1 || intValue > 10) {
|
||||
return errors.New("value is not -1 or between 1 and 10")
|
||||
}
|
||||
openBookmarkLevels = intValue
|
||||
return nil
|
||||
}).
|
||||
Bool("losslessImageCompression", &losslessImageCompression, defaultOptions.LosslessImageCompression).
|
||||
Custom("quality", func(value string) error {
|
||||
if value == "" {
|
||||
@@ -227,6 +341,21 @@ func convertRoute(libreOffice libreofficeapi.Uno, engine gotenberg.PdfEngine) ap
|
||||
SkipEmptyPages: skipEmptyPages,
|
||||
AddOriginalDocumentAsStream: addOriginalDocumentAsStream,
|
||||
SinglePageSheets: singlePageSheets,
|
||||
InitialView: initialView,
|
||||
InitialPage: initialPage,
|
||||
Magnification: magnification,
|
||||
Zoom: zoom,
|
||||
PageLayout: pageLayout,
|
||||
FirstPageOnLeft: firstPageOnLeft,
|
||||
ResizeWindowToInitialPage: resizeWindowToInitialPage,
|
||||
CenterWindow: centerWindow,
|
||||
OpenInFullScreenMode: openInFullScreenMode,
|
||||
DisplayPDFDocumentTitle: displayPDFDocumentTitle,
|
||||
HideViewerMenubar: hideViewerMenubar,
|
||||
HideViewerToolbar: hideViewerToolbar,
|
||||
HideViewerWindowControls: hideViewerWindowControls,
|
||||
UseTransitionEffects: useTransitionEffects,
|
||||
OpenBookmarkLevels: openBookmarkLevels,
|
||||
LosslessImageCompression: losslessImageCompression,
|
||||
Quality: quality,
|
||||
ReduceImageResolution: reduceImageResolution,
|
||||
|
||||
Reference in New Issue
Block a user