[fpc-pascal] fpPDF and support of Latin2 charset

LacaK lacak at zoznam.sk
Tue Mar 19 15:00:04 CET 2019



>>> Is there way how to get correct PDF file WITHOUT embedding full 
>>> Courier font?
>>
>> You can embed only the needed characters for every font ?
> Probably yes, but fpPDF will not handle this automatically? AFAIK I 
> can not control this.
>
> But why I get unreadable characters? What I am doing wrong ?
>
It seems that there is problem specific to CourierNew font (cour.ttf).
With Arial (arial.ttf) it works as expected.

Attached program which demonstrates problem.

-Laco.

-------------- next part --------------
unit test_fpPDF1;

{$mode objfpc}{$H+}
{$codepage UTF8}


interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormShow(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

uses fpPDF;

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
var
  PDF: TPDFDocument;
  Font1, Font2: integer;
begin
  PDF := TPDFDocument.Create(Self);
  PDF.Infos.Producer := '';
  PDF.Infos.CreationDate := Now;
  PDF.Options := [poPageOriginAtTop, {poNoEmbeddedFonts,} poSubsetFont, poCompressFonts, poCompressImages];
  PDF.DefaultOrientation := ppoPortrait;
  PDF.DefaultPaperType := ptA4;
  PDF.DefaultUnitOfMeasure := uomMillimeters;
  PDF.FontDirectory := 'C:\WINDOWS\FONTS';
  PDF.StartDocument;
  PDF.Sections.AddSection;
  PDF.Sections[0].AddPage(PDF.Pages.AddPage);;

  //FontIndex := PDF.AddFont('Courier');
  Font1 := PDF.AddFont('cour.ttf', 'CourierNew');
  Font2 := PDF.AddFont('arial.ttf', 'Arial');
  PDF.Pages[0].SetFont(Font1, 10);
  PDF.Pages[0].WriteText(10,10,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  PDF.Pages[0].WriteText(10,15,'----------------');
  PDF.Pages[0].WriteText(10,20,Edit1.Text);

  PDF.Pages[0].SetFont(Font2, 10);
  PDF.Pages[0].WriteText(10,30,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  PDF.Pages[0].WriteText(10,35,'----------------');

  PDF.SaveToFile('test.pdf');
end;

end.



More information about the fpc-pascal mailing list