Filling Form Data from Database
Наши примеры проектов и шаблоны отчётов помогут Вам разобраться в основах работы с нашими продуктами.A shared form template can be filled per recipient from a database and each personalized PDF e-mailed out.
Read rows, fill the form, export and send.
How it works. One template drives many personalized documents, so a mail-merge over PDF forms runs straight from the database.
Read rows, fill the form, export and send.
using var connection = new MySqlConnection(connectionString);
connection.Open();
using var reader = new MySqlCommand("SELECT Name, Email FROM Recipients", connection).ExecuteReader();
while (reader.Read())
{
var form = new StiForm();
form.Load("Forms/Invitation.pdf");
// set the form's fields from the row, then export to PDF
var pdfBytes = form.ExportToByteArray(new StiPdfFormExportSettings());
var mail = new MailMessage("from@company.com", reader.GetString("Email"));
mail.Attachments.Add(new Attachment(new MemoryStream(pdfBytes), "form.pdf", MediaTypeNames.Application.Pdf));
new SmtpClient("smtp.company.com").Send(mail);
}StiForm.Load+ field assignment — open the shared template and fill it with the row's values.ExportToByteArray(StiPdfFormExportSettings)— render the filled form to PDF bytes for the attachment.SmtpClient.Send(MailMessage)— e-mail the personalized PDF to each recipient.
How it works. One template drives many personalized documents, so a mail-merge over PDF forms runs straight from the database.