I want to set table line style like this attachment. How Can I set this table line style?
Borders I am creating with RadFlowDocumentEditor are not displayed in Radrichtextbox, to demonstrate here is my test code, I am using Telerik UI for WPF R2 2019.
Attached is the file, also how it is displayed in Word and the how it is displayed in the RadRichTextBox inside my application.
using
System.Windows;
using
System.Windows.Controls;
using
Telerik.Windows.Controls;
using
Telerik.Windows.Documents.FormatProviders.Html;
using
System.Linq;
using
System;
using
System.IO;
using
Telerik.Windows.Documents.Flow.Model;
using
Telerik.Windows.Documents.Flow.Model.Editing;
using
Telerik.Windows.Documents.Flow.Model.Styles;
using
Telerik.Windows.Documents.Spreadsheet.Model;
public
void
CreateCell(RadFlowDocumentEditor documentEditor, Table table,
int
row,
int
column,
string
text, FontWeight fw,
float
Width, Alignment alignment,
double
fs = 0)
{
while
(table.Rows[row].Cells.Count < (column + 1))
{
table.Rows[row].Cells.AddTableCell();
}
Paragraph newPara = table.Rows[row].Cells[column].Blocks.AddParagraph();
table.Rows[row].Cells[column].PreferredWidth =
new
TableWidthUnit(Width);
table.Rows[row].Cells[column].Padding =
new
Telerik.Windows.Documents.Primitives.Padding(2);
newPara.TextAlignment = alignment;
documentEditor.MoveToParagraphStart(newPara);
var line = documentEditor.InsertText(text);
line.FontWeight = fw;
if
(fs > 0) line.FontSize = fs;
}
private
void
radButtonTest_Click(
object
sender, RoutedEventArgs e)
{
//produce test doc
Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider =
new
Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
RadFlowDocument document =
new
RadFlowDocument();
RadFlowDocumentEditor documentEditor =
new
RadFlowDocumentEditor(document);
//create table
Table table = documentEditor.InsertTable(1, 3);
//header
double
fsText = Telerik.Windows.Documents.Model.Unit.PointToDip(10);
var row = 0;
CreateCell(documentEditor,table, row, 0,
"Time"
, FontWeights.Bold, 80, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 1,
"Type"
, FontWeights.Bold, 200, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 2,
"Location"
, FontWeights.Bold, 230, Alignment.Left, fsText);
table.Rows[row].Cells[0].Shading.BackgroundColor =
new
ThemableColor(Telerik.Windows.Documents.Spreadsheet.Theming.ThemeColorType.Accent1, 0.5);
table.Rows[row].Cells[1].Shading.BackgroundColor =
new
ThemableColor(Telerik.Windows.Documents.Spreadsheet.Theming.ThemeColorType.Accent1);
table.Rows[row].Cells[2].Shading.BackgroundColor =
new
ThemableColor(Telerik.Windows.Documents.Spreadsheet.Theming.ThemeColorType.Accent1, 0.9);
//add rows
table.Rows.AddTableRow();
row++;
CreateCell(documentEditor, table, row, 0, DateTime.Now.ToString(
"HH:mm:ss"
), FontWeights.Normal, 80, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 1,
"Value "
+ row.ToString(), FontWeights.Normal, 200, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 2,
"Loc "
+ row.ToString(), FontWeights.Normal, 230, Alignment.Left, fsText);
table.Rows[row].Cells[0].Borders =
new
TableCellBorders(
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.Double)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None));
table.Rows[row].Cells[1].Borders =
new
TableCellBorders(
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.Double)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None));
table.Rows[row].Cells[2].Borders =
new
TableCellBorders(
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.Double)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None)
,
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.None));
table.Rows.AddTableRow();
row++;
CreateCell(documentEditor, table, row, 0, DateTime.Now.ToString(
"HH:mm:ss"
), FontWeights.Normal, 80, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 1,
"Value "
+ row.ToString(), FontWeights.Normal, 200, Alignment.Left, fsText);
CreateCell(documentEditor, table, row, 2,
"Loc "
+ row.ToString(), FontWeights.Normal, 230, Alignment.Left, fsText);
table.Borders =
new
TableBorders(
new
Telerik.Windows.Documents.Flow.Model.Styles.Border(BorderStyle.Single));
//save test file
using
(Stream output =
new
FileStream(@
"c:\temp\testdoc.docx"
, FileMode.OpenOrCreate))
{
provider.Export(document, output);
}
}
How to keep an Image in the Spreadsheet Header?
currently in the RadSpreadDocuments.HeaderFooterSettings only it supports text in the Page Header but want to display the Image in the Header.
Can anyone know how to keep the image in the Header of the excel workbook?
I have a word doc that i created using RadFlowDocument and i want to convert this to a pdf. i have tried couple of ways and it never worked.
'Exporting the Rad Document to Word Document
Using output As Stream = File.OpenWrite(directoryPath + "FlexFab.docx")
Dim provider As DocxFormatProvider = New DocxFormatProvider()
provider.Export(document, output)
End Using
'Convert word to PDF
Dim fileFormatProvider As IFormatProvider(Of RadFlowDocument) = New DocxFormatProvider()
Using input As FileStream = New FileStream(filePath, FileMode.Open)
document = fileFormatProvider.Import(input)
End Using
fileFormatProvider = New PdfFormatProvider()
Using output2 As Stream = New FileStream(directoryPath + "FlexFab.pdf", FileMode.OpenOrCreate)
fileFormatProvider.Export(document, output2)
End Using
The Error that i am getting is :
Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider' to type 'Telerik.Windows.Documents.Common.FormatProviders.IFormatProvider`1[Telerik.Windows.Documents.Flow.Model.RadFlowDocument]'.
I also tried the below method and that dosent work either, is there a way i can achieve this.
Dim document As RadFlowDocument = CreateRadFlowDocument
Dim provider Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
Dim fixedDocument As RadFixedDocument = provider.ExportToFixedDocument(document);
I am having trouble positioning text using text fragment. I'm not sure if its a scaling issue during import or what
Below is an extract that failes
I created a PDF completely gray with a black box starting at 100x100 pixels from the top left corner (https://www.pastefile.com/sjKGiJ)
The Original PDF was created by printing a blank page from work through adobe acrobat (for sizing) and then edited in illustrator to add the image.
Via the processor
The file is the imported using PdfStreamWriter and result written to a memory stream
The memorystream is the imported using RadFixedDocument and then text is added at 100x100 position.
Result is written to a file
Resulting file (https://www.pastefile.com/4HZwvR)
The text does not appear at 100x100 but at at ~ 74x70ish
the text font is not Helvetica but Arial
the font size is not 10pt but 5.63 pt
Code below (result is test4.pdf)
Imports
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf
Imports
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Streaming
Imports
Telerik.Windows.Documents.Fixed.Model
Public
Class
Form1
Public
pageLetter
As
New
System.Windows.Size(816, 1056)
Private
Sub
Button2_Click(sender
As
Object
, e
As
EventArgs)
Handles
Button2.Click
'Load file into byte array
Dim
page1
As
Byte
() = ReadFile(
"d:\test2.pdf"
)
Dim
originalsize
As
String
=
""
' Load source document
Dim
sourceDocument
As
New
IO.MemoryStream(page1)
Dim
sourceDocumentPDF
As
New
PdfFileSource(sourceDocument)
Dim
resultIO
As
New
IO.MemoryStream
Using fileWriter
As
PdfStreamWriter =
New
PdfStreamWriter(resultIO)
' Create file same size as source
Using targetPDF
As
PdfPageStreamWriter = fileWriter.BeginPage(pageLetter)
' Store original size to write it out later
originalsize = sourceDocumentPDF.Pages(0).Size.Width &
"x"
& sourceDocumentPDF.Pages(0).Size.Height
' Write file
targetPDF.ContentPosition.Clear()
targetPDF.ContentPosition.Translate(0, 0)
targetPDF.ContentPosition.Scale(1, 1)
targetPDF.WriteContent(sourceDocumentPDF.Pages(0))
End
Using
End
Using
Dim
provider
As
New
PdfFormatProvider()
Dim
doc1
As
RadFixedDocument = provider.Import(resultIO.ToArray)
Dim
pg
As
RadFixedPage = doc1.Pages(0)
Dim
t
As
Telerik.Windows.Documents.Fixed.Model.Text.TextFragment =
New
Telerik.Windows.Documents.Fixed.Model.Text.TextFragment()
t.Font = Fonts.FontsRepository.Helvetica
t.FontSize = Telerik.Windows.Documents.Media.Unit.DipToPoint(10)
t.Text =
"TEST TEXT PDF SIZE"
& originalsize
pg.Content.Add(t)
t.Position.Translate(100, 100)
Dim
b()
As
Byte
= provider.Export(doc1)
Dim
io2
As
New
IO.FileInfo(
"d:\test4.pdf"
)
Dim
sw
As
IO.FileStream = io2.OpenWrite()
sw.Write(b, 0, b.Length)
sw.Close()
End
Sub
Shared
Function
ReadFile(filename
As
String
)
As
Byte
()
Dim
io
As
New
IO.FileInfo(filename)
Dim
fs
As
IO.FileStream = io.OpenRead
Dim
b()
As
Byte
ReDim
b(io.Length)
fs.Read(b, 0, io.Length)
fs.Close()
Return
b
End
Function
End
Class
Hi,
We have a threaded service where we export excel documents to PDF documents (using Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider.Export) and then merge the PDF with other PDF documents (using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.Import and RadFixedDocument.Merge). We make sure to dispose the Workbook of the excel document and the MemoryStream from exporting to PDF.
After some time we start getting the following error, until we restart the service.
One or more errors occurred.
at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Telerik.Windows.Documents.Utilities.TasksHelper.DoAsync(Action[] actions)
at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.CalculateCellContentSizes(List`1 cellsToCalculateContentSize, CellProperties[] cellsFontProperties)
at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.UpdateCellContentSizesCache()
at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.Measure()
at Telerik.Windows.Documents.Spreadsheet.Model.Workbook.UpdateWorksheetLayout(RadWorksheetLayout worksheetLayout, Worksheet worksheet, Boolean isForPrinting)
at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.GetTopLeftPoint()
at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.GetTopLeftCellIndex()
at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.RecalculateUsedCellRange()
at Telerik.Windows.Documents.Spreadsheet.Model.Worksheet.get_TotalUsedCellRange()
at Telerik.Windows.Documents.Spreadsheet.Layout.PageLayout.AddPages(Worksheet worksheet, Boolean ignorePrintArea)
at Telerik.Windows.Documents.Spreadsheet.Layout.PageLayout.PreparePages(Workbook workbook, Boolean ignorePrintArea)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(Workbook workbook, Stream output)
...
...
Inner exception: The operation completed successfully
at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Threading.Dispatcher..ctor()
at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
at System.Windows.Media.TextFormatting.TextFormatter.FromCurrentDispatcher(TextFormattingMode textFormattingMode)
at System.Windows.Media.FormattedText.LineEnumerator..ctor(FormattedText text)
at System.Windows.Media.FormattedText.DrawAndCalculateMetrics(DrawingContext dc, Point drawingOffset, Boolean getBlackBoxMetrics)
at System.Windows.Media.FormattedText.get_Metrics()
at Telerik.Windows.Documents.Core.TextMeasurer.RadTextMeasurer.MeasureTextWithWrapping(TextProperties textProperties, FontProperties fontProperties, Double wrappingWidth)
at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.Measure(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.MeasureMultiline(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.DefaultTextMeasuringMethod(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.CalculateCellContentSize(ICellValue cellValue, CellValueFormat format, FontProperties fontProperties, Double cellIndent, Nullable`1 wrappingWidth, Func`4 measureMultilineText)
at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.<>c__DisplayClass4.<
CalculateCellContentSizes
>b__1()
at System.Threading.Tasks.Task.Execute()
Any help on why this happens and how we can fix it would be appreciated.
I am trying to export my document but I am getting the error attached to the thread.
I can fix this by going into the properties of the document and checking the unblock box. Is there a way to do this in the export to be able to just open the document without having to go into its properties? I get the same error on the demo page for generating word documents https://demos.telerik.com/aspnet-ajax/wordsprocessing/generate-documents/defaultcs.aspx
Here is my code for export
RadFlowDocument document = report.GenerateDoc();
DocxFormatProvider provider = new DocxFormatProvider();
MemoryStream ms = new MemoryStream();
provider.Export(document, ms);
byte[] byteArray = ms.ToArray();
ms.Dispose();
return File(byteArray, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "AAR.docx");