[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

12/06/2008 at 02:17PM PST, ID: 23963414
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.7

Using PHP to Convert HTML to UTF-8 for PDF output

Asked by samiam80304 in Web Application Hosting, WebApplications

Tags: php pdf utf-8

I am working with a PHP class called mPDF, which is a PHP class that generates PDF files from UTF-8 encoded HTML.  It works great, but everything going into it MUST be UTF-8, which is the thing tripping me up I think!

So here is some quick test code that works:

1      <?php
2      define('_MPDF_PATH','mpdf/');
3      include("mpdf/mpdf.php");
4
4      //this is 6x9 book format
6      $mpdf=new mPDF('en-US','Royal','11','dejavuserifcondensed',32,25,27,25,16,13 );
7
8      include "poemfile1.php";
9      $mpdf->WriteHTML($html);
10      $mpdf->Output('mpdfA.pdf','I');
11      exit;
12      ?>

poemfile1.php looks like this:
<?php
$html='
<h1>Title</h1>
<pre>
lots of text</pre>';
<?php>

Using textpad I had to save poemfile1.php AS UTF-8 format. Then when I run the script, my pdf comes out just fine.

Now, what I really want is to write to a file called 'selections.txt' which will contain one or more poems selected by the user and which come from mySQL database.  At this point I haven't brought the db into the picture yet.  Right now, I just want to create the selections.txt file, write to it one or more poems, and then create my pdf.  If I can get *that* to work, I'll move on to selecting from the DB!

So after googling and reading tons of stuff about PHP and UTF-8, I am now totally boggled.  Here is the test code I am trying in the attempt to CREATE a file and save it as UTF-8 format:

1      <?php
2      //iconv_set_encoding("output_encoding", "UTF-8");
3      //iconv_set_encoding("input_encoding", "UTF-8");
4      //var_dump(iconv_get_encoding('all'));
5      //==============================================================
6      define('_MPDF_PATH','mpdf/');
7      include("mpdf/mpdf.php");
8      $selections_file="selections.txt";
9      $input_file="cartog3.htm";
10      //$file_array= array("cartog3.htm","prowl3.htm");
11
12      //this is 6x9 book format
13      $mpdf=new mPDF('en-US','Royal','11','dejavuserifcondensed',32,25,27,25,16,13 );
14
15      $input=file_get_contents($input_file);
16      //echo $input;
17      $fh=fopen($selections_file,"w") or die("can't open file");
18
19      //foreach ($file_array as $poetry_file) {
20            //fwrite($fh,utf8_encode($input));
21            fwrite($fh,iconv("ISO-8859-1", "UTF-8", $input));
23            fclose($fh);
24            //file_put_contents($selections_file, $input, FILE_TEXT|FILE_APPEND);
25      //}
26
27      $fh=fopen($selections_file,"r") or die("can't open file");
28      $html=fread($fh, filesize($selections_file));
29      fclose($fh);
30      echo $html;
31
32      $mpdf->WriteHTML($html,2);
33      $mpdf->Output('mpdfA.pdf','I');
34      exit;
35      ?>

You can see from various commented lines different things I've been trying.  I have saved the file cartog3.htm as a UTF-8 file and it now contains ONLY html and text (unlike the version that works that includes a PHP file with PHP information in it).  However, when I echo $html (on line 30), my text is preceded by the characters:  

And the PDF of course is just a bunch of junk characters.

Can anybody help?  I get the feeling that I am somehow making it harder than it needs to be?

Thanks!
[+][-]12/06/08 03:30 PM, ID: 23114055

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Web Application Hosting, WebApplications
Tags: php pdf utf-8
Sign Up Now!
Solution Provided By: solutionDriver
Participating Experts: 1
Solution Grade: B
 
 
[+][-]12/08/08 01:35 PM, ID: 23124532

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/08/08 04:04 PM, ID: 23125702

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091028-EE-VQP-85 - Hierarchy / EE_QW_3_20080625