Telerik Forums
Telerik Document Processing Forum
0 answers
44 views

Hey,

I have a need to search for text fragments in a PDF page and convert these to navigable Hyperlinks.

Using: string documentContent = provider.Export(document); to export the full PDF document text fragments finds the text fragments properly, but is unusable as it doesn't preserve the content element that contains the text as I am required to insert a link at the same positional data.

I have also tried this code snippet with no luck as it seems to only return individual character data.  The provider.Export(...) method does return the text fragments that are being searched properly, but how to enumerate the text elements in a page similar to what Export() is doing is where I need help with. 

What is wrong with the method below for processing out the text fragments?  Apparently the provider.Export() method that is baked in has another way of reading and forming the full text fragments that I need to copy or mimic as to preserve the positional information for the text fragment.

private void SearchTextFragment(RadFixedDocument document, string searchText)
       {
           foreach (var page in document.Pages)
           {
               foreach (var contentElement in page.Content)
               {
                   if (contentElement is TextFragment)
                   {
                       string text = (contentElement as TextFragment).Text;
                       if (text.IgnoreCaseEqual(searchText))
                       {
  
                       }
                   }
               }
           }
       }
Bill
Top achievements
Rank 1
 asked on 07 Mar 2021
7 answers
284 views
Hi Telerik Team,

I was able to use ZipPackage to zip all the files that I have in a folder into a new zip file.
Note: The folder contains different file types .zip, .pdf, .xlsx .docx and .txt
However a new requirement is to encrypt the main zip file so no one can access the content of the file without having the password.
I have seen the sample below but I don't know how to get it to work with different existing binary files like PDF.

using (Stream stream = File.Open("test.zip", FileMode.Create))
{
    using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, false, null))
    {
        using (ZipArchiveEntry entry = archive.CreateEntry("text.txt"))
       {
            StreamWriter writer = new StreamWriter(entry.Open());
            writer.WriteLine("Hello world!");
            writer.Flush();
        }
    }
}

Can you help?
Peshito
Telerik team
 answered on 04 Mar 2021
2 answers
40 views

Hello,

I'm trying to create a PDF file from a Xamarin app.

