Link to home
Start Free TrialLog in
Avatar of Chimeraza
ChimerazaFlag for South Africa

asked on

How do I fix this DOMPDF error; Unexpected character in input: ''' (ASCII=39)

When I test DOMPDF on my localhost server it works fine.  

I am printing a pdf file from a php file called demo_php.php which contains CSS, PHP and HTML combined.

When I upload this to my webserver it gives the following two errors:
1)
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/content/t/e/a/*****/html/db/classes/dompdf/lib/class.pdf.php on line 4051
2)
Parse error: syntax error, unexpected $end, expecting ']' in /home/content/t/e/a/*****/html/db/classes/dompdf/lib/class.pdf.php on line 4051

Note: the ***** are added for privacy reasons - they can be replaces with the domain name without www or .com

I can attach source code if required but i will need to edit it heavily to protect privacy....so if anyone can solve or give me pointers to solving this without source code, it would be greatly appreciated!!

Thanks in advance!

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Let's try this... Isolate line 4051 and show us that.

Is that the only line that gets the errors?

Unexpected $end means that you're missing some curly braces somewhere.  Possibly on or near line 4051
Avatar of Chimeraza

ASKER

Hi, thanks for your prompt response!

I have attached line lines preceding and after 4051...

This code is the standard dompdf code which I have not edited at all..

Also, it works perfectly offline...only bugs on the web..

Let me know if there is anything else you need..

  function  restoreState($pageEnd =  0) {
 
    if  (!$pageEnd) {
 
      $n =  $this->nStateStack;
 
LINE 4051 = $this->currentColour =  $this->stateStack[$n]['col'];
 
      $this->currentStrokeColour =  $this->stateStack[$n]['str'];
 
      $this->objects[$this->currentContents]['c'].=  "\n".$this->stateStack[$n]['lin'];
 
      $this->currentLineStyle =  $this->stateStack[$n]['lin'];
 
      unset($this->stateStack[$n]);
 
      $this->nStateStack--;
    }
 
    $this->objects[$this->currentContents]['c'].=  "\nQ";
  }

Open in new window

also...don't think im missing curly-brackets anywhere...have tested the demo_php.php file and it renders perfectly on its own..
I'm using this link/button to call the dompdf function:


<a class="button" target="blank" href="test/demo_php.php">HTML</a>] [<a class="button" href="/db/classes/dompdf/dompdf.php?base_path=www%2Ftest%2F&input_file=www%2Ftest%2Fdemo_php.php">Click here to print</a>

Open in new window

sorry...seems impossible to edit your comments...just ignore the link to view the html in the above code...

I'm just using the link that says 'Click here to print'
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It occurs on line 50..but there are tons of them in the document
This is the generic dompdf code so I assume there isn't anything incorrect with it..I think they've tested it thoroughly..

I have included the php file that I'm sure the errors are coming from..  This is the file that is supposed to be rendered into html and converted into pdf.  Also this file converts to pdf nicely on my localhost but gives the error on the webserver.

Thanks for this help!
demo-php.txt
Looking at demo-php, I see that there are some include statements in there with relative path addresses.  Obviously I cannot test this, but you might want to check carefully to see that the paths are all resolved correctly.  You can add error_reporting(E_ALL) to your script to help find this.

And what is this construct?

<script type="text/php">

I am not familiar with that.

Best, ~Ray
the <script type="text/php"> is used to insert the footer into the pdf file...I don't really understand it.. just found it out some how - you need to use it.

I actually managed to solve the problem... I opened the big file (called class.pdf.php) and ran a replace all with the single-quotes (') for double quotes (")...  For anyone else doing this...there is one place that brings up three double quotes in a row (search for it after you do a replace all)...which you can replace with single quote, double quote, single quote ('"').

After doing this, I tried it again and it worked.  So obviously, like you said, there was somewhere in the file that was bringing up errors due to the single quote..

Thanks for your guidance and effort!
Like I commented below, replace all the single quotes with double quotes in the class.pdf.php file and becareful of the one instance of 3 double quotes in a row (change to single double single quotes)
A lot of the XML-related PHP things will have issues with the character entities.  Glad you found a workaround.  Best, ~Ray