Menu

subscript, superscript

PhpRtf
Anonymous
2012-06-19
2013-04-30
  • Anonymous

    Anonymous - 2012-06-19

    I need create subscript, superscript.

    I edit file Element.php

     public static function convertTagsToRtf($text, $charset)
        {
            $search = array(
                // bold
                '/<STRONG[ ]*>(.*?)<\/STRONG[ ]*>/smi',
                '/<B[ ]*>(.*?)<\/B[ ]*>/smi',
                // italic
                '/<EM[ ]*>(.*?)<\/EM[ ]*>/smi',
                '/<I[ ]*>(.*?)<\/I[ ]*>/smi',
                // underline
                '/<U[ ]*>(.*?)<\/U[ ]*>/smi',
                // break
                '/<BR[ ]*(\/)?[ ]*>/smi',
                '/<LINE[ ]*(\/)?[ ]*>/smi',
                // horizontal rule
                '/<HR[ ]*(\/)?[ ]*>/smi',
                '/<CHDATE[ ]*(\/)?[ ]*>/smi',
                '/<CHDPL[ ]*(\/)?[ ]*>/smi',
                '/<CHDPA[ ]*(\/)?[ ]*>/smi',
                '/<CHTIME[ ]*(\/)?[ ]*>/smi',
                '/<CHPGN[ ]*(\/)?[ ]*>/smi',
                // tab
                '/<TAB[ ]*(\/)?[ ]*>/smi',
                // bullet
                '/<BULLET[ ]*(\/)?[ ]*>/smi',
                '/<PAGENUM[ ]*(\/)?[ ]*>/smi',
                '/<SECTNUM[ ]*(\/)?[ ]*>/smi',
    //            '/<PAGE[ ]*(\/)?[ ]*>/smi',
    //            '/<SECT[ ]*(\/)?[ ]*>/smi'
                 '/<SUP[ ]*>(.*?)<\/SUP[ ]*>/smi',
                 '/<SUB[ ]*>(.*?)<\/SUB[ ]*>/smi',
            );
            $replace = array(
                // bold
                '\b \1\b0 ',
                '\b \1\b0 ',
                // italic
                '\i \1\i0 ',
                '\i \1\i0 ',
                // underline
                '\ul \1\ul0 ',
                // break
                '\line ',
                '\line ',
                // horizontal rule
                '{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}',
                '\chdate ',
                '\chdpl ',
                '\chdpa ',
                '\chtime ',
                '\chpgn ',
                // tab
                '\tab ',
                // bullet
                '\bullet ',
                '\chpgn ',
                '\sectnum ',
    //            '\page ',
    //            '\sect '
                '{\super \1\super0}',
                '{\sub \1\sub0}',
            );
            $text = preg_replace($search, $replace, $text);
            $text = html_entity_decode($text, ENT_COMPAT, $charset);
            return $text;
        }
    
     
  • 0b101010

    0b101010 - 2012-08-04

    Thanks, this should be quite useful to me!

    I also added this to $search

    '/<PAGETOTAL[ ]*(\/)?[ ]*>/smi',
    

    and this to $replace

    '{\field{\*\fldinst {NUMPAGES }}}',
    

    so that i could put "page <pagenum> / <pagecount>" into my document footers (tested & works with word viewer 2003 & word 2007).

     
  • Steffen Zeidler

    Steffen Zeidler - 2012-10-04

    I tried to add <pagetotal>, but it did not work on the first page in the header. I don't know why, may be you know an answer to it…

     
  • 0b101010

    0b101010 - 2012-10-04

    Hi sigmaz,

    just to clarify, when you say "did not work on the first page in the header" do you mean:

    1. It does not work for you at all anywhere in the document (I remember vaguely was using it in footers with other text…  ).
    2. It works, but not the in the header of the first page

    Thanks for trying it out, I can post a patch & working example if it will help? (it will probably take me a few days, sorry)

     

Log in to post a comment.