From fd4852b3304015437ad90ee32cfca13bb72417dc Mon Sep 17 00:00:00 2001 From: KB Bot Date: Tue, 21 Oct 2025 10:27:52 +0000 Subject: [PATCH 1/2] Added new kb article aligning-centered-right-margin-text-pdf-telerik-document-processing --- ...in-text-pdf-telerik-document-processing.md | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md diff --git a/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md b/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md new file mode 100644 index 00000000..2111e5c5 --- /dev/null +++ b/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md @@ -0,0 +1,87 @@ +--- +title: Positioning Centered and Right-Aligned Text on the Same Line in PDF +description: Learn how to position centered text and right-aligned text on the same line in a PDF using Telerik Document Processing (RadPdfProcessing). +type: how-to +page_title: Aligning Centered and Right-Margin Text in PDF Using Telerik Document Processing +meta_title: Aligning Centered and Right-Margin Text in PDF Using Telerik Document Processing +slug: aligning-centered-right-margin-text-pdf-telerik-document-processing +tags: pdf, processing,document, position, text, center, right, align, block, measure +res_type: kb +ticketid: 1701532 +--- + +## Environment + +| Version | Product | Author | +| ---- | ---- | ---- | +| 2025.3.806| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| + +## Description + +I want to display centered text and right-aligned text on the same line in a PDF. The centered text varies in length, as does the text in the margin. The goal is to manually position each text block as there is no built-in feature for this layout. + +This knowledge base article also answers the following questions: +- How can I align text to the center and right margin on the same line in a PDF? +- How do I calculate positions for text blocks in Telerik Document Processing? +- How can I measure text width and adjust its position in the PDF? + +## Solution + +To position centered and right-aligned text on the same line, follow these steps: + +1. Measure Text Widths: Use the `Block.Measure()` method to determine the width of both the centered text and the right-margin text. Refer to [Measuring Block Size](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/block#measuring-block-size) for details. + +2. Calculate Positions: + - For centered text, calculate the X position by subtracting the text width from the page width and dividing by two. + - For right-margin text, set the X position close to the right edge by subtracting the text width and any desired margin. + +3. Draw Blocks Separately: + - Use `FixedContentEditor.Position.Translate(x, y)` to move to the calculated positions. + - Draw each block using individual `Block` objects. + +Here is an example: + +```csharp +RadFixedDocument document = new RadFixedDocument(); +RadFixedPage page = document.Pages.AddPage(); +FixedContentEditor editor = new FixedContentEditor(page); + +string centeredText = "This is Centered text"; +string rightMarginText = "Right"; + +Block centerBlock = new Block(); +centerBlock.InsertText(centeredText); +Telerik.Documents.Primitives.Size centerSize = centerBlock.Measure(); + +Block rightBlock = new Block(); +rightBlock.InsertText(rightMarginText); +Telerik.Documents.Primitives.Size rightSize = rightBlock.Measure(); + +double pageWidth = page.Size.Width; +double yPosition = 100; // Example Y position + +// Centered text +double centerX = (pageWidth - centerSize.Width) / 2; +editor.Position.Translate(centerX, yPosition); +editor.DrawBlock(centerBlock); + +// Right margin text +double rightX = pageWidth - rightSize.Width - 20; // 20 for right margin +editor.Position.Translate(rightX, yPosition); +editor.DrawBlock(rightBlock); + +// Save the document +var pdfFormatProvider = new PdfFormatProvider(); +string outputFilePath = "StyledDocument.pdf"; +using (var output = File.Create(outputFilePath)) +{ + pdfFormatProvider.Export(document, output, TimeSpan.FromHours(10)); +} +Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true }); +``` + +## See Also + +- [FixedContentEditor](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/fixedcontenteditor) +- [Measuring Block Size](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/block#measuring-block-size) +- [Block Class](https://docs.telerik.com/devtools/document-processing/api/telerik.windows.documents.fixed.model.editing.block) From 5ecf46703925a8d54ae82c52ca521ee917eaeb22 Mon Sep 17 00:00:00 2001 From: Desislava Yordanova Date: Tue, 21 Oct 2025 14:34:57 +0300 Subject: [PATCH 2/2] polished --- ...in-text-pdf-telerik-document-processing.md | 24 +++++++++++------- ...n-text-pdf-telerik-document-processing.png | Bin 0 -> 5622 bytes libraries/radpdfprocessing/editing/block.md | 1 + .../editing/fixedcontenteditor.md | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 knowledge-base/images/aligning-centered-right-margin-text-pdf-telerik-document-processing.png diff --git a/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md b/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md index 2111e5c5..ade5c2ff 100644 --- a/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md +++ b/knowledge-base/aligning-centered-right-margin-text-pdf-telerik-document-processing.md @@ -9,6 +9,11 @@ tags: pdf, processing,document, position, text, center, right, align, block, mea res_type: kb ticketid: 1701532 --- + ## Environment @@ -18,18 +23,20 @@ ticketid: 1701532 ## Description -I want to display centered text and right-aligned text on the same line in a PDF. The centered text varies in length, as does the text in the margin. The goal is to manually position each text block as there is no built-in feature for this layout. +Learn how to generate a PDF document with centered text and right-aligned text on the same line. The centered text varies in length, as does the text in the right margin. The goal is to manually position each text block as there is no built-in feature for this layout. -This knowledge base article also answers the following questions: -- How can I align text to the center and right margin on the same line in a PDF? -- How do I calculate positions for text blocks in Telerik Document Processing? -- How can I measure text width and adjust its position in the PDF? +This knowledge base article also shows how to: +* Align text to the center and right margin on the same line in a PDF +* Calculate positions for text blocks in RadPdfProcessing +* Measure text width and adjust its position in the PDF + +![Positioning Centered and Right-Aligned Text ><](images/aligning-centered-right-margin-text-pdf-telerik-document-processing.png) ## Solution To position centered and right-aligned text on the same line, follow these steps: -1. Measure Text Widths: Use the `Block.Measure()` method to determine the width of both the centered text and the right-margin text. Refer to [Measuring Block Size](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/block#measuring-block-size) for details. +1. Measure Text Widths: Use the `Block.Measure()` method to determine the width of both the centered text and the right-margin text. Refer to [Measuring Block Size]({%slug radpdfprocessing-editing-block%}#measuring-block-size) for details. 2. Calculate Positions: - For centered text, calculate the X position by subtracting the text width from the page width and dividing by two. @@ -82,6 +89,5 @@ Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecut ## See Also -- [FixedContentEditor](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/fixedcontenteditor) -- [Measuring Block Size](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/block#measuring-block-size) -- [Block Class](https://docs.telerik.com/devtools/document-processing/api/telerik.windows.documents.fixed.model.editing.block) +- [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%}) +- [Block Element]({%slug radpdfprocessing-editing-block%}) diff --git a/knowledge-base/images/aligning-centered-right-margin-text-pdf-telerik-document-processing.png b/knowledge-base/images/aligning-centered-right-margin-text-pdf-telerik-document-processing.png new file mode 100644 index 0000000000000000000000000000000000000000..fd6b19561950f2a4fba35f22d95613fd10ea522e GIT binary patch literal 5622 zcmb7{c{r5c`^O(!YD&g3MG}U>WDjM_5Ml_!%-FI-cCrpaHDSb9G9uYZB+QuX%SZO? zTZ=7ZvQA29$dYY-)A#rNs;^aKKJw7_c_n&+$Y}L^g0*l3tn`smC&?QpJ$R09vK{?6X+x5=Ed z01KIeO@_Uc$+EgGC-ij)VLV(%AqkH$FFkygbrR{|w6W{Rmve2=79x@>g@h*=8n^P5*) zgVW58#NYlRPO-Q`J}dj8w9Vtgg$xmn_}h(4Nr7x4H||vJp=3);d~mjwa4PWl<4L_5 zgjfvDi#5JO=UlU@a&lRJ+v2XULsnKfw>Lk;3Et zx=7@Hg(hTzxiFsl*V0sVRI@ykW2T!+r|uPIi#vIMYAB4bc14dx4 z&Gaa77*7n3l5!O-jW@yb((5OzZEK_Tep^4HYzqVRh9xN$BOYyeU&F&2MS1gdl0vV0 z0_=e{g=GZ=1$>m$`x!sqv^;ym`bac|lN(dY9(VAW>yOKX-Uz`1Ql`F^^5eX!={T%U zvHx5?`t_hW|KeN?@k)$Ki&e}*g1R5C*b`dGHM`D5R*i~F#!|kx7Q3&Mm=nw>vaZ-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