InvalidCastException is thrown when a name start character is followed by a literal string start character.
System.InvalidCastException: Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfName'.
When inserting ligature languages text into a block, the text doesn't appear on the generated PDF file.
With the following sample code, the issue can be reproduced:
private static string fileName = "Hello.pdf";
static void Main(string[] args)
{
byte[] fontData = File.ReadAllBytes("calibri.ttf");
FontFamily fontFamily = new FontFamily("Calibri");
FontsRepository.RegisterFont(fontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = new RadFixedPage();
string text = "مرحبا";
var reversedText = text.ToCharArray();
Array.Reverse(reversedText);
Block block = new Block();
block.InsertText(new FontFamily("Calibri"), new string(reversedText));
FixedContentEditor editor = new FixedContentEditor(page);
editor.DrawBlock(block);
document.Pages.Add(page);
PdfFormatProvider provider = new PdfFormatProvider();
using (Stream output = File.OpenWrite(fileName))
{
provider.Export(document, output);
}
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = fileName;
Process.Start(fileName);
}
Some documents loaded through WordsProcessing and then exported to a RadFixedDocument by utilizing the ExportToFixedDocument() method, fails on export through ImageFormatProvider with System.AggregateException.
As a workaround, you can export the RadFixedDocument to a PDF and then import it again before exporting it to an image.
var pdfFixedProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
bytes = pdfFixedProvider.Export(fixedDocument);
fixedDocument = pdfFixedProvider.Import(bytes);
When loading a PDF generated with PdfProcessing in PDF Accessibility Checker 2021 (PAC) an exception is thrown: "Object reference not set to an instance of an object".
It is reproducible with all PdfComplianceLevel export options.