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 7646705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:16:35+00:00 2026-05-31T10:16:35+00:00

I wrote a small PHP script which does a branding on a present PDF

  • 0

I wrote a small PHP script which does a “branding” on a present PDF file. This means on every page I put a string like “belongs to ” at a special position. Therefor I use Zend_Pdf out of the Zend Framework.
Because the script is used in German language area, in one line there I use the special character “ö” (“Gehört zu “).

On my local machine (Windows, XAMPP) the script worked fine, but when moving it to my hoster’s webspace (some Linux), the string breaks at “ö”. That means in my PDF on appears “Geh”.

The code is this:

        if (substr($file, strlen($file) - 4)  === '.pdf') {
            $name = $user->GetName;
            $fontSize = 12;
            $xTextPos = 100;
            $yTextPos = 10;

            set_include_path(dirname(__FILE__)); // set include_path for external library Zend Framework
            require_once('Zend' .DS . 'Pdf.php');
            $pdf = Zend_Pdf::load($file);
            $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

            $branding = 'Gehört zu ' . $name; // German for: 'Belongs to ', problem with 'ö'

            foreach ($pdf->pages as &$page) {
                $page->setFont($font, $fontSize);
                $page->drawText($branding, $xTextPos, $yTextPos);
            }
        }

I guess the problem is related to some kind of default charset or language setting of the PHP environment. So I searched here and tried out:

            $branding = utf8_encode('Gehört zu ') . $name;

…and I made some experiments with functions like html_entity_decode but nothing helped and I decided stopping groping in the dark and open an own question.

Looking forward to any hints. Thank you in advance for your help!

EDIT: Meanwhile I found the same (?) problem, solved on a German forum. But if I do it like they say…

             $branding = mb_convert_encoding('Gehört zu ', 'ISO-8859-1') . $name;

… the resulting branding in the PDF is “Gehrt zu “. The “ö” is skipped now.

For this I found another hint on the Zend issue tracker.

I sum up, that I can drop all UTF8 things and concentrate on Latin-1 AKA ISO 8859-1.

I still don’t understand why the code worked on my Windows + XAMPP and now crashes on my hoster’s Linux.

  • 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-05-31T10:16:36+00:00Added an answer on May 31, 2026 at 10:16 am

    Your guess is right, the problem is related to encoding. Where exactly the encoding is messed up is hard to say from afar. I’m assuming you work not only with Zend_Pdf, but also have the MVC in place (meaning a complete Zend_Application).

    You should check if your application serves pages as UTF-8, by setting:

    resources.view.encoding = "UTF-8"
    

    and also placing the appropriate meta-tags in your layout/view.

    Depending on what Editor you use, your files may be encoded in a different encoding. You can use Notepad++ on Windows to check your file-encoding and for converting it to UTF-8 (don’t just set the encoding to UTF-8, this might mess up your file!) if necessary. I recommend using Eclipse with text file encoding set to “UTF-8” (Preferences > General > Workspace) to make sure your code files are encoded in UTF-8.

    Now comes the crucial part:

    Zend_Pdf_Page::drawText(string $text, float $x, float $y, string $charEncoding)
    

    See that last argument… set it. If you’re lucky, you can skip the previous stuff and just set the encoding there.

    edit: I missed something. Database connections. You should check the encoding there too. I frequently work with MS SQL Server, which uses Latin-1 internally; not setting driver_otpions.CharacterSet can mess up stuff pretty bad too. This might be relevant, if you have soemthing like Gehört zu: Günther, where the Name Günther is fetched from db.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small PHP script to edit the site news XML file. I
I wrote this small page and for some reason when I cilck on the
I've built a script in PHP for a small shop that does a few
I Wrote a small php script to convert string to HEX but i have
I am trying to use php. I wrote a small script as instructed in
I wrote a small shell script based on an example I found here: https://bbs.archlinux.org/viewtopic.php?id=36305
I have this small PHP script: <?php session_start(); $var = array(); $var['key'] = 'Var
I wrote this small C++ program and built it(Release) #include<iostream> int main(){ std::cout<<Hello World;
So I've wrote a small script to download pictures from a website. It goes
Preface . I wrote a small application in C that plays a video file

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.