Recent

Author Topic: fcl-pdf  (Read 218 times)

deridan

  • Newbie
  • Posts: 2
fcl-pdf
« on: April 24, 2025, 02:51:04 pm »
Hello All,

For fcl-pdf, is there a way to output the PDF to a browser?
Currently I only see a way to save to file, via  Document.SaveToFile('output.pdf');
See sample below.

 begin
  Document := TPDFDocument.Create(nil);
  Document.FontDirectory := 'C:\Windows\Fonts';
  Document.Options := Document.Options + [poPageOriginAtTop, poNoEmbeddedFonts];
  Document.StartDocument;
  FontID := Document.AddFont('arial.ttf', 'Arial');
  FontBoldID := Document.AddFont('arialbd.ttf', 'Arial Bold');

  Section := Document.Sections.AddSection;

  Page := Document.Pages.AddPage;
  Section.AddPage(Page);

  Page.SetFont(FontID, 11);
  Page.WriteText(20, 20, 'This is normal text');

  Page.SetFont(FontBoldID, 11);
  Page.WriteText(20, 30, 'This is bold text');

  Document.SaveToFile('output.pdf');
end;             

rvk

  • Hero Member
  • *****
  • Posts: 6714
Re: fcl-pdf
« Reply #1 on: April 24, 2025, 03:13:36 pm »
Use ShellExecute with "open" to open the PDF directly in the default PDF reader (being Edge, Adobe reader or other user preference).

(not tested but you get the idea)
Code: Pascal  [Select][+][-]
  1. uses ..., ShellAPI, FileUtils;
  2. //
  3. TempFileName := IncludeTrailingPathDelimiter(GetTempDir) + 'output.pdf';
  4. Document.SaveToFile(TempFileName);
  5. ShellExecute(0, 'open', PChar(TempFileName), nil, nil, SW_SHOWNORMAL);

deridan

  • Newbie
  • Posts: 2
Re: fcl-pdf
« Reply #2 on: April 24, 2025, 03:23:02 pm »
Perfect. Thanks.

 

TinyPortal © 2005-2018