Reputation: 31
I have read through previous threads on this topic, but all are old, unanswered, and/or about something more specific about creating custom fonts.
In TCPDF:
$pdf->SetFont('times', '', 10);
The pdfs I create look awesome. It is just that BarnesAndNoble says my submitted PDF does not contain "embedded fonts". Kindle says the same, but that they then embedded them for me. I'm trying LuLu next, but want to deal with BN.com first.
An example suggests:
$fontname = $pdf->addTTFfont('/fonts/arial.ttf', '', '', 32);
... but does not go on to say what to do with "$fontname". Nor what the "32" specifically stands for, or if there are better options for that "32". Or, if THAT does embed fonts!
My webhost says my fonts path is:
/usr/share/fonts/default/Type1
... maybe then (case sensitive??):
/usr/share/fonts/default/Type1/Helvetica
I need to properly embed my fonts!
Upvotes: 3
Views: 6170
Reputation: 7183
If you want to make sure that TCPDF embeds all fonts, even Type1 fonts (like Times or Helvetica), which is required for PDF/A documents you should enable it explicitly.
$pdf = new \TCPDF(
orientation: 'P',
unit: 'mm',
format: 'A5',
unicode: true,
encoding: 'UTF-8',
diskcache: false,
pdfa: 1 // This enables PDF/A-1. You can specify 2 or 3, too. Default is 'false'
);
Attention!
Keep in mind, that PDF/A-1 forbids transparency or gradients.
Embedding files is forbidden in PDF/A-1 and PDF/A-2.
Upvotes: 0
Reputation: 842
TCPDF will just automatically embed fonts you've added on its own. I'm fairly certain it's presumed that most all OS's have Times, Helvetica and Courier already available and therefore TCPDF does not embed them. So in your case, if you add a TTF font TCPDF should recognize when it is used and embed the font definition automatically.
Also, you should only have to do $fontname = $pdf->addTTFfont('/fonts/arial.ttf', '', '', 32);
once, so you could run your script once, and then comment that line out.
Direct From the documentation;
AddFont( $family, $style = '', $fontfile = '', $subset = 'default' )
Imports a TrueType, Type1, core, or CID0 font and makes it available. It is necessary to generate a font definition file first (read /fonts/utils/README.TXT). The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.
Parameters
$family - Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.
$style - Font style. Possible values are (case insensitive):
$fontfile - The font definition file. By default, the name is built from the family and style, in lower case with no spaces.
$subset - if true embedd only a subset of the font (stores only the information related to the used characters); if false embedd full font; if 'default' uses the default value set using setFontSubsetting(). This option is valid only for TrueTypeUnicode fonts. If you want to enable users to change the document, set this parameter to false. If you subset the font, the person who receives your PDF would need to have your same font in order to make changes to your PDF. The file size of the PDF would also be smaller because you are embedding only part of a font.
Returns - array containing the font data, or false in case of error.
Since 1.5 See TCPDF::SetFont(), TCPDF::setFontSubsetting() Public
Upvotes: 4