0

The goal is to have php edit an rtf file to insert an image from the server by building some rtf code which according to other questions should insert the image:

{\pict\wmetafile8\picw[N]\pich[N]\picwgoal[N]\pichgoal[N] [BYTES]}

        $picture_tag = "picture"; //\pict
        $image_type = "8"; //\wmetafile[N]
        $image_width = "100"; //\picw[N]
        $image_height = "100"; //\pich[N]
        $target_width = "100"; // \picwgoal[N]
        $target_height = "100"; // \pichgoal[N]
        $image_hex = bin2hex(file_get_contents("assets/image.jpeg")); // [BYTES]

        //insert the variables into the rtf code:
        $cd_image = \pict".$picture_tag."\wmetafile".$image_type."\picw".$image_width."\pich".$ima 
        ge_height."\picwgoal".$target_width."\pichgoal".$target_height." 
        ".$image_hex."}";

Then i use file_put_contents() to add that cd_image string into the rtf file.

But the only thing that shows up when i open the rtf file is

"ffd8ffe000104a46494600010101012c012c0000ffe11b044578696600004d4d002a00000008000d010e000200000095000000aa010f00020000000600000140011000020000001500000146011200030000000100010000011a0005000000010000015c011b0005000000010000016401280003000000010002000001310002000000200000016c01320002000000140000018c013b00020000000d000001a0021300030000000100010000829800020000001b000001ae876900040"

i think im missing something

Snel23
  • 1,381
  • 1
  • 9
  • 19
  • done some work with RTF it is horrible, do you really need this format? –  May 15 '19 at 01:22
  • I need php to build a word doc, and starting from an rtf template is the only way i found. I was able to replace text and delete parts from the rtf, but not add images – Ioan Yamakov May 16 '19 at 00:29
  • building word docs from php is 100% easier, no idea why you want to to use rtf here at all. https://github.com/PHPOffice/PHPWord has everything you need –  May 16 '19 at 00:32

0 Answers0