Home arrow ASP arrow Adobe Reports in an ASP Web Page
ASP

Adobe Reports in an ASP Web Page


In this article, Matt shows us how to use Adobe Active Reports in our ASP web pages using a custom made VB component.

Author Info:
By: Matt Burnett
Rating: 5 stars5 stars5 stars5 stars5 stars / 20
February 04, 2003

print this article
SEARCH DEVARTICLES

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.

All ASP Tutorials
More By Matt Burnett


blog comments powered by Disqus
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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials