Telerik Forums
Telerik Document Processing Forum
3 answers
280 views

I want to use a then close a RadFlowDocument. 

My current process (will post code):

Open existing RadFlowDocument (word document).

Use RadFlowDocumentEditor to ReplaceText

Save the RadFlowDocument (now edited) as a new RadFlowDocument.  (now it is open on my machine).

Serialize the saved document to send it as an e-mail attachment.

Open the initial RadFlowDocument again

Use RadFlowDocumentEditor to ReplaceText again with a different value

Now I can't serialize the RadFlowDocument because it is open on my machine.

I'm using C# and Blazor

 

Code Sample (This is mostly from https://github.com/telerik/document-processing-sdk/blob/master/WordsProcessing/GenerateDocument/DocumentGenerator.cs)

private RadFlowDocument _document;

protected void OnMySendCommand(GridCommandEventArgs args)

{

OpenFile(fileName);

RadFlowDocumentEditor editor = new RadFlowDocumentEditor(_document);

editor.ReplaceText("Invoice_Number", "T1234567", false, false);

Save("docx", newFileName);

byte[] output = File.ReadAllBytes(newFileName + ".docx");

InsertEmail("myemail@my.com", "Test word file", "Test 1234567", output, "T1234567", true);

 

//Next invoice:

OpenFile(fileName);

editor = new RadFlowDocumentEditor(_document);

editor.ReplaceText("Invoice_Number", "T9999", false, false);

Save("docx", newFileName);

byte[] output2 = File.ReadAllBytes(newFileName + ".docx"); //Error now says:  The process cannot access the file 'E:\Workspace\Intranet\CPE\CPE\Pages\Classes\Invoices\InvoiceTemplate2.docx' because it is being used by another process.

//To Be Clear - it did replace the text and save it to my machine but now can't access the file because it is in use.  

//If necessary, I could save each file with a different file name.  But I would still want to close them programmatically.

}

 

Thanks for any help!

 

Dimitar
Telerik team
 answered on 17 Mar 2021
5 answers
329 views

Hello,

Could someone point me in the right direction for adding a line chart to a PDF. 

In the past I've rendered charts in a browser and exported the image so I can drop it into a PDF document.  This requires user interaction to load the page into a browser in order to render the chart.

I am keen to understand if I can utilise some of the Telerik chart functionality to render a chart when the PDF is generated (I'm currently using RadFixedDocument) - or is it a case of actually drawing the chart?

Thanks

Chris

Dimitar
Telerik team
 answered on 17 Mar 2021
3 answers
1.4K+ views

Real beginner question here but need some pointers on sizing in a PDF document. 

Can anyone explain sizing in PdfProcessing?

First question - How is the page size defined for RadFixedDocument, does is default to A4 or is there some kind of measurement setting applied by default?  Does this same metric apply to the rest of the document (e.g. is it all mm/pixels or some other measurement)

RadFixedDocument document = new RadFixedDocument();

Second question

How is image size in pixels relative to the sizing on the page itself.  In the sample below, imageSource.Width is pixels taken from the actual image, how does that translate to a relative size on the page?

 

Martin
Telerik team
 answered on 12 Mar 2021
3 answers
171 views

Hi,

 

I'd like to suggest you split your assemblies so they are more efficient for server side use.  Currently if you want to do some PDF processing on the server from the namespace `Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Streaming` you end up loading presentation framework dlls on the server which is unnecessary.  If you look at the manifest for Telerik.Windows.Documents.Core.dll you will see

 

.assembly extern PresentationFramework
{
  .publickeytoken = (31 BF 38 56 AD 36 4E 35 )                         // 1.8V.6N5
  .ver 4:0:0:0
}
.assembly extern System.Xaml
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern System.Drawing
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 4:0:0:0
}
.assembly Telerik.Windows.Documents.Core
{

This ends up loading unnecessary dlls, including System.Windows.Forms in IIS (if you are hosting the server in IIS).

Dimitar
Telerik team
 answered on 11 Mar 2021
2 answers
121 views

I have a requirement to write the value "#N/A" but as an error not the text.

I tried to use SetCell with value "#N/A" but it seems that excel will not recognize this cell as an error because when the file is opened with an excel in another language the value remains "#N/A" (In German for instance the value should be converted to "#NV")

Dan
Top achievements
Rank 1
Iron
Iron
Veteran
 answered on 08 Mar 2021
0 answers
296 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
1.4K+ 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
417 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
1.6K+ 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
193 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
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?