cherfia / chromiumly

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.
MIT License
61 stars 7 forks source link

singlePage property not working when converting from xlsx to pdf #360

Closed satramcs closed 4 months ago

satramcs commented 4 months ago

Problem statement: I need the entire excel sheet to single page in pdf so that the excel sheet should not broken. There is a option in libreoffice calc "Whole sheet export" (Please refer the screenshot) Screenshot 2024-04-03 125545

I need to enable the whole sheet export option while converting the xlsx to pdf. So I've set the property singlePage: true but it doesn't not works. Screenshot 2024-04-03 125202

Please let me know if there is any other way to enable the Whole sheet export option Sample code:

const path = require("path");
const fs = require("fs");

const libre = require("libreoffice-convert");
libre.convertAsync = require("util").promisify(libre.convert);

async function main() {
    const { PDFEngine } = await import("chromiumly");
    const buffer = await PDFEngine.convert({
        files: [path.join(__dirname, "/resources/test-file.xlsx")],
        properties: { singlePage: true },
    });
    fs.writeFileSync(path.join(__dirname, "/resources/test-file.pdf"), buffer);
}

main().catch(function () {
    console.log('Error converting file: ');
});
cherfia commented 4 months ago

@satramcs Thank you for reporting it. Could you please tell me what version of Gotenberg you're currently using? This is important as the singlePage property was introduced starting from Gotenberg version 8.2.0.

satramcs commented 4 months ago

I'm using this chromiumly 2.9.0 package. This package is require gotenberg docker image to be run. As per documentation I'm running docker run --rm -p 3000:3000 gotenberg/gotenberg:8 this docker image

cherfia commented 4 months ago

@satramcs Unfortunately, Gotenberg only supports the singlePage property when converting with Chromium. LibreOffice does not have a support for this page property yet πŸ˜• https://gotenberg.dev/docs/routes#page-properties-libreoffice.

cherfia commented 4 months ago

The convert method in the PDFEngine is simply a wrapper for Gotenberg's LibreOffice convert route. Currently, the only properties supported are landscape and nativePageRanges. That is why when using the singlePage property in your code, no action occurs because this property is not supported.

const buffer = await PDFEngine.convert({
    files: [path.join(__dirname, "/resources/test-file.xlsx")],
    properties: { singlePage: true },
});

I hope this helps clarify things.

satramcs commented 4 months ago

Thank you for your clarification. Do we have any other solution to export the excel sheet to single page using libreoffice? (any configuration on the docker side) "Whole sheet export" with this option

cherfia commented 4 months ago

@satramcs I'm not very knowledgeable about that topic πŸ˜… but perhaps you could find assistance by asking in the Gotenberg discussions.

cherfia commented 4 months ago

@satramcs Gotenberg introduced a new property LibreOffice singlePageSheets that you requested in version 8.4.0 and it's now supported in chromiumly version 3.1.0 πŸš€