I have a Template pdf (With company logo as letter head). I want to use this pdf as the first page when I'm creating my pdf.
Here's my sample code. It creates the letter head in the first page and the rest of the content in a new page.
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(File.ReadAllBytes(InputFileName));
using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document))
{
editor.ParagraphProperties.SpacingBefore = 10;
editor.ParagraphProperties.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
editor.InsertParagraph();
editor.CharacterProperties.FontSize = 40;
editor.CharacterProperties.Font = boldItalicFont;
editor.InsertRun("Summary of Proxy Votes");
I'm having this issue with some digital signed pdfs.
Here is the code that gets the exception:
var signatureFields = document.AcroForm.FormFields.Where(field => field.FieldType == FormFieldType.Signature).ToList();
if (signatureFields.IsNotNullOrEmpty())
{
foreach (var signatureField in signatureFields)
{
var field = (SignatureField)signatureField;
if (field != null && field.Signature != null)
{
var test = field.Signature.Validate(); - this is the line where I get the exceptions!
The method Validate() called without the properties parameter throws exception in 2 cases:
1st - using pdf signed with specialized software
Message: "No signature validation handler was found for the subfilter: ETSI.CAdES.detached
and the StackTrace: at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature.Validate(SignatureValidationProperties validationProperties)\r\n at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature.Validate()\r\n at... (there goes the path in my project)
2nd - using pdf signed with the same digital signature by Adobe Acrobat Reader
Message "ASN1 bad tag value met.\r\n"
and the StackTrace: at System.Security.Cryptography.Pkcs.SignedCms.OpenToDecode(Byte[] encodedMessage, ContentInfo contentInfo, Boolean detached)\r\n at System.Security.Cryptography.Pkcs.SignedCms.Decode(Byte[] encodedMessage)\r\n at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Pkcs7Detached.ValidateOverride(SignatureDataProperties dataProperties, SignatureValidationProperties validationProperties)\r\n at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.SignatureValidationHandlerBase.Validate(SignatureDataProperties dataProperties, SignatureValidationProperties validationProperties)\r\n at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature.Validate(SignatureValidationProperties validationProperties)\r\n at Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature.Validate()\r\n at... (there goes the path in my project)
I'll be glad if you can tell me where the problem is and what can I do to fix it.
I want to be clear, there are just some correctly signed pdfs that cannot pass this validation. Most of them can but I'm afraid that I am missing something, as one of the non-passing digital signatures is new.
01.
void
f(List<Bitmap> Images)
02.
{
03.
DateTime now = DateTime.Now;
04.
string
name =
"scan-"
+ now.ToString(
"yyyyMMdd"
) +
"-"
+ now.ToString(
"HHmmss"
) +
"_3"
+
".pdf"
;
05.
06.
using
(FileStream FileStream =
new
FileStream(@
"c:\Users\avicode\Desktop\tmp\"
+ name,FileMode.Create))
07.
using
(MemoryStream ms =
new
MemoryStream())
08.
09.
if
(Images.Count >= 1)
10.
{
11.
RadDocument document =
new
RadDocument();
12.
for
(
int
i = 0; i < Images.Count; i++)
13.
{
14.
System.Drawing.Image oBmpImage = (System.Drawing.Image)Images[Images.Count - 1];
15.
oBmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
16.
Telerik.Windows.Documents.Model.Section section =
new
Telerik.Windows.Documents.Model.Section();
17.
Telerik.Windows.Documents.Model.Paragraph paragraph =
new
Telerik.Windows.Documents.Model.Paragraph();
18.
19.
ImageInline image =
new
ImageInline(ms);
20.
paragraph.Inlines.Add(image);
21.
section.Blocks.Add(paragraph);
22.
document.Sections.Add(section);
23.
24.
}
25.
PdfFormatProvider oPdf =
new
PdfFormatProvider();
26.
oPdf.Export(document,FileStream);
27.
}
28.
}
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);