PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Nov 08, 2024 11:41 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Feb 22, 2024 10:33 pm 
Offline

Joined: Thu Feb 22, 2024 10:28 pm
Posts: 2
Hello everyone,

I have been struggling to figure out how to highlight a textfield. My current code looks like this:

public static void highlightPDF(PdfAcroForm form, string fieldName)
{
PdfAcroField field = form.Fields[fieldName];
PdfTextField txtField;
if ((txtField = field as PdfTextField) != null)
{
txtField.BackColor = PdfSharp.Drawing.XColors.Yellow;
}
}

Nothing happens with this solution however, the variable is showing that it is the color yellow but it doesn't appear that way on my pdf file.

I have tried finding the position of a textfield then drawing a rectangle over it but that solution fell short since it only works for the first element on my pdf for some reason.
Any advice would be greatly appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 04, 2024 10:11 pm 
Offline

Joined: Thu Feb 22, 2024 10:28 pm
Posts: 2
If anyone runs into this problem, here is what I did:

PdfTextField txtField = (PdfTextField)field;
PdfArray fieldRect = (PdfArray)txtField.Elements.GetValue(PdfAnnotation.Keys.Rect);
PdfRectangle rect = txtField.Elements.GetRectangle(PdfAnnotation.Keys.Rect);
XRect rectangle = new XRect(rect.X1, rect.Y1, rect.Width, rect.Height);
XRect pdfPosition = gfx.Transformer.WorldToDefaultPage(rectangle);
XBrush backgroundBrush = new XSolidBrush(XColor.FromArgb(64, XColors.Yellow));
XBrush borderBrush = new XSolidBrush(XColor.FromArgb(128, XColors.Yellow));

gfx.DrawRectangle(backgroundBrush, pdfPosition);
gfx.DrawRectangle(borderBrush, pdfPosition);


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 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