try
PDF.BeginDocument('VATReturn.pdf');
PDF.PageSize:=psA4;
PDF.Header:='VAT Return';
PDF.Footer:='Page 1/1';
PDF.NewPage;
RH:=PDF.GetHeaderRect;
PDF.Graphics.Font.SizeNoScale:=12;
PDF.Graphics.Font.Color:=gcBlack;
PDF.Graphics.Font.Style:=[];
TR:=PDF.Graphics.DrawText('Drawing primitives', PointF(RH.Left,RH.Bottom+10));
PDF.EndDocument(True);
finally
PDF.Free;
end;
Hi,
Application.OnFontCacheReady := DoFontCacheReady;
AddFontToCache('https://myserver.com/tmsweb/pdf/fonts/arial.ttf');
AddFontToCache('https://myserver.com/tmsweb/pdf/fonts/tahoma.ttf');
var
pth: string;
begin
asm
var loc = window.location.href;
var dir = loc.substring(0, loc.lastIndexOf('/'));
pth = dir;
end;
AddFontToCache(pth + '/Fonts/arial.ttf');
end;
the AddFontToCache should only be executed once, and when the DoFontCacheReady is triggered, you can start exporting to PDF. We have upload a sample that demonstrates this, based on your code. Additionally, the code you are using, will try to open the PDF in a PDF reader internally in the browser. If you have an AD Blocker, then it could be possible that you will not see anything. Alternatively, you can also save directly to the Downloads folder, as if you were downloading a file, or if your internet browser is configured to prompt to user with a save dialog, it should present a save dialog.
Thanks, I'll check out the sample.
Perfect. Thank you very much.
Your welcome!
One question though. How do I set the font for the PDF in Web Core?
You can set
I can't get this to work with a ttf added to the project. I have modified your sample and uploaded it to http://test.simplyaccounts.net/PDFExportSample.zip I would appreciate it if you could tell me what I am doing wrong.
Please change the code to:
procedure TForm59.WebButton1Click(Sender: TObject);
var
PDF: TTMSFNCPDFLib;
RH: TRectF;
TR: TRectF;
ms: TMemoryStream;
nFont: string;
begin
nFont := 'Gisha';
PDF := TTMSFNCPDFLib.Create;
try
PDF.FontFallBackList.Clear;
PDF.FontFallBackList.Add(nFont);
PDF.BeginDocument{('VATReturn.pdf')};
PDF.FooterFont.Name:=nFont;
PDF.HeaderFont.Name:=nFont;
PDF.PageSize := psA4;
PDF.Header := 'VAT Return';
PDF.Footer := 'Page 1/1';
PDF.NewPage;
RH := PDF.GetHeaderRect;
PDF.Graphics.Font.Name:=nFont;
PDF.Graphics.Font.SizeNoScale:=12;
PDF.Graphics.Font.Color := gcBlack;
PDF.Graphics.Font.Style := [];
TR := PDF.Graphics.DrawText('Drawing primitives', PointF(RH.Left, RH.Bottom + 10));
ms := PDF.EndDocument{(True)};
try
ms.SaveToFile('VATReturn.pdf');
finally
ms.Free;
end;
finally
PDF.Free;
end;
end;
Thanks again. Getting much closer. Adobe Reader displays a popup saying "Cannot extract the embedded font 'Gisha'. Some characters may not display or print correctly". This also happens in your original sample using the fonts from your website.
This is unfortunately a common issue, when displaying the same PDF in Foxit Reader then the message does not display. We have added this on our todolist for investigation, but could potentially be due to a false positive reported in Adobe Reader.
It's possible that the font you are using is not containing all symbols. When looking at the characters that are included at https://www.fontpalace.com/font-details/Gisha/ I see that it does not include '£'
That's strange as I use Gisha for the entire app and the £ sign is displayed fine in lots of places.
My Bad, we forgot a crucial part here. Whenever a unicode character is used, the font is added compressed inside the PDF. For compression, pako is used, an opensource javascript compression library. This is not automatically included in your project. To include this you need to right-click the project and then select "Manage JavaScript Libraries". You'll get a popup that shows the supported libraries, then you can check "Pako ZLib Compression (PDF)". Click on Apply, and then OK. Clean, Rebuild your application and then refresh the browser application.