This is a frequently asked question from TMS WEB Core users how a PDF file, typically a generated report, can be shown from a TMS WEB Core app.
The good news is that it is simple as browser technology has us covered. There are basically two options:
- Show the PDF file in a new browser window (tab)
- Show the PDF embedded in the application window
So, let’s just do this and provide a project that shows this.
To show the PDF file in a new browser window, all we need to do is call Application.Navigate(URL, ntBlank), where URL is the link to the PDF file.
To show the PDF file embedded in the application window, we can drop a TWebBrowserControl on the form and set its URL to the link to the PDF file.
So, in a nutshell, the code behind becomes as simple as:
procedure TForm2.WebButton1Click(Sender: TObject); const URL = 'https://download.tmssoftware.com/download/manuals/TMS%20Async.pdf'; begin if WebRadioButton1.Checked then WebBrowserControl1.URL := URL else Application.Navigate(URL, TNavigationTarget.ntBlank); end;
For your convenience, you can download the test project here
Needless to say that this exact code works in TMS WEB Core for Delphi, TMS WEB Core for Lazarus and TMS WEB Core for Visual Studio Code. It can be applied in a classic web client application, a PWA and also an Electron based cross-platform desktop application.
Not using TMS WEB Core yet? Get your free & fully functional trial version download from our website and benefit from the Holiday Season holidays to explore and get excited.