lilliputten / jsrtf Goto Github PK
View Code? Open in Web Editor NEWAn RTF document creation library for javascript.
An RTF document creation library for javascript.
Hello! Congrats on your initiative!
Can this code be used directly in the browser?
Spanish characters are displayed as junk characters in jsrtf file even after setting the language as SP_MX.
Greetings @lilliputten!
Thank You for jsrtf library! This is not an issue but a question..
Can You please help mу how to encode non-latin (russian) letters, that are mixed with special symbols, for example: > Abc Ø абв
Here is english text, special symbol and russian text.
I have existing RTF template with 'placeholder' text inside, and what I need is to replace this 'placeholder' with 'Abc Ø абв':
If I use Your function utf8_decode_to_win1251
- it successfully writes russian letters but finally I get "Ш" Instead of 'Ø':
Here is my example code and input and output files:
input rtf: https://mega.nz/file/CtNB2CiY#yid1nLq9P6Jo8zSRAsXeGai-mZLV6xP1OvN1jDpFyG4
output generated by the code below: https://mega.nz/file/asMExKJI#q8oRn1J9oWMlUck6tJ6MdpVGiIjt81kNFRo7T3eSBTU
const http = require('http');
const port = 3100;
function utf8_decode_to_win1251(srcStr) {
var tgtStr = "",
c = 0;
for (var i = 0; i < srcStr.length; i++) {
c = srcStr.charCodeAt(i);
if (c > 127) {
if (c > 1024) {
if (c === 1025) {
c = 1016;
} else if (c === 1105) {
c = 1032;
}
c -= 848;
}
// c = c % 256; // ???
}
tgtStr += String.fromCharCode(c);
}
return tgtStr;
}
const server = http.createServer(function (req, res) {
const fs = require('fs');
// read existing file
fs.readFile("C:\input.rtf", "utf8", (err, inputText) => {
if (err) {
console.error(err);
return;
}
// I want to replace 'placeholder' text in file with this test text:
let text = `Abc Ø абв`; // Abc Ø абв
text = utf8_decode_to_win1251(text); // text with encoded russian letters 'Abc Ø àáâ'
// replace placeholder from input RTF with text with non-latin characters 'Abc Ø àáâ':
inputText = inputText.replace("placeholder", text);
// RTF uses 8-bit so need to convert from unicode
let buf = Buffer.from(inputText, "ascii"); // "binary" also gives wrong output text https://stackoverflow.com/a/34476862/348736
// write output file to disk
fs.writeFile("C:\output.rtf", buf, function (error, resultFile) { // result file contains 'Abc Ш абв', which is wrong..
if (!error) {
console.info('Created file', resultFile);
}
else {
console.error(error);
}
});
});
});
server.listen(port, function (error) {
if (error) {
console.log(`${error}`);
} else {
console.log(`listening on port ${port}`);
}
})
I use LibreOffice v. 7.6.1.2 (X86_64) to view RTF files
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.