Blog

All Blog Posts  |  Next Post  |  Previous Post

Show a PDF from a TMS WEB Core app

Bookmarks: 

Tuesday, December 29, 2020



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:

  1. Show the PDF file in a new browser window (tab)
  2. 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.

Bruno Fierens


Bookmarks: 

This blog post has received 2 comments.


1. Wednesday, December 30, 2020 at 10:20:42 AM

Excellent Demo!
Thanks Bruno and Happy New year!

/Tim

Tim Hamel


2. Friday, December 10, 2021 at 1:50:46 PM

How can you manually set the file name if you select the download function after the document is displayed in the Browsercontrol object. It defaults to document.pdf when you select download. I want to give it another name from the application side.



Bernard van der Merwe




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post