Hello,
Is it possible to insert text or graphic in an existing PDF in a existing page.
Thanks.
Best Regards
static void Main(string[] args)
{
PdfDocument document = new PdfDocument();
document.LoadFromFile(@"..\..\test.pdf");
PdfPageBase page = document.Pages[0];
DrawGraphics(page);
PdfSolidBrush brush = new PdfSolidBrush(Color.Green);
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 20f);
// draw text
page.Canvas.DrawString("Hello World", font, brush, 20, 400);
document.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");
}
static void DrawGraphics(PdfPageBase page)
{
PointF[] points = new PointF[5];
for (int i = 0; i < points.Length; i++)
{
float x = (float)Math.Cos(i * 2 * Math.PI / 5);
float y = (float)Math.Sin(i * 2 * Math.PI / 5);
points[i] = new PointF(x, y);
}
PdfPath path = new PdfPath();
path.AddLine(points[2], points[0]);
path.AddLine(points[0], points[3]);
path.AddLine(points[3], points[1]);
path.AddLine(points[1], points[4]);
path.AddLine(points[4], points[2]);
//save graphics state
PdfGraphicsState state = page.Canvas.Save();
PdfPen pen = new PdfPen(Color.DeepSkyBlue, 0.02f);
page.Canvas.ScaleTransform(50f, 50f);
page.Canvas.TranslateTransform(2f, 5f);
page.Canvas.DrawPath(pen, path);
PdfRadialGradientBrush brush = new PdfRadialGradientBrush(new PointF(0f, 0f), 0f, new PointF(0f, 0f), 1f, Color.Red, Color.Blue);
page.Canvas.TranslateTransform(3f, 0.1f);
path.FillMode = PdfFillMode.Winding;
page.Canvas.DrawPath(pen, brush, path);
//restore graphics
page.Canvas.Restore(state);
}
page.Canvas.DrawString("This is position test", font, brush, position)
Dim pdfdocument As New PdfDocument
pdfdocument.LoadFromFile("Sample.pdf")
Dim page As PdfPageBase
page = pdfdocument.Pages(0)
Dim font As PdfFont = New PdfFont(PdfFontFamily.Helvetica, 10.0F)
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Blue)
Dim position As PointF = New PointF(100, 100)
page.Canvas.DrawString("This is position test", font, brush, position)
pdfdocument.SaveToFile("result.pdf", FileFormat.PDF)