Is there a way in PHP to access compressed RTF and output RTF code
Asked Answered
R

2

10

Is there a way in PHP to access compressed RTF and ouput RTF code to the browser?

I have a text column in SQL and I would like to extract the RTF from it - I have managed to output the data as 0x1F8B

I believe this data is compressed RTF - http://www.freeutils.net/source/jtnef/rtfcompressed.jsp

Using [MS-OXRTFCP]: Rich Text Format (RTF) Compression Algorithm http://msdn.microsoft.com/en-us/library/cc463890%28v=exchg.80%29

Sample data :

0x1F8B0800000000000000654E316EC3300CEC5CA07FE0D6AD909D1628E0A1C8D01F74E422CB94CD46A11C4A6E5018F97B6967EC72381EC9BB5B516B6CD04BE11DC23C36ED5B8B03C5E8364C5EC6C61D0E2BC62CB5F6C988C358AE5C0AC6592F2DC630792D541D1C957DEA6E76D260144EFF57B7A7C715434E59CD0A3A541A1C8E4A240EFBB490EBEC027F98AE2796E11597D0E0EC75C013D1BC8360F1EF0EC316B115695BF89A08CE390B70816ABC571EA74AA542EEBF295460D975642B069F5EEBF45C6CB27707E5F4FBB14558EC1D83D9EEEC28D9BE142E8B59719697BB6C051FFE00D09796A337010000

And this looks like what I want but its in VB http://www.vbforums.com/attachment.php?attachmentid=87371&d=1326754610

Rockwell answered 29/5, 2012 at 13:36 Comment(2)
As long as "compressed RTF" has lossless compression (which would make sense), there is a way to access compressed RTF and output it as uncompressed RTF. The way is to uncompress it. Does that answer your question?Boohoo
I tried gzdeflate and got U‘¹ D1D[ÌaBsõ_ÒòÃ%ABˆy3àÜ€¥Â}P;ÏÈNÉ6 ¥¯¼Pé6<Ì[€cÜL”áœÅú“Ÿ¶ÞquµN£s±Ó#$548±’Ní’XŽ“Ò÷(oKMÅ‚¦HÝã2š~o¹¯%᥊ÓP¥0§ÆÂt±êU7-R@æž{–†Â‡[|¥ßy»ÿh~ÄÐÁ@6¾d®Ë'në`EñF. öìpCŠÝQ—˜ënöqƒ‹ú"Å°Ÿñ[1êŽ!V(7Q¦õ‘o̲fƒÌÀZ†—YävbÝSÞÝI·|ãÚ37 ]7ÚMg¾¼ïü>øRockwell
S
7

Your data sample is gzipped data, use gzdecode to decode it. You'll need to pass a binary string not the hex string supplied(use hex2bin or pack to convert)

if (!function_exists(hex2bin)){
    function hex2bin($hexStr){
        return pack('H*', $hexStr);
    }
}
$rtf = gzdecode(hex2bin('1F8B0800000000000000654E316EC3300CEC5CA07FE0D6AD909D1628E0A1C8D01F74E422CB94CD46A11C4A6E5018F97B6967EC72381EC9BB5B516B6CD04BE11DC23C36ED5B8B03C5E8364C5EC6C61D0E2BC62CB5F6C988C358AE5C0AC6592F2DC630792D541D1C957DEA6E76D260144EFF57B7A7C715434E59CD0A3A541A1C8E4A240EFBB490EBEC027F98AE2796E11597D0E0EC75C013D1BC8360F1EF0EC316B115695BF89A08CE390B70816ABC571EA74AA542EEBF295460D975642B069F5EEBF45C6CB27707E5F4FBB14558EC1D83D9EEEC28D9BE142E8B59719697BB6C051FFE00D09796A337010000'));

Here is the raw data.

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fnil\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\keep\keepn\sa80\cf1\f0\fs22 The moon is the brightest object in the \i\f1 Earth's \i0\f0 sky?\par
\par
\cf0\par
Another question.\par
}

And this is the rendered text.

The moon is the brightest object in the Earth's sky?

Another question.

I'm not sure if you only want the raw rtf or rendered, take a look at Free (preferably) PHP RTF to HTML converter? if you want the rtf in html.

Secondary answered 14/6, 2012 at 3:33 Comment(2)
Great going. Hope you get the bounty :)Watering
OMG amazing! - the bounty has disappeared on this question - I want to award to you - can I reassign?Rockwell
B
6

I can't tell you if

0x1F8B0800000000000000654E316EC3300CEC5CA07FE0D6AD909D1628E0A1C8D01F74E422CB94CD46A11C4A6E5018F97B6967EC72381EC9BB5B516B6CD04BE11DC23C36ED5B8B03C5E8364C5EC6C61D0E2BC62CB5F6C988C358AE5C0AC6592F2DC630792D541D1C957DEA6E76D260144EFF57B7A7C715434E59CD0A3A541A1C8E4A240EFBB490EBEC027F98AE2796E11597D0E0EC75C013D1BC8360F1EF0EC316B115695BF89A08CE390B70816ABC571EA74AA542EEBF295460D975642B069F5EEBF45C6CB27707E5F4FBB14558EC1D83D9EEEC28D9BE142E8B59719697BB6C051FFE00D09796A337010000

is actually compressed RTF data. But if so, the Zarafa's PHP MAPI Extension offers a function to decompress it: mapi_decompressrtf().

Boohoo answered 29/5, 2012 at 13:52 Comment(5)
I saw that but - didnt see a download for it?Rockwell
You find it here: git.zarafa.com/zcp/zcp/trees/master/php-ext / git://git.zarafa.com/zcp/zcp.gitBoohoo
@Rob: Are you looking for a non-binary solution to your problem? How much time can you invest for a PHP port?Boohoo
I am looking for a non-binary solution (web site accessing an existing DB) - the solution is an innovation so dont have much backing at the moment but loads of time (no $$) - but if we did go ahead it could be very goodRockwell
I'd start with a port of that decompress stream thingy. Should be possible to port it to PHP and solve the issue for you. Ideally create a github repro and start with writing tests. Would be good to have some testdata as well.Boohoo

© 2022 - 2024 — McMap. All rights reserved.