elwerene / libreoffice-convert

MIT License
266 stars 98 forks source link

How to use filters in the libreoffice-convert #127

Closed nikhilguptagl closed 4 days ago

nikhilguptagl commented 2 months ago

I am using the basic code which is mentioned here - https://www.npmjs.com/package/libreoffice-convert

const path = require('path');
const fs = require('fs').promises;

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

async function main() {
    const ext = '.pdf'
    const inputPath = path.join(__dirname, '/resources/example.docx');
    const outputPath = path.join(__dirname, `/resources/example${ext}`);

    // Read file
    const docxBuf = await fs.readFile(inputPath);

    // Convert it to pdf format with undefined filter (see Libreoffice docs about filter)
    let pdfBuf = await libre.convertAsync(docxBuf, ext, undefined);

    // Here in done you have pdf file which you can save or transfer in another stream
    await fs.writeFile(outputPath, pdfBuf);
}

main().catch(function (err) {
    console.log(`Error converting file: ${err}`);
});

I want to know what filters can be used and is there any documentation for it ?

elwerene commented 2 months ago

There's a table with all filters:

https://help.libreoffice.org/latest/en-US/text/shared/guide/convertfilters.html

nikhilguptagl commented 2 months ago

@elwerene - I looked at the page but I did not get how to setup the filters in the code itself. It would be great if you can provide any sample for this ?

I am using like this -

const filter = {
    'FilterData': {
        'PageWidth': 21000,
        'PageHeight': 29700
    }
};

but it's not working -

IvanKr1 commented 1 month ago

@nikhilguptagl

Did you manage to do it? change width and height I'm trying to convert the EMF file to SVG, but the width and height are too big, but can't manage to change it.

elwerene commented 1 month ago

@nikhilguptagl I have no idea how your example should work as I can not see any FilterData entry in the table I mentioned.