06
Sun, Oct
2 New Articles

Changing Fonts on IP-connected HP LaserJet Printers

Typography
  • 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:

(10U(s1p**v0s3b4101T
The ** is the point size. The two parts of the command are as follows:

(10U Basic ASCII

symbol/character

set (IBM PC-8)

(s1p36v0s3b4101T Font CG Times

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

(10U(s1p36v0s3b4101T


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:

1B
( 28
1 31
0 30
U 55

(10U 1B28313055
(s1p36v0s3b4101T 1B28733170333676307333623431303154

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

1B283130551B2873317033367630733362
3431303154

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
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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 R TRAVCERT
A SKIPB(001)
A PRTCMD1 132A 1
A TRNSPY CVTDTA
A 20'Travel Certificate'
A SPACEB(006)
A PRTCMD2 132A 1
A TRNSPY CVTDTA
A 15'One Thousand Two Hundred Dollars'
A SPACEB(003)
A PRTCMD3 132A 1
A TRNSPY CVTDTA
A 20'Love, Uncle Bob and Aunt Sue'
A SPACEB(003)

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


FFONTPRT O E PRINTER OFLIND(*In31)

* 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 WRITE TRAVCERT

C EVAL *InLR = *On

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


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 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. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • 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 company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY 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. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) 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:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. 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:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot 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:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business 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.

  • 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:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic 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.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? 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: