-
Notifications
You must be signed in to change notification settings - Fork 41
Add new KB - Creating TableCells with GoToAction and UriAction #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DKaramfilov
merged 6 commits into
master
from
Maria/new-kb-creating-table-cells-with-gotoaction-and-uriaction
Dec 20, 2022
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2eac9b6
Add new KB - Creating TableCells with GoToAction and UriAction
mariaterzieva12 7f752bb
add changes to file
mariaterzieva12 a282dab
Add changes to the file
mariaterzieva12 c9b4496
include the component name in the .md file name.
mariaterzieva12 d33ce2c
dekete old file
mariaterzieva12 c176560
add minor changes
mariaterzieva12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
knowledge-base/creating-tablecells-with-gotoaction-and-uriaction.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| --- | ||
| title: Creating TableCells with GoToAction and UriAction | ||
| description: This article demonstrates how can create table cells with GoTo action and UriAction in PDF document with Telerik Document Processing. | ||
| type: how-to | ||
| page_title: Creating TableCells with GoToAction and UriAction | ||
| slug: kb-create-table-cells | ||
| position: 0 | ||
| tags: pdf, datatable, cells, widget | ||
mariaterzieva12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| res_type: kb | ||
| --- | ||
|
|
||
| |Product Version|Product|Author| | ||
| |----|----|----| | ||
| |N/A|RadPdfProcessing|Maria Terzieva| | ||
|
|
||
| ## Description | ||
|
|
||
| With the PDF format, each content element has a specific position, and in some cases, each character is positioned separately. PDF standard does not have any information about tables as well, once exported the tables in the document are represented by lines and text fragments. | ||
|
|
||
| Although the editors do not allow you to insert the widgets it is possible to insert a place holder and then use its postion to insert the widget. | ||
mariaterzieva12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Solution | ||
|
|
||
| First we need to create a table in the document. Next we have to iterate throught the elements of the page and to find the text fragment which we want. After that for creating Links to URLs or Locations within the document, we use Actions - UriAction or GoToAction. | ||
mariaterzieva12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Create TableCells with GoToAction and UriAction | ||
mariaterzieva12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ````C# | ||
mariaterzieva12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {{region kb-create-table-cells}} | ||
|
|
||
| RadFixedDocument document = new RadFixedDocument(); | ||
| using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document)) | ||
| { | ||
| Table table = new Table(); | ||
| Border border = new Border(BorderStyle.Single); | ||
| table.Borders = new TableBorders(left: border, top: border, right: border, bottom: border); | ||
| TableRow firstRow = table.Rows.AddTableRow(); | ||
| TableCell firstRowFirstCell = firstRow.Cells.AddTableCell(); | ||
| firstRowFirstCell.Borders = new TableCellBorders(left: border, top: border, right: border, bottom: border); | ||
| Block block1 = firstRowFirstCell.Blocks.AddBlock(); | ||
| block1.InsertText("Text in first cell."); | ||
|
|
||
| TableRow secondRow = table.Rows.AddTableRow(); | ||
| TableCell secondRowFirstCell = secondRow.Cells.AddTableCell(); | ||
| secondRowFirstCell.Borders = new TableCellBorders(left: border, top: border, right: border, bottom: border); | ||
| Block block2 = secondRowFirstCell.Blocks.AddBlock(); | ||
| block2.InsertText("Text in second cell."); | ||
|
|
||
| editor.InsertTable(table); | ||
| } | ||
|
|
||
| RadFixedPage secondPage = document.Pages.AddPage(); | ||
|
|
||
| foreach (RadFixedPage page in document.Pages) | ||
| { | ||
| foreach (ContentElementBase element in page.Content) | ||
| { | ||
| if (element is TextFragment textFragment) | ||
| { | ||
| if (textFragment.Text == "Text in first cell.") | ||
| { | ||
| Location location = new Location | ||
| { | ||
| Left = 225, | ||
| Top = 500, | ||
| Zoom = 1, | ||
| Page = secondPage | ||
| }; | ||
|
|
||
| GoToAction goToAction = new GoToAction | ||
| { | ||
| Destination = location | ||
| }; | ||
|
|
||
| Link goToLink = document.Pages[0].Annotations.AddLink(goToAction); | ||
| Rect clippingBounds = textFragment.Clipping.Clip.Bounds; | ||
| goToLink.Rect = new Rect(clippingBounds.X, clippingBounds.Y, clippingBounds.Width, clippingBounds.Height); | ||
| } | ||
| else if (textFragment.Text == "Text in second cell.") | ||
| { | ||
| UriAction uriAction = new UriAction | ||
| { | ||
| Uri = new Uri(@"http://www.telerik.com"), | ||
| }; | ||
|
|
||
| Link uriLink = document.Pages[0].Annotations.AddLink(uriAction); | ||
| Rect clippingBounds = textFragment.Clipping.Clip.Bounds; | ||
| uriLink.Rect = new Rect(clippingBounds.X, clippingBounds.Y, clippingBounds.Width, clippingBounds.Height); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| string outputPath = "Exported.pdf"; | ||
| if (File.Exists(outputPath)) | ||
| { | ||
| File.Delete(outputPath); | ||
| } | ||
|
|
||
| using (Stream output = File.OpenWrite(outputPath)) | ||
| { | ||
| PdfFormatProvider provider = new PdfFormatProvider(); | ||
| provider.Export(document, output); | ||
| } | ||
|
|
||
| Process.Start(new ProcessStartInfo() { FileName = outputPath, UseShellExecute = true }); | ||
|
|
||
| {{endregion}} | ||
|
|
||
| ```` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.