Train e-tickets with QR codes
One ticket per passenger from a single rail booking
- Template
- DOCX
- Export as
- PDF, DOCX, ODT, HTML, PNG +25 more
- Carbone
- 5.18+
- Loop
- Barcode
- Date
- Number format
- Text
- In-template options
- Header and footer
Generate train e-tickets from your booking system
Rail, bus and ferry operators send an e-ticket to every passenger as soon as a booking is paid. Each ticket shows the booking reference, the train, the date, the stations with their times, the coach and seat, the fare and its exchange conditions, and a code the conductor or the gate scans. Your booking system sends the booking to the Carbone API as JSON and gets back one PDF with a page per passenger, ready to attach to the confirmation email or to show in your app.
In this example, Kestova Rail, a fictional operator, issues three first class tickets for a family trip from Paris Montparnasse to Nantes. The header carries a specimen tag, the ticket numbers start with 999 and the QR codes point to a .example address.
In this example, you will:
- Repeat the whole ticket for each passenger, one per page
- Print the booking data shared by all passengers on every ticket
- Generate a QR code for each passenger
- Format the date, the times and the price
- Print the last name in capital letters
How to generate one e-ticket per passenger
1. Lay out the ticket
- In Layout > Size, choose A5 and set the orientation to Landscape.
- Insert a table with four columns: three for the journey and one for the stub on the right. Give each row an exact height so the ticket keeps its shape.
- The card outline, its thin coral top edge and the tinted class panel of the stub are one picture placed in the page header, behind the text. Word prints it on every page, so every ticket gets its frame.
- The dashed line between the ticket and the stub is a dashed left border on the stub column.
2. Repeat the ticket for each passenger
- The JSON holds the booking (
booking,journey) and the list of passengers (passengers). - Write
{d.passengers[i]}in the first line of the page, before the table, and{d.passengers[i+1]}in a paragraph after the table. Carbone repeats everything between the two tags for each passenger, and removes both tags. - Check Page break before on the first line (Format > Paragraph > Line and Page Breaks), so that each ticket starts on a new page.
3. Fill in the ticket
- Insert the Carbone tags where the data goes:
{d.passengers[i].seat},{d.passengers[i].category},{d.passengers[i].fare}and{d.passengers[i].conditions}change on every ticket;{d.booking.reference},{d.journey.from},{d.journey.to},{d.journey.coach},{d.journey.class}and{d.journey.train}are the same for all passengers. Tags outside the array work inside the loop too.
{d.passengers[i].firstName} {d.passengers[i].lastName:upperCase}prints Claire MORVAN with the :upperCase formatter.
4. Format the date, the times and the price
{o.lang=en-ie}{o.timezone=Europe/Paris}, in the last line of the page, sets the language and the time zone of the whole document. See the in-template options.- The booking system sends UTC times, for example
"departure": "2027-03-11T06:42:00.000Z". The :formatD formatter converts them to Paris time:{d.journey.departure:formatD('dddd D MMMM YYYY')}prints Thursday 11 March 2027;{d.journey.departure:formatD('HH:mm')}prints 07:42.
€{d.passengers[i].price:formatN(2)}prints €89.00 with :formatN.
5. Add the QR code
- Insert a temporary square picture in the stub.
- Right-click it, select View Alt Text and write
{d.passengers[i].qrCode:barcode(qrcode, eclevel:M)}. - The :barcode formatter replaces the picture with a QR code that holds the verification link of each ticket, at the size of the temporary picture.
Save the DOCX template, send it with the JSON of the booking, and Carbone returns one PDF with a ticket per passenger.
Related Examples
Trusted by 800+ paid customers in 40+ countries














