Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:19:22+00:00 2026-06-06T07:19:22+00:00

I am using a terrible wrapper of PDFLib that doesn’t handle the problem PDFLib

  • 0

I am using a terrible wrapper of PDFLib that doesn’t handle the problem PDFLib has with cells that are more than the character limit (Which is around 1600 characters per cell).
So I need to break a large paragraph into smaller strings that fit neatly into the cells, without breaking up words, and as close to the end of the line as possible.
I am completely stumped about how to do this efficiently (I need it to run in a reasonable amount of time)

Here is my code, which cuts the block up into substrings based on character length alone, ignoring the word and line requirements I stated above:

SPE_* functions are static functions from the wrapper class,
SetNextCellStyle calls are used to draw a box around the outline of the cells
BeginRow is required to start a row of text.
EndRow is required to end a row of text, it must be called after BeginRow, and if the preset number of columns is not completely filled, an error is generated.
AddCell adds the string to the second parameter number of columns.

function SPE_divideText($string,$cols,$indent,$showBorders=false)
{
$strLim = 1500;
$index = 0;
$maxIndex = round((strlen($string) / 1500-.5));
$retArr= array();
  while(substr($string, $strLim -1500,$strLim)!=FALSE)
    {
    $retArr[$index] = substr($string, $strLim -1500,$strLim);
            $strLim+=1500;

            SPE_BeginRow();
            SPE_SetNextCellStyle('cell-padding', '0');
            if($indent>0)
              {

              SPE_Empty($indent);
              }
            if($showBorders)
              {
            SPE_SetNextCellStyle('border-left','1.5');
            SPE_SetNextCellStyle('border-right','1.5');

              if($index == 0)
                {
                SPE_SetNextCellStyle('border-top','1.5');
                }
                if($index== $maxIndex)
                  {
               SPE_SetNextCellStyle('border-bottom','1.5');

                  }
              }

            SPE_AddCell($retArr[$index],$cols-$indent);
            SPE_EndRow();
            $index++;
    }
}

Thanks in advance for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:19:24+00:00Added an answer on June 6, 2026 at 7:19 am

    Something like this should work.

    function substr_at_word_boundary($string, $chars = 100)
    {
        preg_match('/^.{0,' . $chars. '}(?:.*?)\b/iu', $string, $matches);
        $new_string = $matches[0];
        return ($new_string === $string) ? $string : $new_string;
    }
    
    $string = substr_at_word_boundary($string, 1600)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that browser detection using the userAgent property is a terrible idea because
i am using jquery library in my project.I have terrible problem with jquery tabs.Solutions
(Using java) My old explanation of the problem is terrible so I'll re word
I'm using the NetBeans GUI builder to handle my layout (I'm terrible with LayoutManagers)
I'm making a project using GAE, and have a terrible problem. I wanted to
I'm trying to parse an HTML file that has terrible (believe me, it is)
I'm trying to dive into the quite frankly terrible world of unit testing using
Using Nunit, I want to be able to write a test fixture that will
Using top it's easy to identify processes that are hogging memory and cpu, but
I am using python's csv module to extract data from a csv that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.