What makes PDF files portable?


Font data can be embedded into the PDF . This allows the PDF to be viewed in exactly the same way on any computer. If the font data is not embedded, the PDF viewer application will search on the user’s computer for a similar font. This may result in differences in the display of the text when viewed on different computers with different installed fonts, but we have a solution for you:

In PL/PDF, you can embed both Standard and Unicode TrueType fonts, but if you want to use Unicode, your database has to be installed with UTF character set. You can see if you have it, with this query:

SELECT * FROM NLS_DATABASE_PARAMETERS
After you checked if you have the infrastructure for your font, then you can start using it by the following steps:

Generating the data of the font

  • Load your file into the PLPDF_TTF_FILE table:
  • ID: Unique identifier, 2. FONTFILE_NAME: TTF name with extension, 3.: FONTFILE_DATA: the TTF font file.
  • Generate data for the selected TTF with the following script (it usually takes some seconds):
  • begin
    plpdf_ttf_parser.StoreTTF(
    p_font_file_id => 6,
    p_enc => 'cp1252', -- cp1252 for standard, utf16 for unicode,
    -- see more in the specification of plpdf.SetEncoding
    p_commit => true
    );
    end;

    Using your font in the PDF

    1. You have to declare a ’plpdf_type.t_addfont’ variable for it, alongside with other variables.
    2. declare
      l_blob blob;
      l_ttf plpdf_type.t_addfont;

    3. Then you retrieve the font into your variable using the plpdf_ttf.GetTTF procedure. The parameter is the ID field of the PLPDF_ADD table.
    4. begin
      l_ttf := plpdf_Ttf.GetTTF(
      p_id => 6 -- ID field of the PLPDF_TTF_ADD table
      );

    5. After you have the font in the variable, you have to add it to the PDF document:
    6. plpdf.Init;
      Plpdf.addTTF(
      p_family => 'DejaVuSerif-Italic',
      p_style => 'I',
      p_data => l_ttf
      );

    7. And then you only need to set it as PrintFont:
    8. plpdf.NewPage;
      plpdf.SetPrintFont(
      p_family => 'DejaVuSerif-Italic',
      p_style => 'I',
      p_size => 12
      );
      plpdf_cell.PrintCell(
      p_width => 200,
      p_height => 10,
      p_text => 'Font family:DejaVuSerif-Italic -> TTF Example'
      );
      plpdf.SendDoc(
      p_blob => l_blob
      );
      insert into STORE_BLOB (blob_file, created_date, filename)
      VALUES (l_blob,sysdate, 'TTFembending');
      commit;
      end;