joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

Is there any way to join two pdfs together? #713

Open Finneah opened 3 years ago

Finneah commented 3 years ago

i have downloaded a PDF file and saved them as a file. Then i created another PDf File. When I try to make one out of these two files with writeStream(filePath,'base64',true) or with appendFile(filepath,data,'base64') I always have only the content of the second file.

Lib Version: 0.12.0

       RNFetchBlob.config({
                fileCache: true,
                path: filePath
            })
                .fetch(
                    'POST',
                    'https://app.useanvil.com/api/v1/fill/rTtjlIZnny79WW1WofOO.pdf',
                    {
                        Authorization:
                            '...',
                        'Content-Type': 'multipart/form-data'
                    },
                    [
                        {name: 'data', data: JSON.stringify(data)}
                    ]
                )
                .then(async (res) => {
                    let status = res.info().status;
                    if (status == 200) {
                        var pdf = new PDF_HA();
                        var html = pdf._getPDF(this.state);
                        PDF.fromHTML(html, '').then((protocolData) => {
                            RNFetchBlob.fs
                                .writeStream(filePath, 'base64', true)
                                .then((stream) => {
                                    stream.write(protocolData);
                                    RNFetchBlob.fs
                                        .readFile(filePath, 'base64')
                                        .then((allData) => {
                                            this.setState({
                                                filePath: filePath,
                                                base64: allData
                                            });
                                            return stream.close();
                                        });
                                });
                        });
                    }
                })
                .catch((err) => {
                    error_handler._handleDefaultError(
                        err
                    );
                });