16 0 obj <</AP<</N<</Off null/On 188 0 R>>/D<</Off 189 0 R/On 190 0 R>>>>/AS/Off/F 4/FT/Btn/H/T/P 19 0 R/Rect[ 40.3 690.45 56.15 706.7999]/Subtype/Widget/T(Einraeumung:Grabnutzungsrechts)/Type/Annot>> endobj
Hi Telerik,
Could you add abbility to contact TSA (timestamp) server and sign PDF document with certificate (which is currently supported) and signed timestamp?
Thank you
PdfProcessing: Handle merge of documents containing fields with the same invalid name.
System.OutOfMemoryException: Insufficient memory to continue the execution of the program. at System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount) at System.Text.StringBuilder.AppendWithExpansion(Char value) at System.Text.StringBuilder.Append(Char value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Utilities.CrossReferenceCollectionReader.GetAllText(Reader reader, Int64 minOffset, Int64 maxOffset) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Utilities.CrossReferenceCollectionReader.FindAllObjectOffsets(Reader reader, Dictionary`2 tokenToOffsets, Int64 minOffset, Int64 maxOffset)
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 });
}
This is the code used for merging:
private void MergeDifferentDocumentsPagesWithFixed()
{
string[] documentsToMerge =
{
"14301-STOCK_Proforma.pdf",
"14302-STOCK_Proforma.pdf",
"14303-STOCK_Proforma.pdf",
"14304-STOCK_Proforma.pdf",
"14305-STOCK_Proforma.pdf",
"14330-STOCK_Proforma.pdf"
};
RadFixedDocument doc = new RadFixedDocument();
PdfFormatProvider provider = new PdfFormatProvider();
foreach (string current_item in documentsToMerge)
{
string path = @"..\..\Samples\" + current_item;
RadFixedDocument docToMerge;
if (!File.Exists(path))
{
continue;
}
using (Stream stream = File.OpenRead(path))
{
docToMerge = provider.Import(stream);
}
doc.Merge(docToMerge);
}
string outputFilePath = @"..\..\mergedFixed.pdf";
File.Delete(outputFilePath);
using (Stream output = File.OpenWrite(outputFilePath))
{
provider.Export(doc, output);
}
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
}
Workaround:
private void MergeDifferentDocumentsPages(string resultFileName)
{
string[] documentsToMerge =
{
"14301-STOCK_Proforma.pdf",
"14302-STOCK_Proforma.pdf",
"14303-STOCK_Proforma.pdf",
"14304-STOCK_Proforma.pdf",
"14305-STOCK_Proforma.pdf",
"14330-STOCK_Proforma.pdf"
};
File.Delete(resultFileName);
using (PdfStreamWriter fileWriter = new PdfStreamWriter(File.OpenWrite(resultFileName)))
{
foreach (string documentName in documentsToMerge)
{
string path = @"..\..\Samples\" + documentName;
using (PdfFileSource fileToMerge = new PdfFileSource(File.OpenRead(path)))
{
foreach (PdfPageSource pageToMerge in fileToMerge.Pages)
{
fileWriter.WritePage(pageToMerge);
}
}
}
}
Process.Start(new ProcessStartInfo() { FileName = resultFileName, UseShellExecute = true });
}
Currently, a NullReferenceException is thrown because of the incorrect structure.
As a workaround, the exception can be handled using the Handling Exceptions mechanism.
Update:
When importing documents with invalid structure of path construction operators an InvalidGraphicOperandsCountException is thrown which could be handled using the Handling Exceptions mechanism.
PdfFormatProvider provider = new PdfFormatProvider();
provider.ImportSettings.DocumentUnhandledException += this.ImportSettings_DocumentUnhandledException;
private void ImportSettings_DocumentUnhandledException(object sender, DocumentUnhandledExceptionEventArgs e)
{
if (e.Exception is InvalidGraphicOperandsCountException)
{
e.Handled = true;
}
}
The visual fill element is not exported to pdf:
Only the text part is present.
Import the document with RadSpreadProcessing and export it PDF format. You will notice that the cell value is displayed in the exported PDF document while in the Excel file it is hidden due to the custom format:
A page with a negative value rotation is exported as a blank image.
Workaround: Use only the Enum Rotation values (Rotate0, Rotate90, Rotate180, Rotate270).