This is the code for reproducing the incorrect PDF document. If the step with changing the font is commented, the document is exported properly:
//Step 1: Create an instance of XlsxFormatProvider to import the Excel file
XlsxFormatProvider xlsxFormatProvider = new XlsxFormatProvider();
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider pdfFormatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
Workbook workbook;
using (FileStream input = new FileStream("Input.xlsx", FileMode.Open))
{
workbook = xlsxFormatProvider.Import(input, TimeSpan.FromSeconds(10));
}
//Step 2: Export the workbook to PDF RadFixedDocument to modify fonts
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider spread_pdf_provider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
RadFixedDocument fixedDocument = spread_pdf_provider.ExportToFixedDocument(workbook, TimeSpan.FromSeconds(10));
foreach (var page in fixedDocument.Pages)
{
foreach (var content in page.Content)
{
if (content is TextFragment text)
{
// Replace the font with Helvetica or HelveticaBold based on the original font style
text.Font = text.Font.Name.ToLower().Contains("bold")
? FontsRepository.HelveticaBold
: FontsRepository.Helvetica;
}
}
}
//Step 3: Save the modified RadFixedDocument back to PDF
string outputFileName = "ExportedWorkbook.pdf";
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider fixed_pdf_provider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
using (FileStream output = new FileStream(outputFileName, FileMode.Create))
{
fixed_pdf_provider.ExportSettings.DocumentUnhandledException += ExportSettings_DocumentUnhandledException;
fixed_pdf_provider.ExportSettings.FontEmbeddingType = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.FontEmbeddingType.Subset;
fixed_pdf_provider.Export(fixedDocument, output, TimeSpan.FromSeconds(10));
}
Process.Start(new ProcessStartInfo() { FileName = outputFileName, UseShellExecute = true });
When importing a large document (e.g. 2.3GB) , the library fails to parse int value that exceeds the limit which leads to endless importing:
LocalizableException is thrown after removing columns from a workbook with set Print Titles.
Workaround - Remove the PrintTitles before removing the columns:
WorksheetPageSetup pageSetup = workbook.ActiveWorksheet.WorksheetPageSetup;
pageSetup.PrintTitles.RepeatedRows = null;
pageSetup.PrintTitles.RepeatedColumns = null;
HtmlFormatProvider: Styles are not correctly preserved when a <b> tag is applied to the same styled element.
Workaround: Apply bold through CSS instead of using <b>.
During export operation of a document that contains signature fields the following error occurs:
System.InvalidOperationException: 'The signature was not properly initialized for external signing. The signing delegate is missing.'Setting the ComplianceLevel to PdfA3B and the TaggingStrategy to UseExisting when exporting a PDF document leads to the following Error reported by VeraPdf:
Specification: ISO 19005-3:2012, Clause: 6.2.11.5, Test number: 1 For every font embedded in a conforming file and used for rendering, the glyph width information in the font dictionary and in the embedded font program shall be consistent. Glyph width 274.4140625 in the embedded font program is not consistent with the Widths entry of the font dictionary (value 272)
Resaving a document with Acrobat throws an error due to invalid Info dictionary in document trailer.
You need to explicitly set the correct MIME type when embedding the file into the PDF. This is especially important for standards like PDF/A-3 and Factur-X, which require strict metadata and MIME type declarations for embedded files.
The default value /application/octet-stream is too generic and not compliant for XML attachments.
List's top and bottom margins are not correctly exported.
Workaround: Apply TelerikNormal style to the 'ol' element.
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Streaming;
using Telerik.Windows.Documents.Fixed.Model.Editing;
using Telerik.Windows.Documents.Fixed.Model.InteractiveForms;
using Telerik.Windows.Documents.Fixed.Model;
using Telerik.Documents.Primitives;
using System.Diagnostics;
using System.Reflection.Metadata;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
namespace _1681158PdfInputFields
{
internal class Program
{
static void Main(string[] args)
{
ExportExamplePdfForm();
}
public static void ExportExamplePdfForm()
{
RadFixedDocument fixedDoc = new RadFixedDocument();
RadFixedPage fixedPage = fixedDoc.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(fixedPage);
editor.Position.Translate(100, 100);
TextBoxField textBox = new TextBoxField("textBox");
fixedDoc.AcroForm.FormFields.Add(textBox);
textBox.Value = "Sample text...";
Size widgetDimensions = new Size(200, 30);
DrawNextWidgetWithDescription(editor, "TextBox", (e) => e.DrawWidget(textBox, widgetDimensions));
string fileName = "output.pdf";
File.Delete(fileName);
// File.WriteAllBytes(fileName, new PdfFormatProvider().Export(fixedDoc, TimeSpan.FromSeconds(15)));
string ResultFileName = "result.pdf";
File.Delete(ResultFileName);
using (PdfStreamWriter writer = new PdfStreamWriter(File.OpenWrite(ResultFileName)))
{
foreach (RadFixedPage page in fixedDoc.Pages)
{
writer.WritePage(page);
}
}
ProcessStartInfo psi = new ProcessStartInfo()
{
FileName = ResultFileName,
UseShellExecute = true
};
Process.Start(psi);
Console.WriteLine("Document created.");
}
private static void DrawNextWidgetWithDescription(FixedContentEditor editor, string description, Action<FixedContentEditor> drawWidgetWithEditor)
{
double padding = 20;
drawWidgetWithEditor(editor);
Size annotationSize = editor.Root.Annotations[editor.Root.Annotations.Count - 1].Rect.Size;
double x = editor.Position.Matrix.OffsetX;
double y = editor.Position.Matrix.OffsetY;
Block block = new Block();
block.TextProperties.FontSize = 20;
block.VerticalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.VerticalAlignment.Center;
block.InsertText(description);
editor.Position.Translate(x + annotationSize.Width + padding, y);
editor.DrawBlock(block, new Size(editor.Root.Size.Width, annotationSize.Height));
editor.Position.Translate(x, y + annotationSize.Height + padding);
}
}
}
When exporting a DOCX file to PDF format, the following error message occurs: