Highlight Text for Portrait PDF
Hello all,
while highlighting the text in existing pdf using C# platform i am facing issue of highlightion which highlights text vertically.
i have tried in all possible ways could you please anyone help me how to highlight text horizontally for portrait pdf
PdfLoadedDocument document = new PdfLoadedDocument(@"d:\LocalData\z015266\Desktop\OneDrive_1_30-07-2019\Updated\AA30-AC.PDF");
PdfDocument pdfDoc = PdfDocument.Merge(null, document) as PdfDocument;
//Gets the first page from the document
float width = pdfDoc.Pages[0].Size.Width;
float height = pdfDoc.Pages[0].Size.Height;
if (pdfDoc.Pages[0].Rotation == PdfPageRotateAngle.RotateAngle90 ||
pdfDoc.Pages[0].Rotation == PdfPageRotateAngle.RotateAngle270)
{
width = pdfDoc.Pages[0].Size.Height;
height = pdfDoc.Pages[0].Size.Width;
}
if (width > height)
{
pdfDoc.Sections[0].PageSettings.Orientation = PdfPageOrientation.Portrait;
}
else
{
pdfDoc.Sections[0].PageSettings.Orientation = PdfPageOrientation.Landscape;
pdfDoc.Sections[0].PageSettings.Size = new SizeF(width, height);
}
//Add a list to maintain extracted text information
List<TextData> extractedText = new List<TextData>();
//Extract text from first page
pdfDoc.Sections[0].Pages[0].ExtractText(out extractedText);
//for (var yu = 0; yu < arrvalues_smipp.Length; yu++)
//{
foreach (TextData textData in extractedText)
{
if (textData.Text == "F261")
{
PdfGraphics graphics = pdfDoc.Pages[0].Graphics;
Font font = new Font("Calibri", 10, FontStyle.Bold);
PdfFont pdfFont = new PdfTrueTypeFont(font, false);
PdfSolidBrush brush = new PdfSolidBrush(Color.DarkGreen);
PdfPen pen = new PdfPen(PdfBrushes.DarkMagenta, 5f);
float x_coordiante = textData.Bounds.Location.X - 3;
float y_coordinate = textData.Bounds.Location.Y - 10;
float width1 = textData.Bounds.Size.Width;
float height1 = textData.Bounds.Size.Height;
RectangleF rectangle = new RectangleF(x_coordiante, y_coordinate, width1, height1);
PdfTextMarkupAnnotation textmarkup = new PdfTextMarkupAnnotation("", "", textData.Text, new PointF(x_coordiante, y_coordinate), pdfFont);
textmarkup.TextMarkupColor = new PdfColor(Color.LightPink);
textmarkup.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight;
textmarkup.Rotate = PdfAnnotationRotateAngle.RotateAngle180;
pdfDoc.Sections[0].Pages[0].Annotations.Add(textmarkup);
}
}
pdfDoc.Save("HighlightText.pdf");
pdfDoc.Close(true);
Process.Start("HighlightText.pdf");
Thanks and Regards,
Yogesh
highlights
SIGN IN To post a reply.
1 Reply
SL
Sowmiya Loganathan
Syncfusion Team
August 5, 2019 12:49 PM UTC
Hi Yogesh,
Thank you for contacting Syncfusion support.
We have checked with the issue which you have mentioned with the provided code snippet, but in our end the text is highlighted as horizontal only. So we suspect that this to be a document specific issue, so could you please share the input PDF file which you have used in your end. It will helpful for us to provide the precise solution on this.
Regards,
Sowmiya L
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
YV Yogesh vasu
- Aug 2, 2019 05:53 PM UTC
- Aug 5, 2019 12:49 PM UTC