Create Multipage PDF
Creates multipage PDF with personalized wedding invitations.
Сode Snippet
// A list of variable data
var names = new[]
{
"NICK",
"MICHAEL",
"JOHN",
};
using (var reader = new PdfReader("wedding-invitation-5x7in-vdp.pdf"))
using (var template = reader.Frames[0].GetContent())
using (var writer = new PdfWriter("wedding-invitation-5x7in-vdp_out.pdf"))
using (var gr = writer.GetGraphics())
using (var fr = new CustomFontRegistry())
{
var psName = fr.Add("Montserrat-Medium.ttf");
foreach (var name in names)
{
writer.AddPage(template.Width, template.Height, template.DpiX, template.DpiY);
gr.FontRegistry = fr;
// The content of this container will be written only with the first call. All further calls will reference the existing content.
gr.DrawContainer(template, 0, 0);
// Let's draw the text at the specified point.
var text = new PlainText(name, gr.CreateFont(psName, 10))
{
Position = new System.Drawing.PointF(250, 105),
};
text.ParagraphStyle.Alignment = TextAlignment.Center;
text.Brush = new SolidBrush(CmykColor.FromPercentages(0.43f, 0.418f, 0.483f, 0.279f, 1));
gr.DrawText(text);
}
}
Input
wedding-invitation-5x7in-vdp.pdf
DownloadMontserrat-Medium.ttf
DownloadOutput
wedding-invitation-5x7in-vdp_out.pdf
Downloadwedding-invitation-5x7in-vdp_out.png
For AI-assisted development: Download Graphics Mill Code Samples XML Catalog