Thursday, 18 May 2017

How I can read a pdf url and download it in node js express

I have a url:http://img01.taobaocdn.com/tfscom/TB1M2f4PpXXXXXVaXXXXXXXXXXX.pdf

I want to download this file and write its content into my file.

I am using phantom js package of node to achieve this. What I am doing:

phantom.create().then(function (ph) {
                                                                    ph.createPage().then(function (page) {
                                                                        page.open('http://img01.taobaocdn.com/tfscom/TB1M2f4PpXXXXXVaXXXXXXXXXXX.pdf').then(function (status) {

                                                                            console.log(" page.open status");
                                                                            console.log(status);
                                                                            return;
                                                                            page.render(base_pdf_path+"waybill"+warehouse_code+"/"+lpnumber+'.pdf').then(function (success) {
                                                                                logGetLpPdfProcess('[getLpdf] PDF generated for waybill');
                                                                                callback(null, waybillUrl);
                                                                                ph.exit();

                                                                            }).catch(function (error_render)
                                                                            {

                                                                                logGetLpPdfProcess("[getLpdf] Error in generating PDF for waybill. order id:" + tid + "Error is:" + error_render);
                                                                                callback(null, waybillUrl);

                                                                            });
                                                                        }).catch(function (error_open)
                                                                        {
                                                                            logGetLpPdfProcess("[getLpdf] Error in generating PDF for waybill. order id:" + tid + "Error is:" + error_open);
                                                                            callback(null, waybillUrl);

                                                                        });
                                                                    }).catch(function (error_create_page)
                                                                    {
                                                                        logGetLpPdfProcess("[getLpdf] Error in generating PDF for waybill. order id:" + tid + "Error is:" + error_create_page);
                                                                        callback(null, waybillUrl);

                                                                    });
                                                                }).catch(function (error_phantom_create)
                                                                {
                                                                    logGetLpPdfProcess("[getLpdf] Error in generating PDF for waybill. order id:" + tid + "Error is:" + error_phantom_create);
                                                                    callback(null, waybillUrl);



});

This code creates an empty pdf file with no data. Can anyone tell me any other lib which I can use for this purpose with some reference URL



via Simer

No comments:

Post a Comment