RadPdfProcessing currently supports interactive forms whose data is defined directly in the document. To preserve them when importing and exporting documents, add support for import-export interactive forms based on the Adobe XML Forms Architecture (XFA).
From PDF 2.0 the XFA forms are depreciated.
When exporting the pdf pages as images with the Skia engine, some parts of the document got missing.
Note: In the previous Version 2024.3.806 these parts appeared.
This exception was originally thrown at this call stack:
System.ThrowHelper.ThrowKeyNotFoundException()
System.Collections.Generic.Dictionary<TKey, TValue>.this[TKey].get(TKey)
Telerik.Windows.Documents.Core.PostScript.Data.PostScriptDictionary.GetElementAs<T>(string) in PostScriptDictionary.cs
Telerik.Windows.Documents.Core.Fonts.Type1.Type1Format.Dictionaries.Type1Font.ReadGlyphData(string) in Type1Font.cs
Telerik.Windows.Documents.Core.Fonts.Type1.Type1Format.Dictionaries.Type1Font.GetGlyphDataInternal(string) in Type1Font.cs
When a PDF document is being imported, some of the characters may experience unexpected results while reading the font.
NOTE: the document is displayed in the MAUI/WPF/WinForms PdfViewer controls with missing parts of the text.
This is the code snippet for reproducing the error message:
static void Main(string[] args)
{
string filePath = "Lorem ipsum dolor sit amet.pdf";
//load a random document
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument originalDocument;
using (Stream stream = File.OpenRead(filePath))
{
originalDocument = provider.Import(stream);
}
//draw something on the first page
FixedContentEditor editor = new FixedContentEditor(originalDocument.Pages[0]);
editor.GraphicProperties.IsFilled = true;
editor.GraphicProperties.FillColor = RgbColors.Black;
Telerik.Documents.Primitives.Rect Rect = new Telerik.Documents.Primitives.Rect(10, 10, 200, 100);
editor.DrawRectangle(Rect);
//export the pages as images and build a brand new document from the images
SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
imageProvider.ExportSettings.ImageFormat = SkiaImageFormat.Jpeg;
imageProvider.ExportSettings.ScaleFactor = 0.8;
imageProvider.ExportSettings.Quality = 80;
RadFixedDocument doc = new RadFixedDocument();
foreach (RadFixedPage page in originalDocument.Pages)
{
byte[] resultImage = imageProvider.Export(page);
RadFixedPage pdfpage = doc.Pages.AddPage();
editor = new FixedContentEditor(pdfpage);
Stream imageStream = new MemoryStream(resultImage);
editor.DrawImage(imageStream);
}
//export the pdf built from the images
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
string outputPdf = @"output.pdf";
File.Delete(outputPdf);
using (Stream output = File.OpenWrite(outputPdf))
{
pdfFormatProvider.Export(doc, output);
}
Process.Start(new ProcessStartInfo() { FileName = outputPdf, UseShellExecute = true });
}
Workaround:
static void Main(string[] args)
{
string filePath = "Lorem ipsum dolor sit amet.pdf";
//load a random document
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument originalDocument;
using (Stream stream = File.OpenRead(filePath))
{
originalDocument = provider.Import(stream);
}
//draw something on the first page
FixedContentEditor editor = new FixedContentEditor(originalDocument.Pages[0]);
editor.GraphicProperties.IsFilled = true;
editor.GraphicProperties.FillColor = RgbColors.Black;
Telerik.Documents.Primitives.Rect Rect = new Telerik.Documents.Primitives.Rect(10, 10, 200, 100);
editor.DrawRectangle(Rect);
using (Stream output = File.OpenWrite(filePath))
{
provider.Export(originalDocument, output);
}
using (Stream stream = File.OpenRead(filePath))
{
originalDocument = provider.Import(stream);
}
//export the pages as images and build a brand new document from the images
SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
imageProvider.ExportSettings.ImageFormat = SkiaImageFormat.Jpeg;
imageProvider.ExportSettings.ScaleFactor = 0.8;
imageProvider.ExportSettings.Quality = 80;
RadFixedDocument doc = new RadFixedDocument();
foreach (RadFixedPage page in originalDocument.Pages)
{
byte[] resultImage = imageProvider.Export(page);
RadFixedPage pdfpage = doc.Pages.AddPage();
editor = new FixedContentEditor(pdfpage);
Stream imageStream = new MemoryStream(resultImage);
editor.DrawImage(imageStream);
}
//export the pdf built from the images
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
string outputPdf = @"output.pdf";
File.Delete(outputPdf);
using (Stream output = File.OpenWrite(outputPdf))
{
pdfFormatProvider.Export(doc, output);
}
Process.Start(new ProcessStartInfo() { FileName = outputPdf, UseShellExecute = true });
}
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);
RadPdfProcessing currently supports interactive forms whose data is defined directly in the document. Add support for interactive forms based on the Adobe XML Forms Architecture (XFA). The entry is defined inside the interactive forms dictionary and refers to an XML stream containing the information of the form. More information is available on page 722 from Pdf Reference, version 1.7.
Updates:
Add support for actions with invalid Subtype casing.
Example: The action Subtype being "Javascript" instead of the expected "JavaScript".
An ArgumentNullException is thrown when importing a document with a missing required MediaBox operator in the Page object ("ArgumentNullException: 'Value cannot be null.")