From 2bd547179bc2ad0b18b7694de3c7403b002bd303 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Tue, 27 Aug 2024 10:58:50 +0000 Subject: [PATCH 1/4] Added new kb article get-textfragment-position-size-radpdfprocessing --- ...fragment-position-size-radpdfprocessing.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 knowledge-base/get-textfragment-position-size-radpdfprocessing.md diff --git a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md new file mode 100644 index 00000000..48d8dad6 --- /dev/null +++ b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md @@ -0,0 +1,65 @@ +--- +title: Getting Position and Size of TextFragment in PDF Documents +description: Learn how to retrieve the (x,y) position and dimensions of a TextFragment within a PDF document using RadPdfProcessing. +type: how-to +page_title: How to Determine TextFragment Position and Size in PDFs with RadPdfProcessing +slug: get-textfragment-position-size-radpdfprocessing +tags: radpdfprocessing, textfragment, position, size, document processing +res_type: kb +ticketid: 1662399 +--- + +## Environment + +| Version | Product | Author | +| --- | --- | ---- | +| 2024.3.806| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| + +## Description + +Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its `Position` property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. + +This KB article also answers the following questions: +- How can I find the exact location of a text in a PDF document? +- What is the method to determine the dimensions of a text segment within a PDF file? +- How to use the `MatrixPosition` for locating text in a PDF document? + +## Solution + +To obtain the (x,y) coordinates and the dimensions (width and height) of a `TextFragment`, follow these steps: + +1. **Extract the (x,y) Coordinates:** + + Each `TextFragment` has a `Position` property of type [MatrixPosition](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/position#matrixposition). The `MatrixPosition` object includes a `Matrix` that exposes `OffsetX` and `OffsetY` properties. These properties represent the fragment's offset from the top-left corner of the PDF page. + + ```csharp + float offsetX = textFragment.Position.Matrix.OffsetX; + float offsetY = textFragment.Position.Matrix.OffsetY; + ``` + +2. **Calculate the Size (Width and Height):** + + To determine the width and height of a `TextFragment`, leverage the measuring functionality of the `Block` object. First, insert the `TextFragment` into a `Block`, and then use the `Measure` method to find its size. + + ```csharp + private static Size GetFragmentSize(TextFragment textFragment) + { + Block block = new Block(); + block.Insert(textFragment); + Size textFragmentSize = block.Measure(); + return textFragmentSize; + } + ``` + +By following these steps, you can accurately locate a `TextFragment` within a PDF document and determine its size, enabling enhanced document processing and manipulation capabilities. + +## Notes + +- The `OffsetX` and `OffsetY` values pinpoint the location relative to the top-left corner of the PDF page. +- The `Measure` method of the `Block` object provides the width and height of the contained `TextFragment`, facilitating precise layout and positioning operations. + +## See Also + +- [Position Concept in RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/position) +- [TextFragment in RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/textfragment) +- [Extracting Text Within a Specific Rectangle in PDF Documents](https://docs.telerik.com/devtools/document-processing/knowledge-base/extract-text-specific-rectangle-pdf-radpdfprocessing) From a186703587328422e997a28233eb9aa7ed0fc7e6 Mon Sep 17 00:00:00 2001 From: Desislava Yordanova Date: Tue, 27 Aug 2024 17:55:12 +0300 Subject: [PATCH 2/4] add links --- .../get-textfragment-position-size-radpdfprocessing.md | 8 ++++---- libraries/radpdfprocessing/model/textfragment.md | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md index 48d8dad6..6efbb149 100644 --- a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md +++ b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md @@ -17,7 +17,7 @@ ticketid: 1662399 ## Description -Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its `Position` property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. +Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its ({%slug radpdfprocessing-concepts-position%}) property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. This KB article also answers the following questions: - How can I find the exact location of a text in a PDF document? @@ -60,6 +60,6 @@ By following these steps, you can accurately locate a `TextFragment` within a PD ## See Also -- [Position Concept in RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/concepts/position) -- [TextFragment in RadPdfProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/textfragment) -- [Extracting Text Within a Specific Rectangle in PDF Documents](https://docs.telerik.com/devtools/document-processing/knowledge-base/extract-text-specific-rectangle-pdf-radpdfprocessing) +- [Position Concept in RadPdfProcessing]({%slug radpdfprocessing-concepts-position%}) +- [TextFragment in RadPdfProcessing]({%slug radpdfprocessing-model-textfragment%}) +- [Extracting Text Within a Specific Rectangle in PDF Documents]({%slug extract-text-specific-rectangle-pdf-radpdfprocessing%}) diff --git a/libraries/radpdfprocessing/model/textfragment.md b/libraries/radpdfprocessing/model/textfragment.md index 90f2e2e5..4bf91e66 100644 --- a/libraries/radpdfprocessing/model/textfragment.md +++ b/libraries/radpdfprocessing/model/textfragment.md @@ -161,3 +161,4 @@ TextFragment exposes the following properties that can modify the look of the re * [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%}) * [Position]({%slug radpdfprocessing-concepts-position%}) * [Extracting Text Within a Specific Rectangle in PDF Documents]({%slug extract-text-specific-rectangle-pdf-radpdfprocessing%}) + * [Getting Position and Size of TextFragment in PDF Documents]({%slug get-textfragment-position-size-radpdfprocessing%}) From b49eb65c0aaa69ffa37247347eec4fbd2c4ec33b Mon Sep 17 00:00:00 2001 From: Desislava Yordanova Date: Wed, 4 Sep 2024 09:47:58 +0300 Subject: [PATCH 3/4] add image --- ...extfragment-position-size-radpdfprocessing.md | 2 ++ .../images/text-fragment-position-and-size.png | Bin 0 -> 9144 bytes 2 files changed, 2 insertions(+) create mode 100644 knowledge-base/images/text-fragment-position-and-size.png diff --git a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md index 6efbb149..de86af56 100644 --- a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md +++ b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md @@ -19,6 +19,8 @@ ticketid: 1662399 Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its ({%slug radpdfprocessing-concepts-position%}) property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. +![TextFragment Position and Size](images/text-fragment-position-and-size.png) + This KB article also answers the following questions: - How can I find the exact location of a text in a PDF document? - What is the method to determine the dimensions of a text segment within a PDF file? diff --git a/knowledge-base/images/text-fragment-position-and-size.png b/knowledge-base/images/text-fragment-position-and-size.png new file mode 100644 index 0000000000000000000000000000000000000000..297e54773fad31b678986bde79d5129424898e7a GIT binary patch literal 9144 zcmd^_XH-+|*XB{A1StYa2bB^~1Ofs|9{*31VWC!D(Pec$`qzw1Oj)l#9MVxuA zHcq1TezL4XFt-fKd3hb_4a#l%vxOXgZdmkuz+D73cm#4R%(!{kv%Rmvq547ZZOuhNIfgoC8FQn)@Y#Vwnu6*%*h zFmY3P0{cy2-DcIceg!PWW?L5j*LNJ4(2f8W@S;>WD1iWhb+}P8avvg4?-p3V%3B!7 z?RHUED<}LM9@V&D0;(-CY5P)BMM~OT({0t+PQFLfUf2`S%^iU}^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zAcg-rHThE`r8t(k3n8$`A(HTXo4!nY;N=D{f3-o{Sh-_Yx<}j>bn3CNTqER` SAn>*giP~c= Date: Wed, 4 Sep 2024 18:06:15 +0300 Subject: [PATCH 4/4] fix slug --- .../get-textfragment-position-size-radpdfprocessing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md index de86af56..f0aa1a40 100644 --- a/knowledge-base/get-textfragment-position-size-radpdfprocessing.md +++ b/knowledge-base/get-textfragment-position-size-radpdfprocessing.md @@ -17,7 +17,7 @@ ticketid: 1662399 ## Description -Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its ({%slug radpdfprocessing-concepts-position%}) property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. +Determining the precise location and size of a [TextFragment]({%slug radpdfprocessing-model-textfragment%}) in a PDF document is essential for various document processing tasks. A `TextFragment`'s position is accessible through its [Position]({%slug radpdfprocessing-concepts-position%}) property, which returns a `MatrixPosition`. This article outlines how to translate the `MatrixPosition` into (x,y) coordinates and how to calculate the width and height of a `TextFragment`. ![TextFragment Position and Size](images/text-fragment-position-and-size.png)