Everything went well until I add text with accent (it's quite embarasing for me, because all my texts are in French).

I know that the 14 Standard fonts are withou accent. 

 

So i try to add a FontsProvider to add a MyriadPro.ttf file (which is also Embedded a ressource in my Android and Ios projets),  as explained here : https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/cross-platform , with the using of the Environment.SpecialFolder.Fonts folder

I put the provider class and initiate it in my create method.

But when i don't know how to add the .tff file to the Environment.SpecialFolder.Fonts

 

 

When a call my fontfamily with this line (from the Xamarin sample app) :  this.SetTextProperties(block, RgbColors.Black, 25, new FontFamily("MyriadPro"))

The custom Fontprovider is called as expected, but a have a exception, because the folder : /data/user/0/com.xxx.xxxx/files/.fonts is not found

My question is : how to add my ttf to the SpecialFolder.fonts , in my Android and Ios project ?

 

Thanks for you help, 

Guittier
Top achievements
Rank 1
 answered on 25 Feb 2021
1 answer
74 views

Hi there,

I have an existing PDF and want to put an image at a certain x and y position and save the result into a new PDF. Is there someone who can provide a sample on how to achieve this?

Thanks in advance!

Martin
Telerik team
 answered on 19 Feb 2021
1 answer
7 views

Hi,

I am adding three tables one after another. Each table has different number of columns from one to three. I like every table have 100% width. All cells should have equal width (100% for table where row has one cell, 50% for table with two cells)
Tables gets merged together, instead of three tables I am getting one table with three rows. Cells gets wrong width. Row with one cell doesn’t have 100% width.

If I add empty paragraph between tables then all three tables get 100% width, but I am getting extra row between tables. Please take a look on the attached picture. First three tables get merged into one table with three rows. The rest of the tables have correct formatting but they do have extra row in-between. 

Here is code:

 

private RadFlowDocument CreateDocument()
{
var document = new RadFlowDocument();

var tableStyle = new Style("TableStyle", StyleType.Table)
{
Name = "Table Style No Borders"
};
tableStyle.TableProperties.Borders.LocalValue = new TableBorders(new Border(BorderStyle.Single));

tableStyle.TableProperties.Alignment.LocalValue = Alignment.Left;
tableStyle.TableCellProperties.VerticalAlignment.LocalValue = VerticalAlignment.Top;

document.StyleRepository.Add(tableStyle);


var editor = new RadFlowDocumentEditor(document);

//TABLE 1 WITH 3 CELLS
var table1 = AddTable(tableStyle, editor);
var row1 = AddTableRow(table1, 3);

AddParagraphMoveEditor(editor, row1, 0);
editor.InsertText("LOGO: ").FontWeight = FontWeights.Bold;

AddParagraphMoveEditor(editor, row1, 1);
editor.InsertText("Quotation Detail");

AddParagraphMoveEditor(editor, row1, 2);
editor.InsertText(DateTime.Now.ToString("MMMM d, yyyy h:m"));

editor.MoveToTableEnd(table1);

//TABLE 2 WITH 2 CELLS
var table2 = AddTable(tableStyle, editor);
var row2 = AddTableRow(table2, 2);

AddParagraphMoveEditor(editor, row2, 0);
editor.InsertText("Customer: ").FontWeight = FontWeights.Bold;

AddParagraphMoveEditor(editor, row2, 1);
editor.InsertText("Quotation No: ").FontWeight = FontWeights.Bold;

editor.MoveToTableEnd(table2);

//TABLE 3 WITH 1 CELL
var table3 = AddTable(tableStyle, editor);
var row3 = AddTableRow(table3, 1);
AddParagraphMoveEditor(editor, row3, 0);

editor.InsertText("Location: ").FontWeight = FontWeights.Bold;
editor.InsertText("location goes here");

editor.MoveToTableEnd(table3);
editor.InsertText("");


//TABLE 4 WITH 3 CELLS
var table4 = AddTable(tableStyle, editor);
var row4 = AddTableRow(table4, 3);

AddParagraphMoveEditor(editor, row4, 0);
editor.InsertText("LOGO: ").FontWeight = FontWeights.Bold;

AddParagraphMoveEditor(editor, row4, 1);
editor.InsertText("Quotation Detail");

AddParagraphMoveEditor(editor, row4, 2);
editor.InsertText(DateTime.Now.ToString("MMMM d, yyyy h:m"));

editor.MoveToTableEnd(table4);
editor.InsertText("");

//TABLE 5 WITH 2 CELLS
var table5 = AddTable(tableStyle, editor);
var row5 = AddTableRow(table5, 2);

AddParagraphMoveEditor(editor, row5, 0);
editor.InsertText("Customer: ").FontWeight = FontWeights.Bold;

AddParagraphMoveEditor(editor, row5, 1);
editor.InsertText("Quotation No: ").FontWeight = FontWeights.Bold;

editor.MoveToTableEnd(table5);
editor.InsertText("");

//TABLE 6 WITH 1 CELL
var table6 = AddTable(tableStyle, editor);
var row6 = AddTableRow(table6, 1);
AddParagraphMoveEditor(editor, row6, 0);

editor.InsertText("Location: ").FontWeight = FontWeights.Bold;
editor.InsertText("location goes here");

editor.MoveToTableEnd(table3);


return document;


private static Table AddTable(Style tableStyleNoBorders, RadFlowDocumentEditor editor)
{

var table = editor.InsertTable();

table.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 100);
table.StyleId = tableStyleNoBorders.Id;

return table;
}

private TableRow AddTableRow(Table table, int cells)
{
var row = table.Rows.AddTableRow();
var cellWidth = 100 / cells;

for (int i = 0; i < cells; i++)
{
var cell = row.Cells.AddTableCell();
cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, cellWidth);
}

return row;
}

private void AddParagraphMoveEditor(RadFlowDocumentEditor editor, TableRow row, int cellNumber)
{
var cellParagraph = row.Cells[cellNumber].Blocks.AddParagraph();
editor.MoveToParagraphStart(cellParagraph);

}

 

Dimitar
Telerik team
 answered on 19 Feb 2021
3 answers
13 views

Hello,

I need to add HTML content to my RadFlowDocument and then export it to PDF. 

The problem is when the HTML text contains a table with borders. Then the borders are not visible in the exported PDF.

C# code - import HTML text:

01.InsertDocumentOptions options = new InsertDocumentOptions
02.{
03.    ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.UseTargetStyle,
04.    InsertLastParagraphMarker = false
05.};
06.var firstPageText = myPdfModel.FirstPageText.ToString();
07.if (firstPageText != null)
08.{
09.    editor.InsertDocument(htmlFormatProvider.Import(firstPageText), options);
10.}

I use Kendo Editor to obtain HTML code. The generated HTML is:

01.<table>
02.   <tbody>
03.      <tr style="height:50%;">
04.         <td style="width:50%;border-width:2px;border-style:solid;border-color:#cc3333;">a</td>
05.         <td style="width:50%;border-width:2px;border-style:solid;border-color:#cc3333;">b</td>
06.      </tr>
07.      <tr style="height:50%;">
08.         <td style="width:50%;border-width:2px;border-style:solid;border-color:#cc3333;">c</td>
09.         <td style="width:50%;border-width:2px;border-style:solid;border-color:#cc3333;">d</td>
10.      </tr>
11.   </tbody>
12.</table>

