Telerik Forums
Telerik Document Processing Forum
1 answer
660 views

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.

 

Georgi
Telerik team
 answered on 20 Nov 2019
21 answers
2.0K+ views
Hello

I would like to create PDF file, as container for images, (the source of the images is scanner).
I order to make small file size, I'm converting the images from BMP to JPEG and then do the export to PDF file,
but the output file size is huge.
I'm following this example.


1. How can i control the PDF file size?
2. Is the PDF export saves JPEG  image as is or decode and then save it?


My Code:

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.}
Nikolay Demirev
Telerik team
 answered on 18 Nov 2019
3 answers
868 views
I need to know how to email a digitally signed PDF document from a user input webform.
Tanya
Telerik team
 answered on 25 Oct 2019
1 answer
404 views

I want to set table line style like this attachment. How Can I set this table line style?




Martin
Telerik team
 answered on 17 Oct 2019
1 answer
755 views

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);
            }
}

 

 

Georgi
Telerik team
 answered on 14 Oct 2019
1 answer
168 views
How to implement the Document Properties like Author, Company,Title etc of the RadSpreadSheet Excel workbook using the Kendo RadSpreadSheet?
Veselin Tsvetanov
Telerik team
 answered on 02 Oct 2019
1 answer
163 views

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?

Tanya
Telerik team
 answered on 27 Sep 2019
3 answers
150 views
With the new release of 2019.3, I was trying to add PdfProcessing to my .net core 3 web application. Following the example found in the Telerik UI for ASP.NET Core R3 2019 folder I added the correct references (Telerik.Windows.Documents.Fixed,Telerik.Windows.Documents.Core and so on). On my application it did compile however when using it I got an unhandled exception when I tried to create a new PdfFormatProvider. I don't have the exact wording on me right now but it was a TypeLoadException when trying to load/use Size or Point from WindowsBase. Now given that this is a web application it obviously has no reference to WindowsBase and as such it doesn't work
Tanya
Telerik team
 answered on 27 Sep 2019
13 answers
2.1K+ views

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);

 

 

Naveen
Top achievements
Rank 1
 answered on 09 Sep 2019
5 answers
333 views

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
Tanya
Telerik team
 answered on 02 Sep 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?