This is a migrated thread and some comments may be shown as answers.

PdfProcessing

2 Answers 165 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Iron
Veteran
Jimmy asked on 20 Feb 2020, 10:10 AM

Hi

 

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

Sort by
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.
Bhusan
Top achievements
Rank 1
commented on 11 May 2021, 07:54 AM | edited

.
0
Dimitar
Telerik team
answered on 11 May 2021, 11:20 AM

Hello Jimmy,

Create a MemoryStream from the byte array. For example: 

var imagebytes = File.ReadAllBytes(@"..\..\tick.png");
var image = new MemoryStream(imagebytes);

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Answers by
Dimitar
Telerik team
Share this question
or