Skip to content

Commit

Permalink
feat: add split methods for chromium and libreoffice requests (#32)
Browse files Browse the repository at this point in the history
* feat: add split methods for chromium and libreoffice requests

* chore: move split mode values to constants

---------

Co-authored-by: Alexander Pikeev <alexanderpikeev@xmail.ru>
  • Loading branch information
starwalkn and Alexander Pikeev authored Dec 29, 2024
1 parent 5a9aa6b commit c5496cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
13 changes: 13 additions & 0 deletions chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ func (req *chromiumRequest) Metadata(jsonData []byte) {
req.fields[fieldMetadata] = string(jsonData)
}

// SplitIntervals splits the resulting PDF by interval.
func (req *chromiumRequest) SplitIntervals(span int) {
req.fields[fieldSplitMode] = splitModeIntervals
req.fields[fieldSplitSpan] = strconv.Itoa(span)
}

// SplitPages splits the resulting PDF by pages. Span should have the format “1-5”.
func (req *chromiumRequest) SplitPages(span string, unify bool) {
req.fields[fieldSplitMode] = splitModePages
req.fields[fieldSplitSpan] = span
req.fields[fieldSplitUnify] = strconv.FormatBool(unify)
}

// ScreenshotWidth Width sets the device screen width in pixels.
func (req *chromiumRequest) ScreenshotWidth(width float64) {
req.fields[fieldScreenshotWidth] = fmt.Sprintf("%f", width)
Expand Down
6 changes: 6 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ const (
fieldSplitSpan = "splitSpan"
fieldSplitUnify = "splitUnify"
)

// Split mode.
const (
splitModePages = "pages"
splitModeIntervals = "intervals"
)
13 changes: 13 additions & 0 deletions libreoffice.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ func (req *LibreOfficeRequest) Metadata(md []byte) {
req.fields[fieldMetadata] = string(md)
}

// SplitIntervals splits the resulting PDF by interval.
func (req *LibreOfficeRequest) SplitIntervals(span int) {
req.fields[fieldSplitMode] = splitModeIntervals
req.fields[fieldSplitSpan] = strconv.Itoa(span)
}

// SplitPages splits the resulting PDF by pages. Span should have the format “1-5”.
func (req *LibreOfficeRequest) SplitPages(span string, unify bool) {
req.fields[fieldSplitMode] = splitModePages
req.fields[fieldSplitSpan] = span
req.fields[fieldSplitUnify] = strconv.FormatBool(unify)
}

// Merge merges the resulting PDFs.
func (req *LibreOfficeRequest) Merge() {
req.fields[fieldOfficeMerge] = strconv.FormatBool(true)
Expand Down
2 changes: 1 addition & 1 deletion split_intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type SplitIntervalsRequest struct {

func NewSplitIntervalsRequest(pdfs ...document.Document) *SplitIntervalsRequest {
br := newBaseRequest()
br.fields[fieldSplitMode] = "intervals"
br.fields[fieldSplitMode] = splitModeIntervals

return &SplitIntervalsRequest{
pdfs: pdfs,
Expand Down
2 changes: 1 addition & 1 deletion split_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type SplitPagesRequest struct {

func NewSplitPagesRequest(pdfs ...document.Document) *SplitPagesRequest {
br := newBaseRequest()
br.fields[fieldSplitMode] = "pages"
br.fields[fieldSplitMode] = splitModePages

return &SplitPagesRequest{
pdfs: pdfs,
Expand Down

0 comments on commit c5496cc

Please sign in to comment.