21
Thu, Nov
1 New Articles

Piercing Together the Web-distribution Puzzle

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

My employer recently tasked me with providing access, via the Internet, to approximately 30 million DB2 UDB records stored on an AS/400. Specifically, I needed to create an interactive, Web-based reporting system. This system would have to display the results in a browser as well as email the results to the requesting client. The platform for this project was Microsoft’s Internet Information Server (IIS) and Active Server Pages (ASP). I decided to use Seagate Software’s Crystal Reports for this project because I have extensive experience with Crystal Reports and it has Web-reporting capabilities. Ultimately, I chose a solution in which a PostScript file, created by Crystal Reports, is converted to Adobe’s PDF. In turn, that PDF file is displayed in the client’s browser and emailed to the client. However, before that solution was implemented, I explored Crystal’s Web-reporting capabilities.

The first Web-reporting capability I investigated was SmartViewer. It’s a browser plug-in, which comes in two flavors, ActiveX and Java. However, I quickly discovered SmartViewer had some problems. The Java version produced very degraded graphics when displaying in Internet Explorer. This was caused by Microsoft’s method of scaling images. (For a full explanation of this problem, visit the Seagate Knowledge Base page at community.seagatesoftware.com/library/kbase/articles/ c2002974.asp.) Additionally, the ActiveX version sometimes had problems displaying an entire report created in landscape mode.

Finally, SmartViewer cannot generate a file that could be subsequently emailed. Another option I explored was Crystal’s exporting features. Crystal Reports is capable of exporting to many popular formats such as Word, Excel, and HTML. However, none of these formats would identically reproduce the report as it was shown on the screen. I then turned to delivering these reports using Adobe’s PDF.

I had ruled out SmartViewer and Crystal’s exporting. That left one option: Print the report to a file. The concept is pretty simple. Print the report to a file, convert that file to PDF using the Adobe Distiller program, display the PDF file in the browser, and email the PDF to the client. However, as with most programming tasks, especially ones that are Web-based, implementing this project turned out to be elusive and frustrating. Yet once I’d solved the mystery of printing to a file, putting the pieces together was a snap. Here are the steps necessary to make this work:


1. Install a PostScript printer and redirect its output to a file.

2. Install Adobe’s Acrobat and Distiller products.

3. Modify the IIS’s registry to allow Web processes (specifically ASP) access to the PostScript printer.

4. Create a Crystal report using Crystal’s Reports’ Designer Component, which, for those who don’t already have it, is available free from the Crystal Report’s Web site at www.

seagatesoftware.com/products/crystalreports/rdc.asp for anyone with a Visual Basic
(VB) license.

5. Write a Visual Basic Component Object Model (COM) object, which causes Crystal Reports to produce a PostScript file and causes Adobe’s Distiller to convert that file to PDF.

6. Write an ASP script that invokes the COM object.

First Steps

Before you can replicate my solution, you need to install a PostScript printer on your server, name it POSTSCRIPT (you’ll see why), and configure it to print to a file. A PostScript printer is necessary because Adobe’s Distiller can only convert PostScript files to PDF. Redirecting the port to a file will provide that file. See the sidebar “Adding a PostScript Printer and Configuring Its Port to Send the Output to a File” for step-by-step instructions on how to create a PostScript printer and redirect its output to a file. Next, install Adobe Acrobat and Distiller. Now, run the Distiller program, configure the job options, and save the job options in a file. The ASP script that creates the PDF file will use these job options. See the sidebar “Configuring the Distiller Options” for step-by-step instructions on setting the job options.

Now, here’s the first technical hurdle: Printing on an IIS requires that certain entries be in the registry. However, Web processes (including ASP scripts) run using the System account. The System account does not normally have any printer information stored in the registry. Furthermore, a COM object instantiated by an ASP page will also run using the System account. Therefore, you will need to modify the registry. See the sidebar “Modifying the Registry” for instructions. (For a full explanation, visit the Microsoft Knowledge Base page at support.microsoft.com/support/kb/articles/q184/2/91.asp.) Note that registry modification can cause serious, systemwide problems that may require reinstalling the operating system. Therefore, be careful! Follow the instructions in the sidebar exactly!

The Working COM Object

It’s time to create a COM object using VB. You can download the complete code for the VB project referenced in this article from the Midrange Computing Web site (www.midrangecomputing.com/mc). For brevity, only the printReport method of the object is described here. This method is the heart of the object. It works by printing a Crystal report to a PostScript file and then converting that file to PDF. Open the project in VB and follow along as I describe what the PrintReport method does.

Because many instances of this component can be running at one time, the PrintReport method starts by waiting until any previous copy of a PostScript file no longer exists. The method does this to ensure that the user produces a report that is exclusive to him and that the program does not accidentally write over the output of another instance of


