I would like to insert a jpg at specified or predefined (field) location in the PDF, is it possible?
My code based is .Net Core c#, thank you.
2 Answers, 1 is accepted
0
Dimitar
Telerik team
answered on 20 Feb 2020, 02:09 PM
Hi Jimmy,
Here is how you can get the location and draw an image:
var provider = new PdfFormatProvider();
var document = provider.Import(File.ReadAllBytes(@"..\..\doc1.pdf"));
var fields = document.AcroForm.FormFields;
var imageStream = new FileStream(@"..\..\green_tick.png", FileMode.Open);
foreach (var item in fields)
{
item.IsReadOnly = true;
var widget = item.Widgets.FirstOrDefault();
var page = widget.Parent as RadFixedPage;
var editor = new FixedContentEditor(page);
editor.SavePosition();
editor.Position.Translate(widget.Rect.X - 64, widget.Rect.Y);
editor.DrawImage(imageStream);
editor.RestorePosition();
}
using (FileStream fs = new FileStream(@"..\..\result.pdf", FileMode.OpenOrCreate))
{
provider.Export(document, fs);
}
Let me know how this works for you.
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.Learn More.