Telerik Forums
Telerik Document Processing Forum
2 answers
49 views

We need to set a spreadsheet font to Courier New in a WPF app using telerik.ui.for.wpf.60.xaml\2024.2.514.  As a first step, we do:

using System.Windows;
using Telerik.Documents.Common.Model;

namespace WpfApp4;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        var fontFamily = new ThemableFontFamily("Courier New");
    }
}

Which is fine until we add a required cross-platform project referencing telerik.documents.core\2024.2.426

Then we get:

The type 'ThemableFontFamily' exists in both 'Telerik.Documents.Core, Version=2024.2.426.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7' and 'Telerik.Windows.Documents.Core, Version=2024.2.426.60, Culture=neutral, PublicKeyToken=5803cfa389c90ce7'

Ambiguous reference.
Candidates are:
Telerik.Documents.Common.Model.ThemableColor
Telerik.Documents.Common.Model.ThemableColor

What is the proper fix for this to reference the version in the WPF app project?

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 10 Apr 2025
1 answer
27 views
Is it possible to add text to headers based on variables/database fields? I'm trying to loop through a table and use a field within the table as a page title, but all information I could find on this points to it being impossible in Telerik. Guidance would be much appreciated. 

Thanks
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 07 Apr 2025
1 answer
29 views

I am doing some document processing and want to use Telerik to display and edit. I need access to the paraId and textId elements of the docx "document" XML. I have explored the object model in the debugger and do not see these attributes. Are they available in the imported model?

Thanks.

 

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 26 Mar 2025
1 answer
62 views
Im using:
var xlsxProvider = new XlsxFormatProvider();
var pdfFormatProvider = new PdfFormatProvider();

byte[] docBytes = File.ReadAllBytes(path);
Workbook workbook = xlsxProvider.Import(docBytes, null);

byte[] resultBytes = pdfFormatProvider.Export(workbook, null);
File.WriteAllBytes(resultPath, resultBytes);

to conver xlsx file to pdf. In source xlsx file a have a Table and a formula '=SUBTOTAL(109, Table2[...]) that work in xlsx, but when i export it to PDF i need to have the calculated value, but instead im getting the string  '=SUBTOTAL(109, Table2[...]) . 

Is there a simple way to force calculation of all formulas in the sheet before exporting it to PDF?
Yoan
Telerik team
 answered on 28 Feb 2025
1 answer
54 views

The contents of an uploaded .docx file is being cut-off when converted to .pdf file.

 

Code snippet:

var fileFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider(); using (MemoryStream inputFileStream = new MemoryStream()) { this.fileSystemService.GetFile(documentInfo, inputFileStream); if (fileFormatProvider != null) { var document = fileFormatProvider.Import(inputFileStream); using (MemoryStream output = new MemoryStream()) { var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider(); pdfProvider.Export(document, output); var newFile = new DocumentInfo() { NameWithPath = outputFileName, DocumentLocation = documentInfo.DocumentLocation }; this.fileSystemService.SaveFile(newFile, output); } }

 

Can someone confirm if this a Telerik side issue, or am I missing a setting or config?

 

Thanks!

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 26 Feb 2025
0 answers
42 views

Can someone help me figure out what is wrong here?  I'm getting ad horribly vague Null exception.

 

var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
RadFlowDocument document = new RadFlowDocument();
byte[] docBytes = File.ReadAllBytes(path);

document = docxProvider.Import(docBytes);    ERROR HERE

var resultBytes = pdfProvider.Export(document);

File.WriteAllBytes(resultPath, resultBytes);

 

The document i'm trying to load contains tables and images within the tables (jpeg barcodes)

I have verified that pretty much every other tool i use can read the file without issue. 

The goal is ultimately to export the file as a PDF.

 

Error details:

{"Object reference not set to an instance of an object."}

   at Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document.ParagraphPropertiesElement.OnAfterRead(IDocxImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase`3.OnAfterRead(IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(Stream stream, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.ImportPartFromArchive(ZipArchiveEntry zipEntry, PartBase part, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider.ImportOverride(Stream input)
   at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Import(Stream input)
   at Telerik.Windows.Documents.Common.FormatProviders.BinaryFormatProviderBase`1.Import(Byte[] input)
   at IVC_BIPS_Desktop.rfrmMain.ConverDocxToPdf(String path, String resultPath) in C:\Source\IVC Batch Instructions Printing\IVC_BIPS_Desktop\rfrmMain.cs:line 499
Jamie
Top achievements
Rank 1
 asked on 20 Feb 2025
1 answer
34 views

I am trying to convert HTML to a PDF document with 0.25" margins. The left and right margins are being set correctly, but the top and bottom margins remain 0.5".  My code is below, a screenshot of the generated PDF is attached.

                StringBuilder sb = new StringBuilder();

                foreach (string row in data)
                    sb.AppendLine(row);

                HtmlFormatProvider provider = new HtmlFormatProvider();
                RadFlowDocument html = provider.Import(sb.ToString());

                foreach (Section section in html.Sections)
                {
                    section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(24, 24, 24, 24); 

                    // Code snippet from function that adds header inserted below

                    Header header = section.Headers.Add();
                    Table table = header.Blocks.AddTable();
                    Border border = new Border(1, BorderStyle.Single, new ThemableColor(Colors.Black));
                    table.Borders = new TableBorders(border);
            
                    TableRow row1 = table.Rows.AddTableRow();
                    row1.Height = new TableRowHeight(HeightType.Exact, 30);
            
                    TableCell Title = row1.Cells.AddTableCell();
                    Paragraph pTitle = Title.Blocks.AddParagraph();
                    Run rTitle = pTitle.Inlines.AddRun(FormName);
                    Title.PreferredWidth = Inches(3.99);
                    Title.Shading.BackgroundColor = gray;
                    Title.VerticalAlignment = VerticalAlignment.Center;
                    rTitle.FontWeight = FontWeights.Bold;
                    rTitle.FontSize = 16;

                    // Call to similar code for adding footer

                }

                PdfFormatProvider pdf = new PdfFormatProvider();
                return pdf.Export(html);

 

Thanks in advance for the help.

Darwin Pinder

Yoan
Telerik team
 answered on 28 Jan 2025
1 answer
49 views

Hi,

we have editable PDFs which are stored in a database. We used to be able to pull the PDFs, import them through the Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider to get a RadFixedDocument, iterate through the fields of this document and fill them with data. Afterwards, we exported the PDF through the PdfFormatProvider and wrote them to a file. This gave us the original PDF but filled with the required data.

This does not work anymore, as the resulting exported PDF is visually broken. We have no clue why that happens, maybe you can help us fix this.

I attached a small sample project with our work flow including one of the PDFs we try to fill out and the resulting PDF for you to analyze.

Thanks a lot in advance.

Yoan
Telerik team
 answered on 24 Jan 2025
0 answers
68 views
Hi,

i have added and image and some text inside the digital signature and and set them inside properly but when i set the position of the signature field before the signature field like i was showing in below screenshot 


above screenshot i have added the signature field placed the top of the Letter M but when i validate the signature manually but in output the signature field position is not correct as i set the above screenshot below is the screenshot that you can check the position of the signature field

i don't know whats strange can anyone help me this to get it out  
0 answers
214 views
i am getting the Telerik.Windows.Documents.Fixed.Exceptions.NotSupportedImageFormatException: 'Not supported image format.'  this exception in below code can anyone have a solution for that 


// Load the existing PDF from the byte array using PdfFormatProvider
using (MemoryStream inputStream = new MemoryStream(inDocByte))
{
    // Create PdfFormatProvider and load the existing document
    PdfFormatProvider provider = new PdfFormatProvider();
    RadFixedDocument document = provider.Import(inputStream);

    int pageNo = (signInfo.DigitalSignPage() == 0 ? 1 : document.Pages.Count);

    // Path to the image (ensure this is correct)
    System.Drawing.Image signatureImage = null;
    if (signInfo.DigitalSignMode() == 2 && HttpContext.Current.Session["imagesyncfusion"] != null)
    {
        signatureImage = (System.Drawing.Image)HttpContext.Current.Session["imagesyncfusion"];
    }
    // Check if digital signature is needed
    if (signInfo.UseDigitalSign())
    {
        if ((signInfo.DigitalSignMode() == 1) || (signInfo.DigitalSignMode() == 2))
        {
            double signaturePositionLeft = (double)signInfo.DigitalSignLeftInPoints();
            double signaturePositionTop = (double)signInfo.DigitalSignTopInPoints();
            double signatureFieldWidth = (double)signInfo.DigitalSignWidthInPoints();
            double signatureFieldHeight = (double)signInfo.DigitalSignHeightInPoints();
            RadFixedPage radFixedPage = document.Pages[pageNo - 1];

            if (!string.IsNullOrEmpty(customSignatureDetails))
            {
                // Movable signature case: Adjust the signature field based on custom details
                signatureFieldWidth = signaturePositionLeft + (double)signInfo.DigitalSignWidthInPoints();
                signatureFieldHeight = signaturePositionTop + (double)signInfo.DigitalSignHeightInPoints();

                string[] separator = new string[] { "!_!" };
                string[] offsetArray = customSignatureDetails.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                if (offsetArray.Length >= 9)
                {
                    float offsetLeft = returnFloatWithCultureValue(offsetArray[0]);
                    float offsetTop = returnFloatWithCultureValue(offsetArray[1]);
                    float docHeight = returnFloatWithCultureValue(offsetArray[2]);
                    float greenDivHeight = returnFloatWithCultureValue(offsetArray[3]);
                    float greenDivWidth = returnFloatWithCultureValue(offsetArray[4]);
                    float dpi_x = returnFloatWithCultureValue(offsetArray[6]);
                    float dpi_y = returnFloatWithCultureValue(offsetArray[7]);
                    pageNo = int.Parse(offsetArray[8]);

                    // Calculate positions for drawing the text div;
                    signaturePositionLeft = (offsetLeft / dpi_x) * 72;
                    signaturePositionTop = (offsetTop / dpi_y) * 72;
                    signatureFieldWidth = (greenDivWidth / dpi_y) * 72;
                    signatureFieldHeight = (greenDivHeight / dpi_x) * 72;
                }
            }
            else
            {
                // Non-movable case: Place the signature field in a fixed location
                radFixedPage = document.Pages[pageNo - 1];
                Tuple<double, double> k = null;

                if (signatureImage != null)
                {
                    k = calculateAspectRatioFit(signatureImage.Width, signatureImage.Height, signatureFieldWidth, signatureFieldHeight);
                    signatureFieldWidth = k.Item1;
                    signatureFieldHeight = k.Item2;
                }

                signaturePositionLeft = radFixedPage.Size.Height - (double)(signatureFieldWidth + signatureFieldHeight + 1);
                signaturePositionTop = signaturePositionTop + 1; // +1 For border size
                                                                 //pdfForm.FormSource.Size = new Telerik.Documents.Primitives.Size(signatureFieldWidth, signatureFieldHeight);
            }

            // Create a new form to place the signature field
            Form pdfForm = new Form();
            pdfForm.FormSource = new FormSource();
            FixedContentEditor editor = new FixedContentEditor(pdfForm.FormSource);
            pdfForm.FormSource.Size = new Telerik.Documents.Primitives.Size(signatureFieldWidth, signatureFieldHeight);

            // Drawing the image at the starting position (left side of the signature field)
            imageWidth = signatureFieldWidth / 2;  // Half the width for the image
            double imageHeight = signatureFieldHeight;  // Use full height of the signature field

            if (signatureImage != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    signatureImage.Save(ms, signatureImage.RawFormat);
                    ms.Position = 0;
                    editor.DrawImage(ms, new Telerik.Documents.Primitives.Size(imageWidth, imageHeight));
                }
            }

            // Prepare text to draw beside the signature image
            string textToDraw = $"Digitally signed by {certificate.FriendlyName} \nDate: {DateTime.Now:yyyy.MM.dd HH:mm:ss zzz} \nReason: {pdfSignature.Signature.Properties.Reason} \nLocation: {pdfSignature.Signature.Properties.Location}";

            // Set text width and calculate font size
            double textWidth = signatureFieldWidth - imageWidth;
            double fontSize = CalculateFontSize(signatureFieldWidth - 23, signatureFieldHeight, textToDraw);

            // Define the position for the text and draw it
            Telerik.Windows.Documents.Fixed.Model.Editing.Block textBlock = new Telerik.Windows.Documents.Fixed.Model.Editing.Block();
            double textPositionLeft = signaturePositionLeft;  // Adding a 5px gap after the image
            textBlock.TextProperties.FontSize = fontSize;
            textBlock.InsertText($"Digitally signed by {certificate.FriendlyName}");
            textBlock.InsertText($" Date: {DateTime.Now:yyyy.MM.dd HH:mm:ss zzz}");
            textBlock.InsertText($" Reason: {pdfSignature.Signature.Properties.Reason}");
            textBlock.InsertText($" Location: {pdfSignature.Signature.Properties.Location}");
            
            Rect boundingRect;
            if (signatureImage != null)
            {
                boundingRect = new Rect(imageWidth, 5, textWidth, signatureFieldHeight);
            }
            else
            {
                boundingRect = new Rect(textPositionLeft, 5, textWidth, signatureFieldHeight);
            }
            textBlock.Draw(editor, boundingRect);
            //editor.DrawBlock(textBlock);
            // Create the SignatureWidget and position it on the PDF page
            SignatureWidget signatureWidget = pdfSignature.Widgets.AddWidget();
            signatureWidget.Content.NormalContentSource = pdfForm.FormSource;
            signatureWidget.Rect = new Rect(signaturePositionLeft, 0, signatureFieldWidth, signatureFieldHeight);
            signatureWidget.RecalculateContent();

            // Add signature widget to the page and draw the content
            RadFixedPage pdfPage = document.Pages[pageNo - 1];
            FixedContentEditor pageEditor = new FixedContentEditor(pdfPage);
            pageEditor.Position.Translate(signaturePositionLeft , signaturePositionTop + 258.3824795800782);
            pageEditor.DrawForm(pdfForm.FormSource);

            // Add the signature field to the document's AcroForm
            document.AcroForm.FormFields.Add(pdfSignature);

        }

    }
    // Export the document to a byte array and return
    using (MemoryStream memoryStream = new MemoryStream())
    {

        Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver();
        Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver;
        PdfExportSettings settings = new PdfExportSettings() { ImageQuality = ImageQuality.High };
        //PdfFormatProvider provider = new PdfFormatProvider();
        provider.ExportSettings = settings;
        provider.Export(document, memoryStream);
        outDocPdf = memoryStream.ToArray();
    }
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?