Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Taylor 873 posts 2086 karma points
    Jan 10, 2019 @ 10:18
    Matt Taylor
    0

    Does anybody have any experience of creating and sending a PDF invoice rather than the usual HTML email?

    Thanks,

    Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 10, 2019 @ 13:38
    Matt Brailsford
    100

    Oooh, that's an interesting one. I see a couple of options.

    One option could be to fire the regular email template off, but insert a link to "Download PDF invoice" and have this link to an MVC controller which accepts an order number parameter (you'll need to add extra info / encrypt the params so people can't just increment the order number to see other peoples invoices) and then you could lookup the order and generate the PDF on the fly. Benefit here being you only generate PDFs for people who really need them.

    Second option could be to hook into the NotificationCenter.EmailTemplate.MailSending event fired by Tea Commerce and generate and attach the PDF to the outgoing Confirmation email. The MailSending event receives a MailSendingEventArgs args object which itself contains a copy of the order and the MailMessage object so you should have everything you need to generate the PDF and attatch it. The MailSending event also recieves a copy of the EmailTemplate object too so you can make sure you only generate the PDF for "Confirmation" emails.

    I think the second option would be the safer option, ie you don't expose an endpoint that others could try and manipulate, but on the other hand, this would generate PDF invoices all the time, whether people really wanted them or not.

    Hope this helps

    Matt

  • Matt Taylor 873 posts 2086 karma points
    Jan 10, 2019 @ 13:57
    Matt Taylor
    0

    Thanks Matt,

    Those are both really good ideas that I had not considered.

    I quite like first one actually. Most of the website is protected by membership and with the TC orders tagged with the member it will be pretty simple to ensure folk only get to see their own invoices. I've already done it for the member-profile/your-orders section. :-)

    Cheers,

    Matt

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 10, 2019 @ 14:14
    Matt Brailsford
    0

    As long as it's safe and secure (which it sounds like it will be) it's as good a solution as any and like I say, saves you wasting resources untill someone actually needs it (minor resources yes, but hey, every little helps :))

  • Damien Holley 179 posts 540 karma points
    Jan 11, 2019 @ 00:09
    Damien Holley
    1

    I use the nuget package PDFSharp to create and read PDFs. It's reasonably easy to use.

    You can also write to PDFs from XAML layouts in C#.

  • Matt Taylor 873 posts 2086 karma points
    Jan 14, 2019 @ 15:40
    Matt Taylor
    0

    Thanks,

    That one seems popular, so does Rotativa which I have been exploring.

Please Sign in or register to post replies

Write your reply to:

Draft