Coder Social home page Coder Social logo

rtf.js's Introduction

rtf.js

Build Status Coverage Status npm version

Render RTF documents in HTML. This also includes rendering WMF and EMF images which are often contained in RTF documents.

License

The code of this project is licensed under the MIT license. See the file LICENSE for details.

Using the library

For information on how to use the library see the Getting Started Guide

Live samples:

Dependencies

  • rtf.js requires:
    • js-codepage (Apache 2.0 license, included in the rtf.js bundle)
  • Rendering WMF and EMF images is accomplished by using HTML5's <svg> feature.
  • Rendering RTF documents often requires rendering embedded WMF and EMF images, however rtf.js can be used without wmf.js and emf.js or with just one of them, if rendering such images is not required.

See the Getting Started Guide for details.

Developing

To develop first install the dependencies using npm install.

Build with watch mode

For development purposes you can start a watch, which will build the project, serve the sample pages on localhost:8080 and automatically recompile and reload the sample page if you make a code change. This can be started with:

$ npm run watch

Building

To build the entire project and create the bundles run:

$ npm run build

Tests

Please run npm run lint first to make sure your code adheres to the style guide and npm run build to build the code to be tested

To run the test suite run:

$ npm run test

To create a new test (type is rtf, emf or wmf):

$ npm run generate-testcase <type> <test-name> </path/to/test.rtf>

To regenerate the expected result for an existing test:

$ npm run regenerate-testcase <type> <test-name>

Code Coverage

To generate code coverage metrics run:

$ npm run coverage

Afterwards you can generate a nice html report in the coverage directory:

$ npm run coverage-html

Warning: creating coverage reports instruments the bundles in the dist directory. Don't forget to build the project again before committing.

Releasing

See the Release Instructions for details.

rtf.js's People

Contributors

zoehneto avatar tbluemel avatar dependabot[bot] avatar kristianvalind avatar warren-bank avatar msturari avatar mmicalle avatar nickchen120235 avatar ynse01 avatar

Stargazers

XinKeng avatar José A. Ramos avatar  avatar Muhammet Ali Köker avatar vicha zhou avatar JK avatar Yuan Yuan avatar zuizuihao avatar Eunji Baek avatar Manfredi avatar  avatar David Dias avatar Delan Azabani avatar Aria Edmonds avatar Pedro Gómez avatar  avatar  avatar LFT avatar packy avatar  avatar fantasticit avatar Jacky avatar Bob Pritchett avatar Mitică avatar hfcorriez avatar Andrej Kozlovský avatar Mike R. avatar LiminalSpaces avatar Arc avatar  avatar chuyuan du avatar zhilin yi avatar guoyong yi avatar Herve Berard avatar 忆年 avatar Dave avatar Happlex avatar  avatar unrealyan avatar Tao avatar H avatar Alfian Oktafireza avatar  avatar Andreas Stefl avatar  avatar  avatar Doug Waldron avatar  avatar Jannik Waschkau avatar Khang avatar linpicio avatar Andrew Smith avatar JAELYS avatar Sam Jakos avatar makuta avatar Ishan Marikar avatar Matthew avatar Pavel avatar David Merfield avatar  avatar  avatar yanjixiong avatar Yao Cheng avatar yanching avatar Yaroslav Matveev avatar Andrea avatar Hugo Soucy avatar Boninall avatar luoye avatar K. F. Lee avatar dundich avatar  avatar Moritz Schiesser avatar Vikrant Sharma avatar  avatar Slava Dobromyslov avatar Brad Cavanaugh avatar BenSan avatar Gabriele avatar Jeidison Farias avatar  avatar  avatar Jeong Min O avatar  avatar  avatar Kindy Lin avatar Ivan Tcholakov avatar Mikhail Eremeev avatar  avatar Second Datke avatar Mingyi Chen avatar Omega Lightning avatar daboe01 avatar puruidong avatar André Lins avatar songshizhao avatar Robson Fagundes avatar ruiming avatar Y2G avatar Zap avatar

Watchers

