CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Using korean fonts in all PDF operations
Pages: [1]

Author Topic: Using korean fonts in all PDF operations  (Read 2862 times)

jamie

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 6
Using korean fonts in all PDF operations
August 27, 2013, 12:10:45 pm
With help from Mathieu I've manged to get korean fonts working in both PDF letters and PDF labels. Following is a description of the process. At the end I offer some suggestions on how to make this configurable.  Comments are welcome!

CiviCRM uses several PDF libraries/binaries. The first step in adding a font is to understand which libraries is being used. For printing PDF letters, CiviCRM uses DOMPDF. If you want Korean fonts, you'll be best off changing that to use wkhtmltopdf instead. Mathieu has excellent directions for handling korean fonts with wkhtmltopdf.

If you can't use wkhtmltopdf, there are some directions for adding fonts to dompdf, but I haven't tested them.

That takes care of PDF letters. Unfortunately, mailing labels use a different library: tcpdf.

To add korean fonts to tcpdf, you have to install them on your server (as descriibed in Mathieu's post). Then navigate to:

Code: [Select]
packages/tcpdf/
And run:

Code: [Select]
php -r 'include("config/tcpdf_config.php"); include("include/tcpdf_fonts.php"); include("include/tcpdf_static.php"); TCPDF_FONTS::addTTFfont("/usr/share/fonts/truetype/baekmuk/gulim.ttf", "", "", 32, "", 3, 1, false);'
baekmuk is a font family that comes with four fonts: gulim, dotum, batang, and hline. The command above installs just gulim. You could repeat with all four.

Next, you have to patch civicrm. Navigate to:

Code: [Select]
CRM/Utils/PDF
And edit Label.php

Find this section:

Code: [Select]
function getFontNames() {
    // Define labels for TCPDF core fonts
    $fontLabel = array(
      'courier' => ts('Courier'),
      'helvetica' => ts('Helvetica'),
      'times' => ts('Times New Roman'),
      'dejavusans' => ts('Deja Vu Sans (UTF-8)')
 );

And add gulim so it looks like this:

Code: [Select]
$fontLabel = array([i][/i]
     'courier' => ts('Courier'),
     'helvetica' => ts('Helvetica'),
     'times' => ts('Times New Roman'),
     'dejavusans' => ts('Deja Vu Sans (UTF-8)'),
     'gulim' => ts("Baekmuk")
   );

Or apply this patch:

Code: [Select]
diff --git a/Label.php.old b/Label.php
index 19b873c..3753159 100644
--- a/Label.php.old
+++ b/Label.php
@@ -245,6 +245,7 @@ class CRM_Utils_PDF_Label extends TCPDF {
       'helvetica' => ts('Helvetica'),
       'times' => ts('Times New Roman'),
       'dejavusans' => ts('Deja Vu Sans (UTF-8)'),
+      'gulim' => ts("Baekmuk")
     );
     $tcpdfFonts = $this->fontlist;
     foreach ($tcpdfFonts as $fontName) {

jamie

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 6
Re: Using korean fonts in all PDF operations
August 27, 2013, 12:27:46 pm
Now the question is: how to integrate with civicrm?

The hack involved changing the Labels.php, which could be changed to take user input as a new configuration screen or more easily as a config variable set in civicrm.settings.php. Perhaps something like: $civicrm_settings['CiviCRM Preferences']['additional_fonts'] = array('gulim' => 'Baekmuk');

But tcpdf wants the converted font in the packages directory, which will get overwritten. Fortunately, it looks like tcpdf finds fonts based on the setting of the constant K_PATH_FONTS, which is not set by default (if it is not set, it uses the fonts directory in the base path).  So, users would need to:

  • Copy the fonts directory from packages/tcpdf/fonts to a new location out of the civicrm directory
  • Add the following line to civicrm.setttings.php: define('K_PATH_FONTS', '/path/to/fonts/');

And then follow the directions for how to extract the fonts to this directory.

If anyone has better ideas let me know, otherwise I'll work on this approach.

jamie

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Using korean fonts in all PDF operations
August 28, 2013, 07:32:07 am
If this seems like it will work and is the path of least resistance, I won't get in your way. I do wonder though why we have 3 pdf libraries and if it wouldn't solve several problems at once by ditching 2 of them.
I think there is general agreement that wkhtmltopdf is the best, but the downside is it adds an extra step to an already very long process of installing and configuring CiviCRM. Tim has been doing some thinking about dependency/package management and I wonder if any of his proposed improvements would help with this issue.
Try asking your question on the new CiviCRM help site.

jamie

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 6
Re: Using korean fonts in all PDF operations
August 28, 2013, 12:21:02 pm
I fully agree about consolidating the PDF libraries.

I suspect we have tcpdf because dompdf couldn't handle labels as flexibly. I wonder if DOMPDF does anything that can't be done with tcpdf? If we could remove DOMPDF and give the option of replacing tcpdf with wkhtmltopdf we'd be in good shape.

I'm not sure wkhtmltopdf can do with tcpdf does for labels - by providing the degree of flexiblity in terms of positioning them (selecting fonts, etc).

Thanks for the feedback.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using korean fonts in all PDF operations
August 28, 2013, 12:27:39 pm

note that wkhtmltopdf is a binary and as such might not be available on many hosting provider packages st

dompdf does not have the nicely packaged mailing label stuff which tcpdf has

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Using korean fonts in all PDF operations

This forum was archived on 2017-11-26.