0

From a REST API call I get a description text in RTF format. Just as a test, I have added just a small bitmap image (2x3 pixels in red) to that description. This returns the following RTF format string:

{\rtf1\fbidis\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil Arial;}}{\colortbl;} \pard\fi0\li0\ql\ri0\sb0\sa0\itap0 {\pict\picwgoal30\pichgoal45\dibitmap0\wbmwidthbytes8\picw2\pich3 28000000020000000300000001002000000000001800000000000000000000000000000000000000241CED00241CED00241CED00241CED00241CED00241CED00}\par}

If a put this string in an ascii file and set the extension to *.rtf and open it in WordPad I get the expected result, a document with just a small red image.

I would like to be able to convert this RTF string to HTML using PHP. I have tried the roundcube/rtf-html-php package (ExtractImage() and PrintImage()), even modified it, without success. It looks like the RTF file string doesn't include the full bitmap file, maybe it's missing the header. Because if I open the bitmap file in a hex editor, I can see additional 14 bytes in the beginning compared to the data in the RTF file string:

enter image description here

I have looked at imagecreatefromstring() but it also requires the full image file as input.

How can I solve this?

0

1 Answer 1

0

From the RTF specification:

\dibitmapN - Source of the picture is a Windows device-independent bitmap. The N argument identifies the bitmap type (must equal 0).

However the bitmap does not include the BMP header. After extracting the raw pict data, the header must be added before the image can be viewed.

However, BMP is not a web ready picture format. Therefore, the PHP application must first convert it to a suited format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.