oziresrds / html-to-rtf

Convert html to rtf format in the server
38 stars 43 forks source link

Can you add another version in which fs module isn't required? #15

Closed gwozt closed 2 years ago

gwozt commented 4 years ago

You would be a lifesaver if you would modify the code to have it also work without fs module. Or create an angular wrapper for it. I only need the part where you do the conversion. It would also be very helpful if you would update the code so that it also works with VanillaJS.

oziresrds commented 4 years ago

Hello, your suggestion is allow de lib works in the server and browser. Its an improvement and now i dont have enough time to do it, but i will think.

antoniolucasnobar commented 4 years ago

I just removed the ocurrences of fs in the file rtf.class.js. Then I was able to use this lib in the browser.

What else should I do?

//const fs                    = require('fs');
//....
  saveRtfInFile(path, value) {
//    fs.writeFile(path, value, (err) => {
//      if (err) throw err;
      console.log('The file has been saved!');
//    });
  }

to save the rtf from the browser, i did this:

const htmlToRtf = require('html-to-rtf');
const rtf = htmlToRtf.convertHtmlToRtf(this.editor.getData()); 
const blob = new Blob([rtf], {type: "application/rtf;charset=utf-8"});
const link=window.URL.createObjectURL(blob);
window.location=link;

and I was able to download a valid RTF.

oziresrds commented 2 years ago

I sent a package update v2.0.0 to work in the browser and the server.