Export SSRS to PDF as Attachment (not via subscriptions)

Ismail Cassiem 226 Reputation points
2021-07-20T13:30:38.197+00:00

Good day,

Currently i am exporting my SSRS2016 report in html via ssis to internal and external users

Dim client As New WebClient()
client.Credentials = CredentialCache.DefaultNetworkCredentials
Dim content = client.DownloadString("http://sbh-XXXX/ReportServer/Pages/ReportViewer.aspx?%2fDashboard&rS:Format=MHTML&rs:Command=Render&rc:Toolbar=None&rc:HeaderArea=None&rc:MHTMLFragment=True&rc:OutlookCompat=True&rc:ExpandContent=True")

I had a previous solution of having the pdf format link in a text file that opens in PFD but the users hated the text file and i could not find the solution, please help i want to via ssis attach the pdfredendered report in email attachment

please help?

regards

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,927 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ismail Cassiem 226 Reputation points
    2021-07-20T20:31:17.837+00:00

    Thank you
    I dont really want to send mail via the script task
    Without the email I had variable attachmentpdf = pdf but receiving conversion error when changing type
    The ssis var attachmentpdf was string, object and byte but then tried email in script

    How do I do without email script but I update the ssis Var is read write


13 additional answers

Sort by: Most helpful
  1. Michael Taylor 54,401 Reputation points
    2021-07-20T14:24:54.063+00:00

    Render the report in PDF as you normally would. That is an option to the rendered when you request the report. Right now you get HTML back, you'll be getting PDF instead. At this point everything remains the same. Create an email with whatever body you want. Attach the PDF that you got back from SSRS as an attachment and then send the email.

    You didn't mention how you're sending the email but I assume you're using the Send Mail task. It has an option to add an attachment. You'll just need to store the generated report temporarily. Note that there is a warning that if the attachment doesn't exist when the package runs then it'll error but I assume it means when the task runs, which would make sense.

    If for some reason you cannot get the Send Mail task to work then you can do the same thing programmatically using a script.

    0 comments No comments

  2. Ismail Cassiem 226 Reputation points
    2021-07-20T15:28:42.877+00:00

    Thank You, im not sure i follow

    Dim content = client.DownloadString("http://sbh-XXXX/ReportServer/Pages/ReportViewer.aspx?%2fDashboard&rS:Format=PDF&rs:Command=Render&rc:Toolbar=None&rc:HeaderArea=None&rc:MHTMLFragment=True&rc:OutlookCompat=True&rc:ExpandContent=True

    how would i download the file automatically from ssis rendered and then attach it in send mail task
    the above is rendered in SSIS Script task, should i be saving the export pdf from script task
    aslo it would need to overwrite or generate a filename that sis can pickup

    please provide example or ?

    0 comments No comments

  3. Michael Taylor 54,401 Reputation points
    2021-07-20T15:52:39.05+00:00

    You won't be using DownloadString here as that returns the binary file as a string. Use DownloadData instead. You get back the byte array. Place that into an SSIS variable you have defined in your package (or container). Inside the Send Mail Task go to the attachments section and set it using an expression that points to the SSIS variable your script has set.

       byte[] pdf = client.DownloadData(url);   
         
       Dts.Variables["AttachmentPdf"].Value = pdf;  
    

    Note that to write to the variable you need to modify the script properties in the UI and add the variable(s) you are writing to the ReadWriteVariables section. Otherwise it'll fail at runtime.

    You could also send the email directly from the script task if you really wanted to but I think it is more maintainable to use the Send Mail task so it is clear in the package.

    0 comments No comments

  4. Ismail Cassiem 226 Reputation points
    2021-07-20T17:29:10.043+00:00

    WOW - Thank You, this looks very interesting :)
    going to try this tomorrow :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.