Abhik Khanra avatar Fabien Ménager avatar Justin(Moo Chan) Song avatar Kenneth J Hughes avatar SwhGo_oN avatar Joseph Scarano avatar Muhammet Ali Köker avatar  avatar  avatar Herve Berard avatar  avatar

rtf.js's Issues

cant handle tables

the live sample rtf.html cannot convert the a rtf table into html table tags.

EMF support?

Thank you for making your library available.

The December 23, 2016 commit started down the path of adding EMF support. Are there plans to resume that effort?

ReferenceError: document is not defined

I am trying to use RTFJS in Node, and I get the following error...

Error
    at new RTFJSError (/mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:318:19)
    at /mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:208:19
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  name: 'RTFJSError',
  message: ReferenceError: document is not defined
      at Renderer.buildDom (/mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:10305:28)
      at /mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:206:36
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5),
  stack: 'Error\n' +
    '    at new RTFJSError (/mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:318:19)\n' +
    '    at /mnt/c/ivan/lab/catalogue/node_modules/rtf.js/dist/RTFJS.bundle.js:208:19\n' +
    '    at runMicrotasks (<anonymous>)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)'
}

Here's the code...

const RTFJS = require("../../node_modules/rtf.js/dist/RTFJS.bundle.js");

const rtf = `{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}
            {\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\lang9\\f0\\fs22 This \\fs44 is \\fs22 a \\b simple \\ul one \\i paragraph \\ulnone\\b0 document\\i0 .\\par
            }`;

            function stringToArrayBuffer(string) {
                var buffer = new ArrayBuffer(string.length);
                var bufferView = new Uint8Array(buffer);
                for (var i = 0; i < string.length; i++) {
                    bufferView[i] = string.charCodeAt(i);
                }
                return buffer;
            }

            RTFJS.loggingEnabled(false);
            // WMFJS.loggingEnabled(false);
            // EMFJS.loggingEnabled(false);

            const doc = new RTFJS.Document(stringToArrayBuffer(rtf));

            const meta = doc.metadata();
            doc
                .render()
                .then(function (htmlElements) {
                    console.log(meta);
                    console.log(htmlElements);
                })
                .catch(error => console.error(error));

Some problems with displaying WMF

Hi, thanks for the wonderful library, but i have some problems with displaying WMF:
some pictures rendered like this:
image
but should rendered like this:
image
Rtf file with problems inside zip
wmf.zip

support for commonjs

Can we have default exports, it's causing compilation error when used in CommonJS.

backslash newline not treated as equivalent to \par

I have some rtf that doesn't appear to parse correctly. Instead of the \par command it has the backslash character just before a newline, or 5c 0a if you are looking at the file with a hex editor. According to the Microsoft RTF specification (search for the word "carriage" to find it):

A carriage return (character value 13) or linefeed (character value 10) will be treated as a \par control if the character is preceded by a backslash. You must include the backslash; otherwise, RTF ignores the control word.

Not sure if this is a limitation of rtf.js or a bug somewhere in my rtf document or code but it appears that these are ignored.

Some fonts are not correctly shown

Description

When the rtf file contains fonts whose name are not ASCIIs, they are incorrectly parsed (and therefore incorrectly shown).

Reproduce

Load this file into the RTF demo page and check the logs.

[fonttbl][42] index = ¼Ð·¢Åé; alternative: null
[fonttbl][44] index = @¼Ð·¢Åé; alternative: null

Expected

The logs should be

[fonttbl][42] index = 標楷體; alternative: null
[fonttbl][44] index = @標楷體; alternative: null

State handling

While the state is handled correctly during parsing using pushState and popState, this data is not used for the buildDom function. This leads to properties which are applied within a paragraph but never removed when popState is called.