In Kendo Editor the table looks fine (see screenshot) but in PDF there are no borders.

Is it a bug or do I have to set some options somewhere?

 

If it is a bug, suggest me some workaround please.

 

Best Regards,

Daniel

Daniel
Top achievements
Rank 1
 answered on 12 Feb 2021
1 answer
21 views

Hi,

We have a WPF solution with a blog, the blog messages are being saved into our database as RadDocuments.

Now we are building a MVC-solution which should also be able to show this blog.

 

 

The Problems are:

    1. how do I convert the RadDocument to HTML?

    2. how do I convert the RadDocument to RadFlowDocument so I can work with it in the Kendo.Editor?

 

Do you have examples on how to solve this?  RadDocument is loaded as a string from DB.

 

Regards Kristian

 

 

 

 

 

Dimitar
Telerik team
 answered on 03 Feb 2021
7 answers
20 views

Hello,

I'm doing some experiments with WordsProcessing and found an annoying problem.

In a docx document, I have a table in the header. The table height is 2.48cm.
In a test application, I've just opened the document and save it, using your library.
After that, I've opened the document in Word and the table height is not correct as it is only 1.46cm (that's the height of the text inside the table).

Looking at the in-memory data of the document, the height of the table row is set to "Auto".

Unfortunately, there is also a border on this table and it now looks ugly, not counting that the image in the header "crosses" the table border

I also have the same problem in the footer, that also contains a table. In this part, this is more annoying because the height of the footer is not respected and the whole document formatting is not correct.

Martin
Telerik team
 answered on 02 Feb 2021
3 answers
17 views

Hello,

I have a docx template file that contains both MERGEFIELD and CheckBox.

Using version 2021.1.118 of Telerik.Windows.Documents.Flow I perform MailMerge on that document.

After mailmerge the Checkbox control in the output document looses its style when being manually triggered. Manually triggering checkbox in original template does not change original style.

It's expected, that after mailmerge the Checkbox behaves as before mailmerge.

 

The complete demo is here:

https://github.com/vslynko/telerik-mailmerge-bugreport

Vladislav
Telerik team
 answered on 29 Jan 2021
1 answer
10 views

While evaluating Telerik.Documents.Spreadsheet.Trial (2021.1.118) I've encountered a bug with registering custom functions in .NET 5.

 

I'm using a console application, and trying to register a couple of functions right at the start of the Main() method. It works like a charm with target framework netcoreapp3.1.

But as soon as I bump the version to net5.0, registering a function throws an exception (I've copied the full stack below).

Perhaps you can guide me what happens? We're currently evaluating on upgrading our license for the latest features, but this thing could be crucial to us, since we need to use .NET 5 for a couple of reasons.

 

I'm calling them right at the start of the applicaption

public static void Main(string[] args)
{
  FunctionManager.RegisterFunction(new AAA());
  FunctionManager.RegisterFunction(new BBB());
  ...
}

 

Here's the exception stack:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager' threw an exception.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db' threw an exception.
 ---> System.ArgumentOutOfRangeException: Index and count must refer to a location within the string. (Parameter 'count')
   at System.String.Remove(Int32 startIndex, Int32 count)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.FindAllOccurrences(String value, String part)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.ReplaceSeparators(String formatString, Predicate`1 shouldReplaceWithGroupSeparator, Predicate`1 shouldReplaceWithDecimalSeparator, String newGroupSeparat
or, String newDecimalSeparator)
   at Telerik.Windows.Documents.Spreadsheet.Formatting.FormatHelper.ReplaceCultureSpecificSeparatorsWithDefaults(String formatString, Nullable`1 formatStringCategory)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellValueFormat..ctor(String formatString, Boolean convertToInvariant, Nullable`1 formatStringCategory)
   at Telerik.Windows.Documents.Spreadsheet.Model.CellValueFormat..ctor(String formatString)
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.Db..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Spreadsheet.Expressions.Functions.FunctionManager.RegisterFunction(FunctionBase function)
   at Iface.Oik.ScriptEngine.Program.Main(String[] args) in C:\Users\alexeid\Rider\Iface.Oik.ScriptEngine\src\Program.cs:line 20

Dimitar
Telerik team
 answered on 25 Jan 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Liu
Top achievements
Rank 1
Iron
Alex
Top achievements
Rank 1
Veteran
Iron
Iron
George C.
Top achievements
Rank 2
Iron
Veteran
Top users last month
Matthias
Top achievements
Rank 5
Bronze
Bronze
Iron
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Liu
Top achievements
Rank 1
Iron
Alex
Top achievements
Rank 1
Veteran
Iron
Iron
George C.
Top achievements
Rank 2
Iron
Veteran