monospacetext.pp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. program monospacetext;
  2. {$mode objfpc}{$H+}
  3. {$codepage UTF8}
  4. uses
  5. Classes, SysUtils,
  6. fpPDF;
  7. var
  8. PDF: TPDFDocument;
  9. Font1, Font2, Font3, Font4: integer;
  10. begin
  11. if ParamCount<1 then
  12. begin
  13. Writeln(stderr,'Usage : monospacetext <fontdir>');
  14. Writeln(stderr,'Needed fonts : cour.ttf, arial.ttf, verdanab.ttf consola.ttf');
  15. Halt(1);
  16. end;
  17. PDF := TPDFDocument.Create(nil);
  18. PDF.Infos.Producer := '';
  19. PDF.Infos.CreationDate := Now;
  20. PDF.Options := [poPageOriginAtTop, {poNoEmbeddedFonts,} poSubsetFont, poCompressFonts, poCompressImages];
  21. PDF.DefaultOrientation := ppoPortrait;
  22. PDF.DefaultPaperType := ptA4;
  23. PDF.DefaultUnitOfMeasure := uomMillimeters;
  24. PDF.FontDirectory := paramstr(1);
  25. PDF.StartDocument;
  26. PDF.Sections.AddSection;
  27. PDF.Sections[0].AddPage(PDF.Pages.AddPage);;
  28. //FontIndex := PDF.AddFont('Courier');
  29. Font1 := PDF.AddFont('cour.ttf', 'Courier New');
  30. Font2 := PDF.AddFont('arial.ttf', 'Arial');
  31. Font3 := PDF.AddFont('verdanab.ttf', 'Verdana');
  32. Font4 := PDF.AddFont('consola.ttf', 'Consolas');
  33. PDF.Pages[0].SetFont(Font1, 10);
  34. PDF.Pages[0].WriteText(10,10,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  35. PDF.Pages[0].WriteText(10,15,'----------------');
  36. PDF.Pages[0].SetFont(Font2, 10);
  37. PDF.Pages[0].WriteText(10,30,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  38. PDF.Pages[0].WriteText(10,35,'----------------');
  39. PDF.Pages[0].SetFont(Font3, 10);
  40. PDF.Pages[0].WriteText(10,40,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  41. PDF.Pages[0].WriteText(10,45,'----------------');
  42. PDF.Pages[0].SetFont(Font4, 10);
  43. PDF.Pages[0].WriteText(10,50,'AEIOU-ÁÉÍÓÚ-ČŠŇŽ');
  44. PDF.Pages[0].WriteText(10,55,'----------------');
  45. PDF.SaveToFile('test.pdf');
  46. PDF.Free;
  47. end.