Unplanned
Last Updated: 19 Feb 2021 08:24 by ADMIN
Greg Lesniakiewicz
Created on: 17 Feb 2021 15:14
Category: PdfProcessing
Type: Feature Request
1
PdfProcessing: Provide an option to insert widgets in a table cell
This functionality is currently not supported both with the FixedContentEditor and RadFixedDocumentEditor.
4 comments
ADMIN
Dimitar
Posted on: 19 Feb 2021 08:24

Hi Greg,

Thank you for your feedback I will pass it to the team. Please note that voting is only used to identify features that are in high demand and helps us prioritize such features. Having fewer votes or even 0 does not mean that will not implement a specific feature. 

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Greg Lesniakiewicz
Posted on: 18 Feb 2021 23:17

Hi Dimitar,

 

I understand the challenge of the pdf format, but by developing RadFixedDocumentEditor you provide easier interface for pdf creation which is more in line with other formats - much more structured, xml like. Which is great, but it has only value if it supports all common components of pdf and widgets/annotations are such a component. So to me it is an important feature to include it in the Editor implementation, rather than treat it as optional component and get your users to vote for it. 

Having said that I do appreciate workaround that you suggested which might be something I am actually going to use. I would suggest to put it in your documentation somewhere close to Block.InsertForm as usually if anyone wants to add widget via form to the block while creating a table, the intention is to put it inside a cell.

Thanks for your suggestion!

Regards,

Greg

ADMIN
Dimitar
Posted on: 18 Feb 2021 07:36

Hello Greg,

The pdf format is different than the format we are used to in MS Word or other commonly used editors. 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. This approach requires more work and is a bit complex but I believe that it will work for your scenario. Here is a sample implementation that shows it:

var doc = new RadFixedDocument();

var editor = new RadFixedDocumentEditor(doc);
editor.InsertRun("Sample Document");

Table table = new Table();
for (int i = 0; i < 100; i++)
{
    TableRow row = table.Rows.AddTableRow();
    for (int j = 0; j < 5; j++)
    {
        var cell = row.Cells.AddTableCell();
        cell.Blocks.AddBlock().InsertText("Test");
    }
}
TableRow lastRow = table.Rows.AddTableRow();
var lastCell = lastRow.Cells.AddTableCell();
lastCell.Blocks.AddBlock().InsertText("##FieldHolder");

editor.InsertTable(table);

var provider = new PdfFormatProvider();
var docBytes = provider.Export(doc);

var document = provider.Import(docBytes);

SimplePosition holderPosition = new SimplePosition();
RadFixedPage holderPage = null;

foreach (var page in document.Pages)
{
    foreach (var element in page.Content)
    {
        if (element is TextFragment fragment)
        {
            if (fragment.Text == "##FieldHolder")
            {
                var fragmentPosition = fragment.Position;
                holderPosition.Translate(fragmentPosition.Matrix.OffsetX, fragmentPosition.Matrix.OffsetY);
                holderPage = page;
                fragment.Text = "";
            }
        }
    }
}

TextBoxField textField = new TextBoxField("SampleTextBox")
{
    MaxLengthOfInputCharacters = 500,
    IsMultiline = true,
    IsPassword = false,
    IsFileSelect = false,
    ShouldSpellCheck = true,
    AllowScroll = true,
    Value = "Sample content",
};

VariableContentWidget widget = textField.Widgets.AddWidget();
widget.Rect = new Rect(new Point(holderPosition.Matrix.OffsetX, holderPosition.Matrix.OffsetY), new Size(250, 50));
widget.RecalculateContent();

document.AcroForm.FormFields.Add(textField);
holderPage.Annotations.Add(widget);

File.WriteAllBytes(@"..\..\result.pdf", provider.Export(document));

I hope this helps.  

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Greg Lesniakiewicz
Posted on: 17 Feb 2021 15:34
Without it the widgets are pretty much useless...