We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create PDF dynamically and email as attachment ?

Platform: WinForms |
Control: PDF
Tags: pdf, attachment, email

The PDF can be created dynamically and send email with an attachment, please find the code example and sample below for the same.

// Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
// Add a page to the document.
PdfPage page = document.Pages.Add();
// Create PDF graphics for the page.
PdfGraphics g = page.Graphics;
// Create a solid brush
PdfBrush brush = new PdfSolidBrush(Color.Black);
// Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20f);
// Draw the text.
g.DrawString("Hello world!", font, brush, new PointF(20, 20));
MemoryStream ms = new MemoryStream();
// Save and close the document.
//Reset the memory stream position.  
ms.Position = 0;
//Attach the file
Attachment file = new Attachment(ms ,"Attachment.pdf", "application/pdf");
using (SmtpClient smtp = new SmtpClient("xxxx.co.in"))
MailMessage message = new MailMessage();
// end-user customization
message.From = new MailAddress("yyyy@gmail.com");
message.Subject = "message";
message.IsBodyHtml = false;

Sample link:


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile