Using PDF Export for ASP.NET Web applications

Posted by: awerber on 4 August 2017, 6:03 am EST

  • Posted 4 August 2017, 6:03 am EST

    We'd like to stream some reports as PDF over the Web using Active Reports 2. My plan is to use the ExportStream method of the ARExportPDF object in a COM object to create a byte array, and make that the response of a Web page that has a PDF content type.


    I've heard that there could be a problem with this because of the threading of the COM object. Will this be a problem?


    Thanks,


    Andy

  • Replied 4 August 2017, 6:03 am EST

    Hello,

    It can be the similar but not the same, since in ASP.NET project you should use .NET appropriate language code like C# or VB.NET e.g. In ASP you can use languages like VBScript or JScript e.g. that is not .NET language. So, the code of ASP.NET and ASP projects is generally different even if the Response object has the similar methods.
  • Replied 4 August 2017, 6:03 am EST

    Hello,

    Please sorry for confusing. The solution I have provided above is completely related to ASP technology, not for ASP.NET and .NET platform. In case when you need to create ASP.NET application with ActiveReports, it is recommended to use ActiveReports for .NET version, since ActiveReports 2 (COM) is not for .NET solutions.

    However, if you need to use the Active Reports 2.0 with ASP.NET, please take a look at the recommendations listed in the following KB article:
    *How Can I Use ActiveReports 2.0 in Visual Studio .NET?*
    http://www.datadynamics.com/forums/77673/ShowPost.aspx

    > When I run the code you supplied, the PDF comes up in its own
    >window, not the ASPX page, so I have to close 2 windows.
    Is it possible to have a look at the code of ASPX page completely (html and code-behind)?

    >Also, when I drag the window with the PDF around on my screen, the
    >scroll bar doesn't work right. Is there something missing?
    Please note that when you pass PDF file to client's browser, the Acrobat add-on is used to display your PDF, not ActiveReports components. The ActiveReports only creates PDF file itself.

  • Replied 4 August 2017, 6:03 am EST

    Thanks! This got me going. But, things are not working 100%


    When I run the code you supplied, the PDF comes up in its own window, not the ASPX page, so I have to close 2 windows. Also, when I drag the window with the PDF around on my screen, the scroll bar doesn't work right. Is there something missing?


    Thanks again,


    Andy


     

  • Replied 4 August 2017, 6:03 am EST

    Hello,

    You should be able to implement your solution without a problem. It is one of the standard web solutions with ActiveReports.

    You need to create ASP page which calls your Visual Basic
    developed ActiveX DLL COM object which contains ActiveReports. The COM
    object runs the
    ActiveReports located in the DLL and exports the report in PDF format as a byte array using ExportStream method. Then
    the ASP page pass the PDF file to client as a reponse with PDF content type using Response.AddHeader and Response.BinaryWrite methods, like this:
    <font face="Courier New" size="2">Response.ContentType = "application/pdf"
    Response.AddHeader "content-disposition", "inline;filename=myrep</font><font face="Courier New" size="2">ort.pdf"
    Response.BinaryWrite binPages
    Response.End</font>

    You may want to take a look at the following KB articles regarding this subject:
    <span class="txt2">*INFO: ActiveReports 2 on The Web*</span>
    http://www.datadynamics.com/forums/415/ShowPost.aspx

    *Designing Visual Basic COM Objects for ASP*
    http://www.datadynamics.com/forums/316/ShowPost.aspx

  • Replied 4 August 2017, 6:03 am EST

    Thanks again. I had seen that article, but forgot about it. I set up a desktop application as described and it worked fine.


    The ASP.NET Response object has the same methods as the ASP Response object. Is the ASP.NET code for streaming the PDF to a Web page the same in ASP.NET as ASP?


    Thanks,


    Andy


     

  • Replied 4 August 2017, 6:03 am EST

    I found a way to get the report to work over the Web (inspired by looking at another recet post on this board), if I do the following:


    Private Sub ActiveReport_Initialize()
        Me.Printer.DeviceName = ""
    End Sub


    The report will run. But, the problem is that we also use the report in a VB6 application where we want to allow printing, so this was not good enough. So I tried to create a module level boolean (mIsWebReport) to conditionally call this line of code. We have a public method that's called in the report that we use to pass in variables. So the code looks something like this:


    Private IsWebReport as Boolean 'module level variable


    Public Sub StartReport (ByVal WebReport as Boolean)


       IsWebReport = WebReport


       If IsWebReport Then Me.Printer.DeviceName = ""


    End Sub


    Private Sub ActiveReport_Initialize()


       If IsWebReport Then Me.Printer.DeviceName = ""


    End Sub


    The report object is instantiated by implication with a call to the StartReport method. By putting in some AppLogEvent calls, I found that the Initialize event gets called before StartReport, so the test for IsWebReport is useless, since IsWebReport will be False. But the code in StartReport should set Printer.DeviceName to an empty string. However, the page is never displayed when the code looks like what I have above.


    Is there some event or other way around this problem?


    Thanks,


    Andy


     

  • Replied 4 August 2017, 6:03 am EST

    I finally got everything to work on my development machine. I did the following (in VB.NET)


    with Response


       .ContentType = "application/PDF"


       .BinaryWrite(GetReportAsPDF()) 'GetReportAsPDF() runs the report and the PDF exporter and returns a byte array


       .Flush()


       .End()


       .Close()


    End with


    But we have another developer who's working on the real project, and I copied the code to his machine. There's also a VB.NET desktop application that runs the same method and creates and displays the report as a PDF. The desktop application runs fine on his machine, but we get the following error when the Web application is run: ActiveReports PDF Export DLL error Pages collection contains 0 pages.


    I've tripled checked that I'm using the same data in the Web and desktop application. I searched on this error, and I noticed a couple of people had a similar problem where their Web app failed and a desktop app worked. They did not get a definitive solution. I was wondering whether anything more is known about this problem.


    By the way, I'm not sure what version of AR we're running. How do I figure that out? And, we use DSR files in our reports.


    Thanks again,


    Andy

  • Replied 4 August 2017, 6:03 am EST

    Hello,

    It seems like the problem may be with another machine, since on your machine the web project works fine as you mentioned. Please try to check that you use the same DLL on the both machines e.g.

    The simplest way to know build number of the product is look at the product's DDLs version:
    1) Locate the actrpt2.dll (or ardespro2.dll) file e.g., which should be placed by default in the folder "C:\Program Files\Common Files\Data Dynamics\ActiveReports 2" (or "C:\Program Files\Common Files\Data Dynamics\ActiveReports Pro").
    2) Right click on the located DLL file and select "Properties".
    3) Click the "Version" tab. You will see the version of the DLL.



  • Replied 4 August 2017, 6:03 am EST

    The report now works in ASP.NET on the other developer's machine.


    But, it does not work when I migrated everything to a test server. The application just seems to hang. I used calls to App.LogEvent to track down the problem. The last method that gets called before the program hangs is the Run method of the report. I know the report object was instantiated because I did a test for that. I put an App.LogEvent in the Report Start event code of the report. It never gets called, while it does get called on the two development machines.


    The development machines are Windows 2000 and Windows XP. The test server is Windows 2003 Server. I saw someone else report  a similar problem on this board. It was suggested that they reboot the server. So I tried rebooting my server. That did not help.


    Is there anything I can do to get this working?


    Thanks,


    Andy

  • Replied 4 August 2017, 6:03 am EST

    Hello,

    Could you please detail what do you mean exactly *the page is never displayed*? The report's pages collection is empty or PDF is blank? Are you able to run the report and make pages collection to export it to PDF format? Can you make RDF file of the report?
  • Replied 4 August 2017, 6:03 am EST

    Hello,

    You may want to take a look at the solutions described in the following KB article for common ASP issues (please see troubleshooting section):
    http://www.datadynamics.com/ShowPost.aspx?PostID=2275

    Here is a KB artilce that provides an additional information for web applications running on Windows 2003 Server IIS 6 that may be helpful for you:
    http://www.datadynamics.com/forums/74919/ShowPost.aspx


  • Replied 4 August 2017, 6:03 am EST

    When I say the page is never displayed it means when you click the hyperlink the outline of a Web page comes up, but nothing is ever displayed in the page. Also, the report never completes, as determined by calls to the App.LogEvent calls. If I set the printer to "", the report displays in the page.
  • Replied 18 February 2019, 8:39 pm EST

    Try using ZedPDF.com
    It helped me a lot!

    Best regards

    jeremiah
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels