Skip to content

Commit

Permalink
feat(libre-office): add downloadFrom property
Browse files Browse the repository at this point in the history
  • Loading branch information
cherfia committed Sep 24, 2024
1 parent f96c0cb commit 34b95b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/libre-office/interfaces/libre-office.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReadStream } from 'fs';
import { Metadata, PdfFormat } from '../../common';
import { DownloadFrom } from '../../common/types';

type FileExtension =
| '123'
Expand Down Expand Up @@ -170,4 +171,5 @@ export type ConversionOptions = {
reduceImageResolution?: boolean; // Allow turning on or off image resolution reduction (default to false).
quality?: number; // Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.
maxImageResolution?: 75 | 150 | 300 | 600 | 1200; // Specify if all images will be reduced to the given value in DPI
downloadFrom?: DownloadFrom; // Download a file from a URL. It must return a Content-Disposition header with a filename parameter.
};
18 changes: 4 additions & 14 deletions src/libre-office/libre-office.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import FormData from 'form-data';

import { Chromiumly } from '../main.config';
import { GotenbergUtils, PdfFormat, Metadata } from '../common';
import { GotenbergUtils } from '../common';
import {
PageProperties,
ConversionOptions,
PathLikeOrReadStream
} from './interfaces/libre-office.types';
import { LibreOfficeUtils } from './utils/libre-office.utils';
Expand All @@ -26,6 +26,7 @@ export class LibreOffice {
* @param {boolean} [options.reduceImageResolution] - Indicates whether to reduce image resolution.
* @param {number} [options.quality] - Quality of the JPG export.
* @param {75 | 150 | 300 | 600 | 1200} [options.maxImageResolution] - Maximum image resolution for the converted PDF.
*
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
*/
public static async convert({
Expand All @@ -39,18 +40,7 @@ export class LibreOffice {
reduceImageResolution,
quality,
maxImageResolution
}: {
files: PathLikeOrReadStream[];
properties?: PageProperties;
pdfa?: PdfFormat;
pdfUA?: boolean;
merge?: boolean;
metadata?: Metadata;
losslessImageCompression?: boolean;
reduceImageResolution?: boolean;
quality?: number;
maxImageResolution?: 75 | 150 | 300 | 600 | 1200;
}): Promise<Buffer> {
}: { files: PathLikeOrReadStream[] } & ConversionOptions): Promise<Buffer> {
const data = new FormData();

await LibreOfficeUtils.addFiles(files, data);
Expand Down
4 changes: 4 additions & 0 deletions src/libre-office/utils/libre-office.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ export class LibreOfficeUtils {
data.append('maxImageResolution', options.maxImageResolution);
}

if (options.downloadFrom) {
data.append('downloadFrom', JSON.stringify(options.downloadFrom));
}

if (options.properties) {
LibreOfficeUtils.addPageProperties(data, options.properties);
}
Expand Down

0 comments on commit 34b95b6

Please sign in to comment.