ASP
  Home arrow ASP arrow Adobe Reports in an ASP Web Page
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Adobe Reports in an ASP Web Page
By: Matt Burnett
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2003-02-04

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    In this article, Matt shows us how to use Adobe Active Reports in our ASP web pages using a custom made VB component.This article is a quick example on inserting Adobe report documents into a browser and using Adobe Reader to display them.

    I am using MS 2000 Server, IIS5.0 and ASP to implement this article's functions. Additionally, you will need Adobe Reader installed on your machine, VB6.0 and Active Reports. (Adobe Reader is a free download.)

    In the support file is a picture of the project in VB6.0.

    The process of presenting the document is 1) to build and compile a VB COM object using Active Reports to output the report, and 2) calling the COM object from the server code in an ASP page to present the report.

    An example of this can be found at
    http://www.datadynamics.com/default.aspx
    ...however, I accomplished this task a little differently, and I think it’s useful for other programmers to see it.

    Our VB object uses a single function to call the designers needed to create the report:

    ' VB6 code of Generalized function to generate the report.
    Public Function GenerateReport (ByVal ReportDate As Date, ByVal LOF As String, ByVal Funding As String, _
        ByVal SubFunding As String) As Variant
      Dim oPDF As ActiveReportsPDFExport.ARExportPDF
      
      ' create Active Report designer objects
      Set oRpt = New rptPerfStds
      oRpt.Printer.Orientation = ddOLandscape
      'Go build the report with the oRpt object!
      'After that
      oRpt.Pages.Insert intPageCount, YourReport.Pages(i)
      'export to pdf
      Set oPDF = New ActiveReportsPDFExport.ARExportPDF
      ' pdf and tmp will be in current folder:
      oPDF.FileName = modGenReporting.GenerateTempPDF(App.Path)
      oRpt.Export oPDF
      
      'create byte file for output report
      GenerateReport = modGenReporting.StreamFile(oPDF.FileName)
      
      'kill pdf file and temp file
      modGenReporting.DeleteTempPDF oPDF.FileName
    End Function


    A big step after creating the report is preparing the report for export which requires a temp file. This function:

    modGenReporting.GenerateTempPDF(App.Path)

    ...is a little complex, so lets show how the temp file is made:

    Public Function GenerateTempPDF(strPath As String, Optional strPrefix As String = "tmp") As String
      Dim strTempName As String
      
      strTempName = GenTempName(strPath, strPrefix)
      If UCase(Right(strTempName, 4)) = ".TMP" Then
        GenerateTempPDF = Left(strTempName, Len(strTempName) - 4) & ".pdf"
      Else
        Err.Raise vbObjectError + GEN_REPORTING_ERR_UNEXPECTED_EXT, "GenerateTempPDF", "Unexpected file name format"
      End If
    End Function

    Public Function GenTempName(strPath As String, Optional strPrefix As String = "tmp")
      Dim lngUnique As Long
      Dim strTempFileName As String
      lngUnique = 0
      strTempFileName = Space$(100)
      GetTempFileName strPath, strPrefix, lngUnique, strTempFileName
      If Trim(strTempFileName) = "" Then
        strTempFileName = ""
        Err.Raise vbObjectError + GEN_REPORTING_ERR_NO_TEMP_FILE, "modGenReporting.GenTempName", "Error creating temporary file."
      Else
        strTempFileName = Mid$(strTempFileName, 1, InStr(strTempFileName, Chr$(0)) - 1)
      End If
      GenTempName = strTempFileName
      Exit Function
    End Function

    Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long


    Ok, now to stream the file to the .ASP page for display with function:

    modGenReporting.StreamFile

    We use this:

    Public Function StreamFile(ByVal strFileName As String)
    On Error GoTo ErrHnd
      Dim lngFlen As Long
      Dim bytStream() As Byte
      Dim strBinFile As String
      Dim intFHan As Integer
      
      intFHan = FreeFile
      
      lngFlen = FileLen(strFileName)
      ReDim bytStream(lngFlen)
      
      Open strFileName For Binary Access Read As #intFHan
      
      Get #intFHan, , bytStream
      
      Close #intFHan
      
      StreamFile = bytStream
      
      Exit Function
    End Function


    Then, set the stream to the return value the function: GenerateReport = byte stream.

    Compile and register your COM object on the Web Server.

    Lastly, call the COM within your ASP page:
    (ASP VBS Server code)

    'get report info from query string
    strOfficeId = Request.QueryString("office")
    strFundingSource = Request.QueryString("FundSource")
    strFundingSubCat = Request.QueryString("FundSubCat")
    'instantiate the report with whatever class name you gave it
    set oRpt = Server.CreateObject("WIAPSServer.cWIAPerfStds")
    'set up the HTTP Content-Type, and write out the report in binary
    Response.ContentType="application/pdf"
    Response.BinaryWrite oRpt.GenerateReport(CDate(Now),strOfficeId,strFundingSource,strFundingSubCat)


    The browser will respond by opening Adobe Reader to display the output. If the Reader is not installed you will be prompted to download it. This method of displaying reports should work for either Netscape or IE.

    Questions can be directed to burnettm@hotmail.com, but I don't promise to answer them ( ;o) ). However, the reference to Data Dynamics is a good one and I would use that first.

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Articles
    More By Matt Burnett

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek