PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Using fillable Forms in PDFSharp https://forum.pdfsharp.net/viewtopic.php?f=2&t=3370 |
Page 1 of 1 |
Author: | Kampi [ Wed Jun 01, 2016 8:00 am ] |
Post subject: | Using fillable Forms in PDFSharp |
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: 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: Code: 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: Code: 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! |
Author: | gaweringo [ Tue Aug 13, 2024 8:35 pm ] |
Post subject: | Re: Using fillable Forms in PDFSharp |
For anyone stumbling over this in the future. I had the same problem as the second issue discussed here (wrong positioning). For me, the /Rect array had the Values in this order: Code: Left Bottom Right Top with bottom and top being the distance from the bottom edge of the page and left and right from the left edge.
|
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |