tags:

views:

1065

answers:

4

Hi There,

I am using FPDF / FPDI to build a pdf templating system. One pdf is used as the background and has a number of editable regions defined within it (stored in database). An editable region could be an image, or text, or both, however this is not my question, just a bit of background.

Some of the backgrounds (FPDI source pdf) pdf's or 'templates' contain embedded fonts, I want to be able to acheive two things and was wondering if this is possible.

  1. I want to be able to use any fonts embeded in the source document in the output document.
  2. I need to enumerate these fonts so that they can be included in the UI's font list.

To be clear I want to resuse these fonts, not just have them applied to the imported page, but offer the option to render new text in one of the embedded fonts.

Any pointers would be greatly appreciated.

+1  A: 

First on fonts and PDFs. If I remember correctly, when a font gets included into a PDF, all of the font can be included, or just a subset of the font covering the character faces actually being used can be embedded. Some of the PDF 'compression' tools can strip the unused font glyphs from the pdf file. (Can someone confirm/refute this?)

As for FPDF (it's the library I use), I don't think it can open a PDF in 'edit' mode. It can simply open a PDF and use it as a background - effectively an image of the document. A quick look through the contributed scripts appears to show no scripts that will open a PDF file for real (besides one that can just get the meta-info on the document).

There are other options for PDF libraries. The demonstration of TCPDF I saw at the following presentation, showed that TCPDF may have more in-built capabilities the FPDF. It may be worth a look into that library? http://suburbanchicagophp.org/archives/75

creuzerm
A: 

I am the orginal question asker, but I lost my temp account so cant comment (admin please merge if you can).

Just to clarify.

We have chosen to use FPDF over over TCPDF due to compatibility problems detailed on the FPDI website as FPDI is the core component in this, dropping FPDI was not an option.

We use FPDI to pull pages from the template document, and we then place text and images (as defined in the database using a web UI) over the top of each page, so the usuage is exactly as FPDI allows.

I found another question on this board asking about pulling embedded fonts from pdf files, the asker was slated for copyright infringing activites which is a huge assumption.

http://stackoverflow.com/questions/823348/how-can-i-extract-fonts-from-a-pdf-file-with-perl

Our templates will be coming from our designers, we want to resuse (rather than extract) fonts in the template pdf.

So these are our fonts, we just dont want every machine this pdf passes through for editing to have to not only have the font available to embed, but also to select and embed the correct font. It leads to double, even tripple handling of fonts, and possibly some guess work.

One of the replies in the above post is a very helpful direction, it is a Perl module that can enumurate embeded fonts, which is exctly what I need to display embeded fonts in the UI font list.

Now I need to test if the fonts embedded in a source (template) pdf are carried across to the new pdf, I presume they must be, so there must be a resonable way to reuse them.

Ill post back for completelness when I know for sure, still if anyone has any feedback or knowledge on this it would be greatly appreciated.

p.s. it is correct that some editors will create compressed pdf documents and strip some of the unused font, however it is a simple request for us to say dont use an editor that does this, or you will have to re-embed the font.

A: 

To further clarify this, Zend_PDF will allow for this exact functionality, enumerating and then reusing fonts embeded in a PDF, but it will not work with PDF later than v1.4, with v1.4 pdf however Zend works very well:

e.g the following is possible in Zend_PDF and then a font can reused by name:

public static function GetFontList($background)
{
     $pdf = Zend_Pdf::load($background);
     $fonts = array(); 
     // Get all document fonts
     $fontList = $pdf->extractFonts();

    foreach ($fontList as $font) 
    {
        $fontName = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
        $fonts[] = $fontName;
    }

    return $fonts;
}

Hopefully this will be helpful to someone, however I need a higher pdf versions than 1.4 so I guess I am looking to modify FPDI.

A: 

I'm doing the exact same thing at the moment and my "template pdfs" already have the fonts embedded. All I want to do is use these fonts for new cells.

Have you fond a solution for this problem?

Jens