Consider the following example: {\rtf1\ansi\ansicpg1252 {Some Text }{\i italic text}{ text which shouldn't be italic} }

During parsing the \i keyword is applied, but when calling popState at the curly bracket it is not removed so the rest of the text is also italic.

Bullet Points (ListTable) not supported

Doesn't appear that bullet points are supported. I get a blank response back with no HTML elements, even for the stuff that isn't part of the bullet points.

Error when parsing rtf file with spaces in colortbl definition

Hi! Thanks for this wonderful plugin.

Today I encountered some problems in parsing some RTF files.
Ended up finding out that the problem lies in the definition of the colortbl property.

At some point, for not known reason, after the closing semicolon of a colordef, a white space is present. This generate the parsing error of the file.

I tested the plugin here with both versions of the file (with and without the whitespace), and only the one without the whitespace works.

Then I tested both files on several websites (like this one), and both versions were rendered correctly.

Adding <br /> in empty divs so new line is preserved when paste the html back MS Word

Our web application receives files in rtf format and use rft.js to convert rtf to html. Then we save the html version to OS clipboard with text/html format (using web clipboard API). So user could then paste the content to other OS native rich text editor (MS Word for example). We found all empty lines are lost during this process. Here is an example:

Converting rtf to html:
rtf:

{\rtf1 \ansi\ansicpg1252
{
\plain \f5 \fs24 \cf0  test line1
\par \pard \ltrpar\li0 \fi0 \ri0 \sl240 \sb0 \sa0 \par \pard \ltrpar\li0 \fi0 \ri0 \sl240 \sb0 \sa0 \par \pard \ltrpar\li0 \fi0 \ri0 \sl240 \sb0 \sa0 \par \pard \ltrpar\li0 \fi0 \ri0 \sl240 \sb0 \sa0 \plain \f5 \fs24 \cf0 test line4
}

rtf.js generated html:

<div><span style="font-size: 12pt"> test line1</span></div>
<div style="text-align: left"></div>
<div style="min-height: 12pt; text-align: left"></div>
<div style="min-height: 12pt; text-align: left"></div>
<div style="min-height: 12pt; text-align: left">
  <span style="font-size: 12pt">test line4</span>
</div>

The HTML looks good in the browser but when copy the html from web browser and paste it to a rich text editor (like MS Word), the three empty lines in between are missing.

Can we just add <br /> tag in empty divs like below, so all empty lines are preserved when pasting back to OS native rich text editor.

<div><span style="font-size: 12pt"> test line1</span></div>
<div style="text-align: left"><br /></div>
<div style="min-height: 12pt; text-align: left"><br /></div>
<div style="min-height: 12pt; text-align: left"><br /></div>
<div style="min-height: 12pt; text-align: left">
  <span style="font-size: 12pt">test line4</span>
</div>

Continuous integration

Since I added a test setup, it would be really nice if the test suite was run for every PR using some continuous integration system like travis ci. That way we could ensure whatever is being committed using a PR doesn't break users.

@tbluemel since you are the repository owner only you can make these kinds of changes, would you be interested in looking into this?

Provide minified bundles

Would it be possible to provide minified bundles, i.e. RTFJS.bundle.min.js etc, alongside the expanded ones in the dist/ directory, similar to how e.g. pdf.js does?

Japanese language renders incorrectly

I created some text in Japanese that I loaded into Windows 10 WordPad and saved as an RTF document. When I close and open the RTF document in WordPad everything appears to render correctly. When I load the RTF in RTF.js using the demo page in Chrome, Firefox, IE, or Edge it looks very different and appears corrupted.

Screenshot:
image

Using the demo page here: https://tbluemel.github.io/rtf.js/samples/01_rtf/rtf.html
And generated Japanese text here: http://generator.lorem-ipsum.info/_japanese

Any suggestions for how to have it render correctly? Is there some setting I need to configure?

The following is an example rtf file with Japanese text: japanese lorum ipsum.zip

Coverage reporting

@tbluemel I just added coverage reporting for our test suite. Could you please enable coveralls so we can get coverage reporting for PRs etc.? When you have added coveralls I can do the rest of the setup (sending coverage info from travis ci to coveralls.

Infinite Loop error

I am trying to use the library in Node, but I can't get it to work...

Here's the codesandbox. (The error can be seen here)

Or the code...

const RTFJS = require("rtf.js").RTFJS;

const rtf = `{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}
    {\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\lang9\\f0\\fs22 This \\fs44 is \\fs22 a \\b simple \\ul one \\i paragraph \\ulnone\\b0 document\\i0 .\\par
    }`;

function stringToArrayBuffer(string) {
  var buffer = new ArrayBuffer(string.length);
  var bufferView = new Uint8Array(buffer);
  for (var i = 0; i < string.length; i++) {
    bufferView[i] = string.charCodeAt(i);
  }
  return buffer;
}

RTFJS.loggingEnabled(false);
// WMFJS.loggingEnabled(false);
// EMFJS.loggingEnabled(false);

const doc = new RTFJS.Document(stringToArrayBuffer(rtf));

const meta = doc.metadata();
doc
  .render()
  .then(function(htmlElements) {
    console.log(meta);
    console.log(htmlElements);
  })
  .catch(error => console.error(error));

Unexpected token *

I installed [email protected] to my project and when I try to run my project it fails with a syntax error.

import * as RTFJS from './dist/RTFJS.bundle';
^
SyntaxError: Unexpected token *
I added "type": "module" to my package.json and added --experimental-modules to my start script.
I changed the version to 2.3.3
Everything I have attempted I get the same error. Any ideas on what I am doing incorrectly

WMF image not renderer correctly

The following WMF image is not renderer correctly. The error being displayed is:
WMFError: Unexpected end of file
Same result if I drag it into the live example on GitHub.
I had a quick look at the extensive logging, but couldn't find the cause.

If I open the same image in another viewer (I tried IrfanView), it is displayed correctly. The image is supposed to contain a cooking pot, seen from above.

Issue Image

Issue when converting RTF from clipboard to HTML

I have an issue when converting RTF from clipboard to HTML.
It tries to get a property of undefined:

image

It seems that the character is not found in the code page or something.
This is the RTF that I paste (The source PDF file from where I copy the data is attached here - I use Acrobat Reader DC to open and copy the data):

{\rtf1\ansi\ansicpg1253\uc1 {\fonttbl\f0\fswiss\fcharset0 Calibri;\f1\fswiss\fcharset0 Calibri,Bold;\f2\fswiss\fcharset0 Calibri,Italic;\f3\fswiss\fcharset0 Calibri,BoldItalic;\f4\fnil\fcharset136 \'53\'79\'6D\'62\'6F\'6C;}\pard\plain\ql\f0\fs20 {\fs22 Test }{\b\f1\fs22 123 }{\fs22 Test 123 Test }{\i\f2\fs22 123 }{\fs22 Test }{\b\i\f3\fs22 123 }{\fs22 Test 123 Test 123\par }{\f4\fs22 {\uc2\u61623 \'84\'68}\'20}{\fs22 A\par }{\f4\fs22 {\uc2\u61623 \'84\'68}\'20}{\fs22 B\par }{\f4\fs22 {\uc2\u61623 \'84\'68}\'20}{\fs22 C}}

...and I use this code:

                                    var rtf = clipboardData.getData('text/rtf');

                                    var stringToBinaryArray = function(txt) {
                                        var buffer = new ArrayBuffer(txt.length);
                                        var bufferView = new Uint8Array(buffer);
                                        for (var i = 0; i < txt.length; i++) {
                                            bufferView[i] = txt.charCodeAt(i);
                                        }
                                        return buffer;
                                    }
                                    
                                    var settings = {};
                                    var doc = new window.RTFJS.Document(stringToBinaryArray(rtf), settings);
                                    var parts = doc.render();
                                    var pastedHtml = $('<div/>').append(parts).html();

Any ideas?
I use the full code page file (cptable.full.js), so it is weird...
Probably it should render a ? character when the code-page symbol is not found tough, right? :^)

Module won't compile

Hi,

I am trying to use this module in an NX monorepo (http://nx.dev) using Angular 11, but the module will not compile. I get the following error messages:

> nx run portal:build
√ Browser application bundle generation complete.

Error: node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:7:5 - error TS2411: Property 'brush' of type 'Brush | undefined' is not assignable to string index type 'Obj'.

7     brush?: Brush;
      ~~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:8:5 - error TS2411: Property 'pen' of type 'Pen | undefined' is not assignable to string index type 'Obj'.

8     pen?: Pen;
      ~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:9:5 - error TS2411: Property 'font' of type 'Font | undefined' is not assignable to string index type 'Obj'.

9     font?: Font;
      ~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:10:5 - error TS2411: Property 'region' of type 'Region | undefined' is not assignable to string index type 'Obj'.

10     region?: Region;
       ~~~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:11:5 - error TS2411: Property 'path' of type 'Path | undefined' is not assignable to string index type 'Obj'.

11     path?: Path;
       ~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:8:5 - error TS2411: Property 'brush' of type 'Brush | undefined' is not assignable to string index type 'Obj'.

8     brush?: Brush;
      ~~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:9:5 - error TS2411: Property 'pen' of type 'Pen | undefined' is not assignable to string index type 'Obj'.

9     pen?: Pen;
      ~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:10:5 - error TS2411: Property 'font' of type 'Font | undefined' is not assignable to string index type 'Obj'.

10     font?: Font;
       ~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:11:5 - error TS2411: Property 'palette' of type 'Palette | undefined' is not assignable to string index type 'Obj'.

11     palette?: Palette;
       ~~~~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:12:5 - error TS2411: Property 'region' of type 'Region | undefined' is not assignable to string index type 'Obj'.

12     region?: Region;

the error messages go away if I change GDIContext.d.ts from

export interface ISelectedStyle {
    brush?: Brush;
    pen?: Pen;
    font?: Font;
    region?: Region;
    path?: Path;

    [key: string]: Obj;
}

to

export interface ISelectedStyle {
    brush?: Brush;
    pen?: Pen;
    font?: Font;
    region?: Region;
    path?: Path;

    [key: string]: Obj | undefined;
}

Is there something I am doing wrong or is the above fix actually necessary?

Small error on line 212

if (chp.fontfamily && doc._fonts[chp.fontfamily]) {

Should instead be as follows, because the value might very well be equal to 0:

if (chp.hasOwnProperty("fontfamily") && doc._fonts[chp.fontfamily]) {

For example the following RTF will not be correctly parsed:

{\rtf1\ansi\ansicpg1252\fromtext \fbidis \deff0
{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\colortbl\red0\green0\blue0;\red0\green0\blue255;}
\uc1\pard\plain\deftab360 \f0\fs20 Test Message\par
\par
Greets\par
s3rb31\par
}

Issue rendering images

Hi there,

I have an issue trying to load a RTF with image. I'm getting this error message in log:
findParentDestination() did not find destination pict-group

Does anyone knows what's happening?

The rest of the text is rendering fine, just the image doesn't load. Also, I'm using the online sample (https://tbluemel.github.io/rtf.js/samples/01_rtf/rtf.html)

Bellow a little fragment of the code:
{\rtf1\ansi\ansicpg1252\uc1\deff0\adeff0\deflang0\deflangfe0\adeflang0{\fonttbl {\f0\fswiss\fcharset0\fprq2{\*\panose 020B0604020202020204}Arial;} {\f1\froman\fcharset2\fprq2{\*\panose 05050102010706020507}Symbol;}} {\colortbl;\red0\green0\blue0;} {\stylesheet{\s0\ltrpar\itap0\nowidctlpar\ql\li0\ri0\lin0\rin0\cbpat0\rtlch\af0\afs24\ltrch\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}} {\info {\*\txInfo{\txVer 25.0.721.500}}} \paperw15000\paperh15840\margl1440\margt1440\margr1440\margb1440\deftab1134\widowctrl\lytexcttp\formshade\viewbksp1 {\*\background{\shp{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1\shplid1025{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn fillColor}{\sv 16777215}}{\sp{\sn fFilled}{\sv 1}}{\sp{\sn lineWidth}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn fBackground}{\sv 1}}{\sp{\sn fLayoutInCell}{\sv 1}}}}}\sectd \headery720\footery720\pgwsxn15000\pghsxn15840\marglsxn1440\margtsxn1440\margrsxn1440\margbsxn1440\pgbrdropt0\pard\ltrpar\itap0\nowidctlpar\ql\li0\ri0\lin0\rin0\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\tx9360\tx10080\plain\rtlch\af0\afs20\alang0\ltrch\f0\fs20\lang0\langnp0\langfe0\langfenp0 ---------------------\par From: JHON DOE USER \par To: XZTEST, RYAN \par Sent: 06/02/2022 11:52:28 MDT\par Subject: rtf - image in line \par\pard\ltrpar\itap0\nowidctlpar\ql\li0\ri0\lin0\rin0\plain\rtlch\af0\afs20\alang0\acf1\ltrch\f0\fs20\lang1024\langfe1024\langnp0\langfenp0\noproof\cf1{\txfielddef{\*\txfieldstart\txfieldtype0\txfieldflags147\txfielddataval1\txfielddata 30007800640034003600390061003100660033000000}{\*\txfieldtext \par {\*\txfieldend}}\par }\plain\rtlch\af0\afs20\alang1033\acf1\ltrch\f0\fs20\lang1033\langnp1033\langfe1033\langfenp1033\cf1{\pict{\*\picprop{\sp{\sn shapeType}{\sv 75}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn wzName}{\sv _tx_id_1_}}{\sp{\sn fLayoutInCell}{\sv 1}}}\wmetafile8\picw14764\pich5636\picwgoal8370\pichgoal3195\picscalex100\picscaley100\blipupi96 01000900000378b9020000005db902000000050000000b0200000000050000000c02d5002e02050000000701040000005db9 020040092000cc0000000000d5002e0200000000280000002e020000d500000001001800000000007c720500000000000000 00000000000000000000329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb329ffb32.....

proposed changes

Hey guys, first off great work on this, has been a huge help. However, I tried pulling down version 2.0 and the current master and I was having issues with EMFJS and WMFJS being undefined modules.

Because I didn't want to deal with that at the time I just pulled v1.0 (pre-typescript) and that was a bit more promising, but I did need to make the following changes to get it working:

screen shot 2018-03-26 at 12 49 09 pm

Just letting you guys know if you want to merge the changes in. Making logging more easily configurable would be a great change. And just adding module.exports to the rtf.js made it "requireable" as a module. And that parser.version check doesn't really make sense to me. Obviously I'm not as familiar with the code, but I'm not quite sure what the point of that is. It would throw an error on every RTF file I tried, and simply removing it seemed to parse the RTFs just fine.

Anyway feel free to reach out to discuss.

Best

Ordered list bullet list showing boxes in front on copying pastin from ms-outlook and ms-word

On copying-pasting ordered/bullet list from outlook/ms-word the rtf file does not render properly.

  • The first item of the list in the clipboard (the item from where the copying action began) renders with a bunch of boxes in front.

-The bullet list icons don't look quit right.
See the image below:
image
Please, find rtf files inside the zips that will replicate the issue
list_improper_render.zip
bullet_list_issue.zip

Original copied lists
image

Consider using fewer codepages?

According to the RTF spec (https://www.microsoft.com/en-us/download/details.aspx?id=10725), there are only a few codepages needed in RTF:

Code 				page | Name
-- | --
437 | United States IBM
708 | Arabic (ASMO 708)
709 | Arabic (ASMO 449+, BCON V4)
710 | Arabic (transparent Arabic)
711 | Arabic (Nafitha Enhanced)
720 | Arabic (transparent ASMO)
819 | Windows 3.1 (United States and Western Europe)
850 | IBM multilingual
852 | Eastern European
860 | Portuguese
862 | Hebrew
863 | French Canadian
864 | Arabic
865 | Norwegian
866 | Soviet Union
874 | Thai
932 | Japanese
936 | Simplified Chinese
949 | Korean
950 | Traditional Chinese
1250 | Eastern European
1251 | Cyrillic
1252 | Western European
1253 | Greek
1254 | Turkish
1255 | Hebrew
1256 | Arabic
1257 | Baltic
1258 | Vietnamese
1361 | Johab
10000 | MAC Roman
10001 | MAC Japan
10004 | MAC Arabic
10005 | MAC Hebrew
10006 | MAC Greek
10007 | MAC Cyrillic
10029 | MAC Latin2
10081 | MAC Turkish
57002 | Devanagari
57003 | Bengali
57004 | Tamil
57005 | Telugu
57006 | Assamese
57007 | Oriya
57008 | Kannada
57009 | Malayalam
57010 | Gujarati
57011 | Punjabi

As far as I can tell, rtf.js supports 145 code pages (searching for cptable[###] = in the RTFJS.bundle.js file), and eliminating ones that aren't necessary could cut down the bundle file size substantially.

Required control words for RTF Table

First off, awesome work! Glad to see our codepage library was helpful :)

https://jsfiddle.net/omyjg5a9/ generates an RTF table that Word 2016 and OSX TextEdit recognize as a borderless table. rtf.js doesn't seem to recognize this as a table :(

The generator is extremely simple, using a handful of control words for the table block. Here's an example with some comments prefixed by #:

{\rtf1\ansi
  \trowd\trautofit1 # start of row
  \cellx1\cellx2    # Word seems to need this, even though the widths are not used
  \pard\intbl       # mark before cells
    a\cell          # each cell is terminated with the \cell control word
    b\cell
  \pard\intbl\row   # end of row

  \trowd\trautofit1
  \cellx1\cellx2
  \pard\intbl
    1\cell
    2\cell
  \pard\intbl\row
}

A request for table support was already raised in #15 . Based on your understanding of the specification, do those control words suffice to represent a table? If so, would you accept a PR for table support based on those words?

Cannot read property 'dec' of undefined

This comes from Parser.js inside summarizeText
cptable[codepage].dec

Just migrated to Webpack 5 and this error showed up.
I think somehow cptable is not resolving.

some issues

  • [ ✓] # add class name

  • lost firstline and indent

Hyperlinks

Active hyperlinks inside the RTF document are not displayed

NPM

@tbluemel I have just published the latest version of rtf.js to npm to make it easier to use with modern projects. You can find it at https://www.npmjs.com/package/rtf.js . If you create an account as described here I can give you the permissions to publish packages.

How here works images?

I going throw your GETTING STARTED and library works fine only for text, it can't see images. Looking throw code example i see only onPicture setting, that doesn`t working at all, cuz console.logs in here never calling.
Can you explain me, and later for all in getting started how to use your good library with images?

Unable to Render Data from XMLHttpRequest

I'm working on a Chrome extension to read RTF files directly but I am running into an error when I try to render a file in the browser. I'm using this file for testing and it works when I drag and drop it into your demo page but I get Not a valid rtf document when I send the contents directly to RTFJS.Document-- if I log the contents to the console and compare them to the file itself in a diff viewer I don't see any differences. I've also tried using the .response and .responseText properties of the XMLHttpRequest without any difference. Am I improperly instantiating the RTFJS.Document object, is this an encoding issue or something else?

Unable to render Images of the original .rtf file

I have one sample .rtf file which included images and text.
I was able to successfully convert the .rtf to html but when rendered on the UI, I saw that I was able to see all the text from the original file but the images were nowhere to be found.

Can someone guide me on how to render images from the .rtf file after conversion?

Thanks.

Support non ansi character sets when converting hex codes to characters

The parser currently only supports the ansi charset, which leads to wrong hex code conversion when using the mac charset. For example the codes 0xD4 (212, left quote) and 0xD5 (213, right quote) actually correspond to ansi characters 145 and 146 which leads to text with wrong characters.

Unable to show tab spaces

Hi,

When my .rtf file contains list with sub-list it is not showing any tab space for the sub-list items. It is showing both the list and sub-list items as same.

For ex. In my .rtf file I've items as shown below.

  • First item
  • Second item
    - sub-item
    - sub-item2

and it is showing as

  • First item
  • Second item
  • sub-item
  • sub-item2

Could you please help me to fix this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.