How to print business cards from a Delphi application

2020-08-24

Applications built in Delphi are less common than, for example, those built in C #. These programming languages are from different times. However, even nowadays Delphi and VCL can complete some of the modern tasks. There are many free and commercial libraries that can modernize even old applications. For example, the FastReport 6 VCL report generator allows you to create modern reports and export them to many formats of electronic documents and images. Sometimes, report generators are used to complete non-trivial tasks, such as printing business cards.

A business card is a very resourceful invention. A small cardboard card that contains the necessary contact information about the business representative allows you to instantly share this information with another person, obviating the need for writing down the contact information during a short meeting with your business partner or customer. Eventually having a business card has become a common courtesy and even social networks and messengers can’t force them out of daily life. Generally, people have many business cards from different people in their wallets. To stand out from this variety, they spend a lot of time to make a good design. A good design attracts attention and makes it easy to read the information. Large companies order a unique business cards design for a large amount of money and print them on expensive pre-punched paper. So it goes – image.

The business cards form factor and size are generally settled around the world, but there are still some slight differences from country to country. So, for example, a standard business card in the USA has dimensions of 3,2*2 inches (88,9*50,8mm), when in Germany and France business cards are higher and narrower – 85*55mm.

In this article, we will look at how to quickly and easily print business cards using the FastReport VCL report generator.

The user application will be created in VCL. After the FastReport VCL report generator was installed, FastReport components tabs had been added to the component palette in your development environment. Therefore, first of all let's add the frxReport component to the form which will allow us to launch the report designer, as well as the report itself. Also you need two buttons: one to launch the report designer, another one to launch reports.

You can create a separate application that will run the report designer or delete this button when you finish creating the report. The thing is, that to run the report designer, we need to compile the application.

Let’s add the click event for each of the buttons. The code for launching the report designer will be like this:

1
frxReport1.DesignReport();

 And for launching the report – like this:

1
2
3
 frxReport1.LoadFromFile(‘Report file path here’);
 frxReport1.PrepareReport();
 frxReport1.Print();

 This code will send a report to print when you click on the button. The Print Settings window will be displayed before printing. But if you want to preview the report first, replace the last line of the code with:

1
frxReport1.ShowReport();

 In addition, you can use the Open File dialog box instead of setting the hard path to the report file. Add the OpenDialog component to the form. Change the button code as follows:

1
2
3
4
5
6
7
8
OpenDialog1.Filter := 'FastReport VCL (*.fr3)|*.FR3';
 OpenDialog1.Execute();
 if Length(OpenDialog1.FileName)>0 then
 begin
 frxReport1.LoadFromFile(OpenDialog1.FileName);
 frxReport1.PrepareReport();
 frxReport1.Print();
end

 Let’s run the application and click on the first icon to launch the report designer.

To create business cards, we need only one Data band in the report – MasterData. Select Page Settings from the File menu:

 Page options

In the Page Settings window, we can set the number of columns on the page. This way we can display text information as in a newspaper or magazine. But we have a different goal. We need to place as many business cards on the standard A4 sheet as possible. We need two columns if the business card width is 9cm. Set the height of the future business card in the band’s properties: Height = 5. That is, the height is 5 centimeters. Thus the size of the business card is 90*50mm.

Now you can start creating the business card itself – this is a matter of your taste. To make cut lines with scissors, you can place a Text object on the band. Stretch it to fit the band and set all borders, select a line thickness of 0.1 and dash line type.

 Line style

If we launched the report right now we would see only one business card, when according to our calculations there should be 10. Just set the RowCount property for the MasterData band. As a result, you will get the following report template:

Business card report template.

Now you can save it and close the designer. Using the second button, select the saved report and print it (if you used the print option in the code). If you chose the report preview (ShowReport), you will see the page with business cards:

Showed report

That’s all. Simple and, most importantly, fast! In ten minutes, we gave our program the ability to display business cards on the screen or immediately send them to print. However, from the report preview window you can print using the corresponding button and export the document to one of the following formats: PDF, DOC, HTML, HTML5, SVG, RTF, XLS, XML, BMP, JPEG, TIFF, CSV, TXT (for matrix printers), GIF, ODS, ODT, Excel and others.

20. November 2024

Lokalisierung und Ändern von Sprachen in FastReport VCL

FastReport VCL unterstützt 40 Sprachen für die Schnittstellenlokalisierung und ermöglicht es Ihnen, die Sprache im laufenden Betrieb über Menüs oder Code ohne Neukompilierung zu ändern.
11. Dezember 2023

Neuer S3 (Amazon) Transport in FastReport VCL

In diesem Artikel werden wir uns den neuen Transport in S3 (Amazon) für FastReport VCL ansehen, bei dem es sich um einen Objektspeicher für Dateien und Buckets handelt.
26. September 2023

Installation von FastReport- und FastCube-Komponenten in Lazarus

Anleitung zur Installation von FastReport in Lazarus für verschiedene Betriebssysteme mit einem Vergleich der Trial, Professional-Editionen.
Fast Reports
  • 800-985-8986 (Englisch, die USA)
  • +4930568373928 (Deutsch)
  • +55 19 98147-8148 (Portugiesisch)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.