itself. Next, the method loops through the printer collection until it finds the printer named POSTSCRIPT. Once found, the printer and Crystal’s report objects are assigned to this printer so that, when Crystal is invoked, it will create a PostScript file of its output. Next, Crystal’s page orientation is set, and Crystal’s PrintOut method is invoked. The PrintOut method actually causes Crystal to read the records from the AS/400 and write the PostScript file. Finally, the PostScript file is converted to PDF by invoking Distiller’s FileToPDF method, and the PostScript file is deleted. Once the file is deleted, any other instances of the object will be free to process their reports.

Piece by Piece

At this point, you’ve created a PostScript printer, installed Distiller, safely modified the registry, and created the VB COM object that converts a Crystal Reports PostScript printout to PDF. It’s now time to tie all these steps together with an ASP page created with VBScript. You can download the complete ASP and HTML files used in this example from the MC Web site. Again, for brevity, only the ASP script is described here. This RunSysCols ASP script displays certain fields from the SysColumns table of an AS/400 database. This script is “called” from an HTML file via a hyperlink. Here are the steps implemented in this script:

1. Create a reference to the COM object you’ve created and initialize the Crystal report to run.

2. Generate a random file name, which will be the final PDF file.

3. Connect to the AS/400 using ActiveX Data Object (ADO) and set some of the ADO properties.

4. Initialize the ADO recordset and pass the recordset to the COM object.

5. Using the COM object, open the Crystal report and invoke other methods used to further manipulate the Crystal environment.

6. Invoke the PrintReport object, passing in the proper parameters (report orientation, the PDF file name to create, the PostScript file name to convert, and the Distiller job options file).

7. Close the Crystal report, reset the ADO features, and display the PDF file in the client’s browser.

Putting It Together!

As I stated, once the mystery of printing from an NT service was solved, putting the pieces together was a snap. The critical piece in this case was getting an ASP page to print out. Once that was done, I created a VB COM object that uses Crystal Reports and Acrobat Distiller. Finally, the ASP page tied all the pieces together. If you want to see examples of this technology in action, I invite you to visit the AdSpies.com Web site at www.adspies.com, where my company is generating reports for its users with this technique.

References and Related Materials

• AdSpies.com: www.adspies.com
• Crystal Reports Report Designer Component Web site: www.seagatesoftware.com/products/crystalreports/rdc.asp
• Seagate Knowledge Base Web site:


community.seagatesoftware.com/library/kbase/articles/c2002974.asp

Configuring the Distiller Options

1. After installing Adobe Acrobat 4.0 and Distiller, find and run Distiller. It is located under the Adobe Acrobat 4.0 item of the Programs menu.
2. Choose Settings and then Job Options from the Distiller menu.
3. The Job Options menu offers many parameters that you can use to tailor created PDFs. For example, you can configure compression, version compatibility, and color handling from within this screen. See the Distiller documentation for a more in-depth description of these parameters and how you can use them.
4. After you’ve configured all the Distiller options you want, press the Save As... button and save your options in a file. You might want to name your file something that you can easily identify as the options file used for your Web site.

Modifying the Registry

1. Launch the Registry Editor (Regedit.exe).
2. Select the following key:
HKEY_CURRENT_USER
SoftwareMicrosoftWindows NTCurrent VersionDevices
3. From the Registry menu, click Export Registry File.
4. In the File Name text box, type c:Devices.reg.
5. Select the following key:
HKEY_CURRENT_USER
SoftwareMicrosoftWindows NTCurrent VersionPrinterPorts
6. From the Registry menu, click Export Registry File.
7. In the File Name text box, type c:PrinterPorts.reg.
8. Select the following key:
HKEY_CURRENT_USER
SoftwareMicrosoftWindows NTCurrent VersionWindows
9. From the Registry menu, click Export Registry File.
10. In the File Name text box, type c:Windows.reg.
11. From the Start button, select Run. Open c:Devices.reg in Notepad by typing Notepad c:Devices.reg in the Run dialog box.
12. Replace the text


HKEY_CURRENT_USER
with HKEY_USERS.DEFAULT.
13. Save the file. Then import it into the registry by double-clicking the file in Windows Explorer.
14. Repeat steps 11 through 13 for c:PrinterPorts.reg and c:Windows.reg.

Adding a PostScript Printer and Configuring Its Port to Send the Output to a File

Go to Settings/Control Panel and open the Printers icon. Select the Add Printer icon. Using the Add Printer Wizard, follow these steps:
1. First, choose My Computer as the location of the printer.
2. Proceed to the next screen and choose Add Port....
3. Next, highlight Local Port and press New Port....
4. For the port name, enter the directory and file name you want and press OK. For example, type in C:postscript.eps and press OK.
5. Now, you should be back at the Printer Ports screen. Simply close this screen and proceed.
6. Choose Next in the Add Printer Wizard screen and install any PostScript printer. I chose an HP LaserJet 5Si Mopier PS, but any PostScript printer will work.
7. Next, name the printer POSTSCRIPT.
8. You can designate this printer as not shared.
9. Finally, choose not to print a test page and click the Finish button. You’re done!


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: