PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jun 15, 2019 10:49 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jun 01, 2016 8:00 am 

Joined: Wed Jun 01, 2016 7:45 am
Posts: 1
Hello Guys,

I´ve created a fillable PDF with OpenOffice and now I want to change the background color of the textbox. For this I use the following code:

PdfDocument Template = PdfReader.Open("MyPath", PdfDocumentOpenMode.Modify);
PdfAcroField.PdfAcroFieldCollection Form = Template.AcroForm.Fields;

if (Field.GetType() == typeof(PdfTextField))
   PdfTextField CurrentField = (PdfTextField)Field;
   CurrentField.ReadOnly = false;
   CurrentField.Value = new PdfString("Test");
   CurrentField.BackColor = Color.Red;

If I run this code, the background of the textbox doesn´t change the color, but the value of the textbox changed to "Test". How can I change the background of the textbox?

I also want to copy a screenshot into my PDF. So I use a textfield to define the position of the image. The image should be placed at the same position as the textbox.
So I read out the position of the textfield:

PdfArray ImagePosition = (PdfArray)CurrentField.Elements["/Rect"];
double[] Imageformat = {
   Convert.ToDouble(ImagePosition.Elements[0].ToString(), CultureInfo.InvariantCulture),
   Convert.ToDouble(ImagePosition.Elements[1].ToString(), CultureInfo.InvariantCulture),
   Convert.ToDouble(ImagePosition.Elements[2].ToString(), CultureInfo.InvariantCulture),
   Convert.ToDouble(ImagePosition.Elements[3].ToString(), CultureInfo.InvariantCulture)

I´ve got the information that the first element is the x-coordinate, the second is the y-coordinate and the third and the fourth are the width and the height of the textbox. If I use this informations to place an image above the textbox, the image will be placed wrong:

XGraphics Graphic = XGraphics.FromPdfPage(Template.Pages[1]);

XImage image = XImage.FromGdiPlusImage((Bitmap)Parameter.ParameterValue);
Graphic.DrawImage(image, Imageformat[0], Imageformat[1], Imageformat[2], Imageformat[3]);

How can I place the image above the textbox?

Thank you for help!

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group