Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write to a Text File. #5

Open
majortargets opened this issue Nov 2, 2017 · 1 comment
Open

Write to a Text File. #5

majortargets opened this issue Nov 2, 2017 · 1 comment

Comments

@majortargets
Copy link

majortargets commented Nov 2, 2017

I am new to node.js and I want to write "rows" object to a text file. Can you help with below code.

Basically a way to iterate the rows object.

var pdf2table = require('pdf2table');
var fs = require('fs');

var logger = fs.createWriteStream('log.txt', {
    flags: 'a' 
})
fs.readFile('./test.pdf', function (err, buffer) {
    if (err) return console.log(err);
    pdf2table.parse(buffer, function (err, rows, rowsdebug) {
        if (err) return console.log(err);      
        console.log(rows);
        logger.write(rows);        
    });
});
@SamDecrock
Copy link
Owner

Something like:

var pdf2table = require('pdf2table');
var fs = require('fs');

var logger = fs.createWriteStream('log.txt', {
    flags: 'a' 
})
fs.readFile('./test.pdf', function (err, buffer) {
    if (err) return console.log(err);
    pdf2table.parse(buffer, function (err, rows, rowsdebug) {
        if (err) return console.log(err);      
        console.log(rows);


        for (var i = 0; i < rows.length; i++) {
	  var columns = rows[i];
	  var line = columns.join("\t");
	  logger.write(line);        
        }      


    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants