Changing Fonts on IP-connected HP LaserJet Printers

Document Management
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

PC-based applications make Hewlett-Packard LaserJet printers whirl, jig, and print some downright fancy documents. On the iSeries and AS/400, IPDS-defined printers can do sophisticated printing, too. But what about SNA Character Stream-type printers, and HP LaserJet printers, in particular? SNA Character Stream (SCS) allows for basic formatting, but face it, this is really talking about plain vanilla text reports. There are thousands (or more) of HP LaserJet printers connected to iSeries 400 computers by IP connections that are capable of some extraordinary font printing, but the SCS interface doesn’t allow the developer to easily change fonts on a single page. Or does it?

What if we could mix fonts—larger, smaller, and bold, for example—on the same page? That could really open up the possibilities. Perhaps your biggest customer will still be the text report, but it sure would be nice to be able have the tools to print fancy documents every now and again.


To Print the Impossible


But aren’t I talking about an SCS-defined printer here? You can’t dynamically change the fonts within the print file for a SCS device. Often to easily connect a LAN HP LaserJet printer to the AS/400, you use the CRTOUTQ command and specify the printer’s IP address. This sets up an implicit SCS device, and print files sent to the printer must abide by the limitations of SCS. Or do they?

The secret is knowing how to build a command that tells the printer to begin printing a new font and then knowing how to pass this command to the printer. Several methods can be used to accomplish this (see “Use PC Laser Printer Fonts in Your RPG Output” by Ann Willyard in the February 1995 issue of MC), and this article presents one technique. Actually, after going through the various pieces involved, it’s not too daunting a task, and the rewards are simply spectacular. Oh, by the way, it can be done with an IP- connected HP LaserJet printer, even though it’s defined as SCS.


Speaking the Language


The printer’s native language is PCL. This is a series of escape sequences followed by parameters that tell a printer things like how to print, where on the page to print, what the

print looks like, how many times to print, and so on. Most of the time, a developer only uses PCL when the host computer’s interface doesn’t allow a particular function, or when it’s just plain easier to send a PCL command rather than fumble through the host interface.

The HP LaserJet printer likes to receive these commands in hexadecimal format, so before you send the PCL commands to the printer, a translation will need to be made. Normally, OS/400 will translate a print file into the necessary PCL commands. You still want this to happen, but you’re going to need to help the operating system a bit when a fancy font is needed.

This article will only deal with the PCL command to change fonts. There are so many commands in PCL that one article wouldn’t cover them all. Thankfully, OS/400 will continue to translate most of the print file for you, and you only need to concentrate on font changes. The font command consists of two parts: a symbol set and the font attributes. The symbol set defines the allowable characters to print, and the font attributes tell the printer how to print the allowable characters. Together they form the command that will cause a font change on the printer.


The Hex Connection!


When you send a PCL command to the printer, you must code it in hexadecimal format. That is, every character that will be translated must be represented by a pair of hexadecimal digits. Figure 1 (page 46) contains a chart of all of the characters that will be converted into hex pairs for this article.

To convert a character, symbol, or control into a hex pair, first find the character in the table and then find out which row and column it’s in. Finish by writing the row as the first character and the column as the second character. For example, the escape character, ESC (and written below as ), is in row 1 and column B, so its hexadecimal representation is 1B. A null, or NUL, which is valid in hexadecimal, is 00, capital A is 41, and 4 is hex 34. It’s pretty simple once you get the hang of it.

Using the chart in Figure 1 as your “secret agent decoder ring” will make translating the PCL commands into hexadecimal kind of like going on a spy mission. But instead of secret codes, you’ll be translating PCL.


The PCL Command


As I mentioned, the command to make font changes has two parts: the symbol set and the font attributes. Say you wanted to print a string of text at 36 points (each point is 1/72 of an inch in height) using the font CG Times.

In the HP LaserJet’s user’s manual, the PCL command for printing CG Times is as follows:

The ** is the point size. The two parts of the command are as follows:

(10U Basic ASCII


set (IBM PC-8)

(s1p36v0s3b4101T Font CG Times

in 36 point
Putting both parts of the PCL command together gives you the whole picture:


Using the translation table in Figure 1 and taking it one character at a time, the hex pair representation of the PCL command becomes as follows:

( 28
1 31
0 30
U 55

(10U 1B28313055
(s1p36v0s3b4101T 1B28733170333676307333623431303154

The complete hex pair representation of (10U(s1p36v0s3b4101T is the following:


Now, take a breath. OS/400 will take care of translating this long string down to the machine level that the printer will actually use. There are several resident fonts on the HP LaserJet printer, so check the printer’s user’s manual for more fonts and the corresponding PCL command to make the font change.


DDS Smoke and Mirrors


Within the DDS of the print file, there are two important field-level keywords that allow you to insert your own PCL commands right smack in the middle of the PCL that OS/400 is generating: TRNSPY and CVTDTA. A data field will contain a text string of the hex pairs like the one above, and these two keywords working together will cause the operating system to change the text into something the printer can understand. The PCL command itself is not printed out on the page, but it does cause the printer to change fonts.

Figure 2 shows how to use these two keywords in your DDS. Indicators are not valid with either of these two. Because hex pairs always appear in twos, make sure that the field is defined with an even length. The TRNSPY (Transparency) keyword prevents OS/400 from interpreting the contents of the field into printable characters and the CVTDTA (Convert Data) keyword tells OS/400 to convert the contents of the field into machine-understandable hexadecimal data when passing it to the printer.

You’ve come a great way in a short amount of time and are just about finished.


The RPG IV Program


The RPG IV code in Figure 3 uses the methods above to control the fonts of an IP- connected HP LaserJet printer. Start off by defining the two parts of the PCL command as two separate constants. This will keep the size of the constant to one line and allow you to define multiple font attributes for later use. In the calculation specs, EVAL is used to concatenate the two parts together and place the completed PCL command into the field that has the TRNSPY and CVTDTA keywords. The field receiving the concatenated data is longer than it needs to be, and this presents an unexpected challenge.

Because OS/400 will attempt to translate the entire contents of the field containing the PCL command, it is very important to send only valid hex pairs to the printer. Invalid data will be translated as garbage, and the printer won’t know what to do with the command. Spaces, as it turns out, are not valid hexadecimal digits, but zeros are. So, if you’re dynamically building the contents of the data field, like the example in Figure 3, change any residual spaces to zeros. The RPG command XLATE will accomplish the conversion very nicely.


Watch Your Step, Please


When changing the font from the default font, be aware that some of the fonts and point sizes are proportional. This implies that the spacing is also proportional, so take care how your print file is laid out. If you have the luxury, keeping the special fonts on separate lines will provide you with a good mechanism for managing the proportional spacing. The space between print lines still needs to be controlled by SPACEA and SPACEB. Keep in mind that the larger the point size specified, the more the printed text will encroach on the text lines above and below. This is also a good time to reiterate the other warnings I stated before. Make sure that the field containing the PCL command is large enough to contain all the hex pairs that make up the translated command, and if the field is generously sized, convert any residual spaces to zeros.


Fonts to the Masses


Now you are able to overcome the SCS limitation for fonts. You have a powerful technique for passing a font PCL command to the printer. Using the same method, other PCL commands could also be sent to the printer. Be brave, and experiment with this powerful tool. Explore the different fonts available on the HP LaserJet printer, spruce up some of those sagging reports, and create new ones. Certificates, invoices, and statements are now possible and can be printed over the LAN to the IP-connected HP LaserJet printer. One last thought: This method could also be used to send other PCL commands to the printer. I wonder if there are any that may be appropriate. Hmmmm.

0 1 2 3 4 5 6 7 8 9 A B C D E F
2 SP ! “ # $ % & ‘ ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ ] ^ _
6 ` a b c d e f g h I j k l m n o
7 p q r s t u v w x y z { | } ~ DEL

Figure 1: Using this chart, you can translate PCL commands into hex.

A SKIPB(001)
A PRTCMD1 132A 1
A 20'Travel Certificate'
A PRTCMD2 132A 1
A 15'One Thousand Two Hundred Dollars'
A PRTCMD3 132A 1
A 20'Love, Uncle Bob and Aunt Sue'

Figure 2: This DDS is an example of using TRNSPY and CVTDTA.


* Basic ASCII symbol/character set
D SymSet C '1B28313055'

* Font CG Times, Bold, 36 Point - (s1p36v0s3b4101T
D Cg36P C '1B28733170333676307333623431303154'

* Font CG Times, Normal, 20 Point - (s1p20v0s0b4101T
D Cg20P C '1B28733170323076307330623431303154'

* Font Coronet, Normal, 24 Point - (s1p24v1s0b4116T
D Cn24P C '1B28733170323476317330623431313654'

* Concatenate the symbol set together with the font attributes
C EVAL PrtCmd1 = SymSet + Cg36P
C EVAL PrtCmd2 = SymSet + Cg20P
C EVAL PrtCmd3 = SymSet + Cn24P

* Convert any spaces to zeros
C ' ':'0' XLATE PrtCmd1 PrtCmd1
C ' ':'0' XLATE PrtCmd2 PrtCmd2
C ' ':'0' XLATE PrtCmd3 PrtCmd3

* Print

C EVAL *InLR = *On

Figure 3: The RPG IV source drives font commands and printing.



Support MC Press Online





  • White Paper: Node.js for Enterprise IBM i Modernization

    SB Profound WP 5539

    If your business is thinking about modernizing your legacy IBM i (also known as AS/400 or iSeries) applications, you will want to read this white paper first!

    Download this paper and learn how Node.js can ensure that you:
    - Modernize on-time and budget - no more lengthy, costly, disruptive app rewrites!
    - Retain your IBM i systems of record
    - Find and hire new development talent
    - Integrate new Node.js applications with your existing RPG, Java, .Net, and PHP apps
    - Extend your IBM i capabilties to include Watson API, Cloud, and Internet of Things

    Read Node.js for Enterprise IBM i Modernization Now!


  • Profound Logic Solution Guide

    SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation.
    Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects.
    The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the companyare not aligned with the current IT environment.

    Get your copy of this important guide today!


  • 2022 IBM i Marketplace Survey Results

    Fortra2022 marks the eighth edition of the IBM i Marketplace Survey Results. Each year, Fortra captures data on how businesses use the IBM i platform and the IT and cybersecurity initiatives it supports.

    Over the years, this survey has become a true industry benchmark, revealing to readers the trends that are shaping and driving the market and providing insight into what the future may bring for this technology.

  • Brunswick bowls a perfect 300 with LANSA!

    FortraBrunswick is the leader in bowling products, services, and industry expertise for the development and renovation of new and existing bowling centers and mixed-use recreation facilities across the entertainment industry. However, the lifeblood of Brunswick’s capital equipment business was running on a 15-year-old software application written in Visual Basic 6 (VB6) with a SQL Server back-end. The application was at the end of its life and needed to be replaced.
    With the help of Visual LANSA, they found an easy-to-use, long-term platform that enabled their team to collaborate, innovate, and integrate with existing systems and databases within a single platform.
    Read the case study to learn how they achieved success and increased the speed of development by 30% with Visual LANSA.


  • Progressive Web Apps: Create a Universal Experience Across All Devices

    LANSAProgressive Web Apps allow you to reach anyone, anywhere, and on any device with a single unified codebase. This means that your applications—regardless of browser, device, or platform—instantly become more reliable and consistent. They are the present and future of application development, and more and more businesses are catching on.
    Download this whitepaper and learn:

    • How PWAs support fast application development and streamline DevOps
    • How to give your business a competitive edge using PWAs
    • What makes progressive web apps so versatile, both online and offline



  • The Power of Coding in a Low-Code Solution

    LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed.
    Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks



  • Why Migrate When You Can Modernize?

    LANSABusiness users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
    In this white paper, you’ll learn how to think of these issues as opportunities rather than problems. We’ll explore motivations to migrate or modernize, their risks and considerations you should be aware of before embarking on a (migration or modernization) project.
    Lastly, we’ll discuss how modernizing IBM i applications with optimized business workflows, integration with other technologies and new mobile and web user interfaces will enable IT – and the business – to experience time-added value and much more.


  • UPDATED: Developer Kit: Making a Business Case for Modernization and Beyond

    Profound Logic Software, Inc.Having trouble getting management approval for modernization projects? The problem may be you're not speaking enough "business" to them.

    This Developer Kit provides you study-backed data and a ready-to-use business case template to help get your very next development project approved!

  • What to Do When Your AS/400 Talent Retires

    FortraIT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators is small.

    This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:

    • Why IBM i skills depletion is a top concern
    • How leading organizations are coping
    • Where automation will make the biggest impact


  • Node.js on IBM i Webinar Series Pt. 2: Setting Up Your Development Tools

    Profound Logic Software, Inc.Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. In Part 2, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Attend this webinar to learn:

    • Different tools to develop Node.js applications on IBM i
    • Debugging Node.js
    • The basics of Git and tools to help those new to it
    • Using as a pre-built development environment



  • Expert Tips for IBM i Security: Beyond the Basics

    SB PowerTech WC GenericIn this session, IBM i security expert Robin Tatam provides a quick recap of IBM i security basics and guides you through some advanced cybersecurity techniques that can help you take data protection to the next level. Robin will cover:

    • Reducing the risk posed by special authorities
    • Establishing object-level security
    • Overseeing user actions and data access

    Don't miss this chance to take your knowledge of IBM i security beyond the basics.



  • 5 IBM i Security Quick Wins

    SB PowerTech WC GenericIn today’s threat landscape, upper management is laser-focused on cybersecurity. You need to make progress in securing your systems—and make it fast.
    There’s no shortage of actions you could take, but what tactics will actually deliver the results you need? And how can you find a security strategy that fits your budget and time constraints?
    Join top IBM i security expert Robin Tatam as he outlines the five fastest and most impactful changes you can make to strengthen IBM i security this year.
    Your system didn’t become unsecure overnight and you won’t be able to turn it around overnight either. But quick wins are possible with IBM i security, and Robin Tatam will show you how to achieve them.

  • Security Bulletin: Malware Infection Discovered on IBM i Server!

    SB PowerTech WC GenericMalicious programs can bring entire businesses to their knees—and IBM i shops are not immune. It’s critical to grasp the true impact malware can have on IBM i and the network that connects to it. Attend this webinar to gain a thorough understanding of the relationships between:

    • Viruses, native objects, and the integrated file system (IFS)
    • Power Systems and Windows-based viruses and malware
    • PC-based anti-virus scanning versus native IBM i scanning

    There are a number of ways you can minimize your exposure to viruses. IBM i security expert Sandi Moore explains the facts, including how to ensure you're fully protected and compliant with regulations such as PCI.



  • Encryption on IBM i Simplified

    SB PowerTech WC GenericDB2 Field Procedures (FieldProcs) were introduced in IBM i 7.1 and have greatly simplified encryption, often without requiring any application changes. Now you can quickly encrypt sensitive data on the IBM i including PII, PCI, PHI data in your physical files and tables.
    Watch this webinar to learn how you can quickly implement encryption on the IBM i. During the webinar, security expert Robin Tatam will show you how to:

    • Use Field Procedures to automate encryption and decryption
    • Restrict and mask field level access by user or group
    • Meet compliance requirements with effective key management and audit trails


  • Lessons Learned from IBM i Cyber Attacks

    SB PowerTech WC GenericDespite the many options IBM has provided to protect your systems and data, many organizations still struggle to apply appropriate security controls.
    In this webinar, you'll get insight into how the criminals accessed these systems, the fallout from these attacks, and how the incidents could have been avoided by following security best practices.

    • Learn which security gaps cyber criminals love most
    • Find out how other IBM i organizations have fallen victim
    • Get the details on policies and processes you can implement to protect your organization, even when staff works from home

    You will learn the steps you can take to avoid the mistakes made in these examples, as well as other inadequate and misconfigured settings that put businesses at risk.



  • The Power of Coding in a Low-Code Solution

    SB PowerTech WC GenericWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed.
    Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks



  • Node Webinar Series Pt. 1: The World of Node.js on IBM i

    SB Profound WC GenericHave you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.
    Part 1 will teach you what Node.js is, why it's a great option for IBM i shops, and how to take advantage of the ecosystem surrounding Node.
    In addition to background information, our Director of Product Development Scott Klement will demonstrate applications that take advantage of the Node Package Manager (npm).
    Watch Now.

  • The Biggest Mistakes in IBM i Security

    SB Profound WC Generic The Biggest Mistakes in IBM i Security
    Here’s the harsh reality: cybersecurity pros have to get their jobs right every single day, while an attacker only has to succeed once to do incredible damage.
    Whether that’s thousands of exposed records, millions of dollars in fines and legal fees, or diminished share value, it’s easy to judge organizations that fall victim. IBM i enjoys an enviable reputation for security, but no system is impervious to mistakes.
    Join this webinar to learn about the biggest errors made when securing a Power Systems server.
    This knowledge is critical for ensuring integrity of your application data and preventing you from becoming the next Equifax. It’s also essential for complying with all formal regulations, including SOX, PCI, GDPR, and HIPAA
    Watch Now.

  • Comply in 5! Well, actually UNDER 5 minutes!!

    SB CYBRA PPL 5382

    TRY the one package that solves all your document design and printing challenges on all your platforms.

    Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product.

    Request your trial now!

  • Backup and Recovery on IBM i: Your Strategy for the Unexpected

    FortraRobot automates the routine tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:
    - Simplified backup procedures
    - Easy data encryption
    - Save media management
    - Guided restoration
    - Seamless product integration
    Make sure your data survives when catastrophe hits. Try the Robot Backup and Recovery Solution FREE for 30 days.

  • Manage IBM i Messages by Exception with Robot

    SB HelpSystems SC 5413Managing messages on your IBM i can be more than a full-time job if you have to do it manually. How can you be sure you won’t miss important system events?
    Automate your message center with the Robot Message Management Solution. Key features include:
    - Automated message management
    - Tailored notifications and automatic escalation
    - System-wide control of your IBM i partitions
    - Two-way system notifications from your mobile device
    - Seamless product integration
    Try the Robot Message Management Solution FREE for 30 days.

  • Easiest Way to Save Money? Stop Printing IBM i Reports

    FortraRobot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing.
    Manage your reports with the Robot Report Management Solution. Key features include:

    - Automated report distribution
    - View online without delay
    - Browser interface to make notes
    - Custom retention capabilities
    - Seamless product integration
    Rerun another report? Never again. Try the Robot Report Management Solution FREE for 30 days.

  • Hassle-Free IBM i Operations around the Clock

    SB HelpSystems SC 5413For over 30 years, Robot has been a leader in systems management for IBM i.
    Manage your job schedule with the Robot Job Scheduling Solution. Key features include:
    - Automated batch, interactive, and cross-platform scheduling
    - Event-driven dependency processing
    - Centralized monitoring and reporting
    - Audit log and ready-to-use reports
    - Seamless product integration
    Scale your software, not your staff. Try the Robot Job Scheduling Solution FREE for 30 days.