0

I have an issue where I have 2 linked blocks. Once there is a max of characters(before they shrink to fit) it moves to my next linked block. The problem is that if there is a lot of text pushed to the next block it becomes very tiny. Is there a way to divide all characters evenly and each box? Even if it shrinks that is ok, just needs to look the same. Image and code below of example:

https://i.stack.imgur.com/Kwn74.png

public function addTextToMultiBlock($text,$baseBlockName,$numberOfBlocks)
{
    $tf = 0;
    for ($i = 1; $i <= $numberOfBlocks; $i++)
    {
        $optlist ="encoding=unicode textflowhandle=" . $tf;
        $tf = $this->p->fill_textblock($this->page, $baseBlockName.$i, $text, $optlist);
        //Set text to null ( $tf handle holds extra text from now on )
        $text = null;
        if ($tf == 0) {
         trigger_error("Warning: " . $this->p->get_errmsg() . "\n");
         break;
        }
    $reason = (int) $this->p->info_textflow($tf, "returnreason");
    $result = $this->p->get_parameter("string",  $reason);
    //Break if all text is placed
     if ($result == "_stop")
        {
            $this->p->delete_textflow($tf);
           break;
        }
    }
}

//call below to block
    if(!empty($this->orderData->remarks))
    {
    $addRemarks.= $this->orderData->remarks;
    $helper->addTextToMultiBlock($this->orderData->remarks, 'info', 2);
    }
    else
    {
        //nothing
    }
Jcdevelopment
  • 51
  • 2
  • 8
  • `Is there a way to divide all characters evenly and each box?` Not really. Which takes up more space, 20 `w`s or 40 `i`s? – SubjectCurio Mar 17 '14 at 17:51

2 Answers2

0

What I am thinking is to do a count of the words:

<?php

// SET THE NUMBER OF BOXES YOU WANT
$boxes = 2;

// SAMPLE INPUT STRING
$string = 'Life it seems to fade away, drifting further every day.  Getting lost within myself.  Nothing matters no one else.';

// MATCH EACH WORD AND STORE IT INTO AN ARRAY
preg_match_all('/\S+/', $string, $matches);

// COUNT HOW MANY WORDS WE HAVE TOTAL
$word_count = count($matches[0]);

// DIVIDE THE TOTAL WORDS BY THE NUMBER OF BOXES
// TO FIND HOW MANY WORDS WE SHOULD HAVE IN EACH BOX
$words_per_box = round($word_count / $boxes);

// SPLIT THE ARRAY OF WORDS INTO CHUNKS BASED ON THE
// - NUMBER OF WORDS PER BOX THAT WE SHOULD HAVE   
$chunks = array_chunk($matches[0], $words_per_box);

// START OUTPUTTING THE TABLE
print '
    <table border=1 cellpadding=5 cellspacing=0>
    <tr>';

// LOOP THROUGH EACH CHUNK OF WORDS AND TURN IT BACK
// - INTO A STRING THAT WE CAN PRINT OUT
foreach ($chunks AS $word_block) {
    //PRINT BLOCK TEXT
    print '
      <td>'.implode(' ', $word_block).'</td>';  
}

// CLOSE OUT THE TABLE
print '
    </table>';

This outputs the following:

<table border="1" cellpadding="5" cellspacing="0">
<tr>
  <td>Life it seems to fade away, drifting further every day.</td>
  <td>Getting lost within myself. Nothing matters no one else.</td>
</table>

This is not going to be a perfect solution, but hopefully it gets you pretty darn close.

Quixrick
  • 3,190
  • 1
  • 14
  • 17
0

you should check the "fitmethod" property in the block. If the fitmethod is set to "auto" the complete text will be fit to the textlblock.

From the PDFlib cookbook sample: http://www.pdflib.com/pdflib-cookbook/block-handling-and-pps/linked-textblocks/

Please see the following comment before filling the block:

         * "fitmethod=clip" to clip the text when it doesn't fit completely
         * into the block while avoiding any text shrinking.
Rainer
  • 2,013
  • 1
  • 10
  • 7