Decided to make a very simple demo of the problem.
Create a simple VCL app and add a button, a file save dialogue and a TAdvPDFLib component from the palette.
This is the form file
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 144
ClientWidth = 356
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 15
object Button1: TButton
Left = 120
Top = 96
Width = 129
Height = 25
Caption = 'Create Demo PDF File'
TabOrder = 0
OnClick = Button1Click
end
object TMS: TAdvPDFLib
Left = 96
Top = 8
Width = 26
Height = 26
Visible = True
end
object FileSaveDialog1: TFileSaveDialog
FavoriteLinks = <>
FileTypes = <>
Options = []
Left = 16
Top = 8
end
end
and this is the code
unit TMSFontDemo;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AdvCustomComponent,
AdvPDFLib;
type
TForm1 = class(TForm)
Button1: TButton;
FileSaveDialog1: TFileSaveDialog;
TMS: TAdvPDFLib;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
System.Types;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
procedure SomeText(FontName: String; FontSize: Single; X, Y: Single; cl: TColor);
begin
TMS.Graphics.Font.Name:= FontName;
TMS.Graphics.Font.Size:= FontSize;
TMS.Graphics.Font.Color:= cl;
var s: String := Format('Text in Font: %s; Size: %d', [FontName, round(FontSize)]);
TMS.Graphics.DrawText(s, PointF(X, Y))
end;
begin
if FileSaveDialog1.Execute(self.Handle) then
begin
TMS.BeginDocument(FileSaveDialog1.FileName);
try
TMS.NewPage;
SomeText('Times New Roman', 6, 50, 30, clFuchsia);
SomeText('Times New Roman', 8, 50, 80, clFuchsia);
SomeText('Times New Roman', 9, 50, 130, clFuchsia);
SomeText('Times New Roman', 12, 50, 180, clFuchsia);
finally
TMS.EndDocument(true);
end;
end;
end;
end.
Run the application, click the button and pick a file name. It will create the PDF and should then open it in Acrobat PDF reader (if you have it, no idea what happens if not).
If you then copy the text from PDF reader and paste it in to MS word in 2 ways, firstly in "Keep Text only", and then "Keep Source formatting"
Now select each of the first 4 lines in word from the unformatted text, and change the font to "Times New Roman", and the appropriate size. This is what I see.
![image](https://support.tmssoftware.com/uploads/default/original/2X/0/07793916fc668527af42f45c84c527d03afacac1.png)
The top lines are formatted in Word, and the Fuchsia lines, direct from the PDF file.
The factor difference in size is 96/72 and I can see in the code where this is done. I just don't understand why, and there doesn't seem to be any obvious way to stop or control that, other than the very kludgy way of setting a font like 8 point like this...
TMS.Graphics.Font.Size:= (8 * 96 / 72);
which seems like defeat to me for now. I may have to do it, but would like to know why in case that also breaks at some point.
Maybe I should not be using TMS.Graphics.Font, but it looks like the right way...
Thanks