Render / Export to PDF without using Viewer in Web Site or Windows Forms app

Posted by: david.thompson on 22 May 2018, 6:21 pm EST

    • Post Options:
    • Link

    Posted 22 May 2018, 6:21 pm EST

    I’m testing with a couple different projects. I’m trying to export/render a pdf to a saved file from the report object without using a Webviewer (web site project) or Viewer.Win.Viewer (Windows Forms project). It is worth noting that I am not using a file, I am building the reports dynamically (including the document structure & data) in code and can not use the ‘load’ method.

    According to documentation it looks like this should be possible but all of the examples use reports that are loaded from a file and everything else I’ve been trying has failed.

    Is what I’m trying to do even possible?

  • Posted 23 May 2018, 2:25 am EST

    Hello,

    You simply use the following line of code to export into PDF file:

    
     Dim pr As New PageReport()
            Try
                setReportMarkup(pr, "pt", "portrait")
                pr.Report.DataSources.Add(myDataSource())
                pr.Report.DataSets.Add(myDataSet())
                pr.Document.Printer.PrinterName = String.Empty
                pr.Run()
            ' Create an output directory.
    Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyPDF")
    outputDirectory.Create()
    
    ' Provide settings for your rendering output.
    Dim pdfSetting As New GrapeCity.ActiveReports.Export.Pdf.Page.Settings()
    
    ' Reduce the report size and report generation time.
    pdfSetting.OptimizeStatic = True
    
    ' Set the rendering extension and render the report.
    Dim pdfRenderingExtension As New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
    Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
    
    ' Overwrite output file if it already exists
    outputProvider.OverwriteOutputFile = True
    
    pr.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting)
    
    
    
            Catch ex As Exception
                    Dim x As String = ""
    
    
                End Try
    
    
    

    Note:- I have referred modified the code that is given by you in the previous post.

    Also, please add the “GrapeCity.ActiveReports.Export.Pdf.v12.dll” reference in your project.

    Hope it helps.

    Thanks,

    Mohit

  • Posted 23 May 2018, 9:55 am EST

    Thanks Mohit!

    I was so close,

    I didn’t have the following line

    pdfSetting.OptimizeStatic = True
    

    I’m guessing the pdf export never finished before I aborted the execution. I was only getting 0kb pdf files and I couldn’t figure out why.

    Thank you so much!

  • Posted 24 May 2018, 9:07 am EST

    Hello David,

    Is your issue has been resolved after adding the following line:

    pdfSetting.OptimizeStatic = True
    

    If yes, Could I close this issue?

    Thanks,

    Mohit

  • Posted 25 May 2018, 11:29 am EST

    Yes , feel free to close. Thanks again!

Need extra support?

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

Learn More

Forum Channels