Hello all,
I have the following problem when using the mail merge:
If I do not have watermark in the document, MailMerge and Export to PDF performs correctly.
Here is how I do the MailMerge (not full code):
and here is how I export to PDF (into a stream):
As I have mentioned, the problem occurs when I have a Watermark in my document. Even though Mail Merge performs correctly, the document crashes on the
provider.Export(document, output) saying that the current thread cannot access object as different thread owns it.
Here is full error report:
Your help would be highly appreciated as I don't know how to handle this problem.
Thank you.
Robert
I have the following problem when using the mail merge:
If I do not have watermark in the document, MailMerge and Export to PDF performs correctly.
Here is how I do the MailMerge (not full code):
//loop throught documentsdo{ RadDocument currentDocument = document.MailMergeCurrentRecord(); if (currentDocument != null) { //freeze images foreach (var image in currentDocument.EnumerateChildrenOfType<ImageInline>()) image.ImageSource.Freeze(); //Floating images foreach (var image in currentDocument.EnumerateChildrenOfType<FloatingImageBlock>()) image.ImageInline.ImageSource.Freeze(); lock (baton) documentQueue.Enqueue(currentDocument);//add new document to a queue for further processing currentDocument = null; }} while (document.MailMergeDataSource.MoveToNext());and here is how I export to PDF (into a stream):
public static async Task<Stream> ExportToPDF(RadDocument document){ PdfFormatProvider provider = new PdfFormatProvider(); Stream output = new MemoryStream(); await StartSTATask(() => { provider.Export(document, output); }); output.Position = 0; return output;}As I have mentioned, the problem occurs when I have a Watermark in my document. Even though Mail Merge performs correctly, the document crashes on the
provider.Export(document, output) saying that the current thread cannot access object as different thread owns it.
Here is full error report:
at System.Windows.Threading.DispatcherObject.VerifyAccess() at System.Windows.Media.Imaging.BitmapSource.get_PixelWidth() at System.Windows.Media.Imaging.WriteableBitmap.InitFromBitmapSource(BitmapSource source) at Telerik.Windows.Media.Imaging.RadBitmap..ctor(BitmapSource image) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.SetImageAlpha(WatermarkImageSettings imageSettings, Byte alpha) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.DrawWatermark(Header header, SectionLayoutBox sectionBox, PdfContentsWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.ExportHeadersAndFooters(SectionLayoutBox sectionBox, PdfContentsWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.ExportPage(SectionLayoutBox sectionBox, PdfContentsWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.<>c__DisplayClass1.<Export>b__0(PdfContentsWriter contentsWriter) at Telerik.Windows.Documents.FormatProviders.Pdf.RadPdf.PdfContents.WriteContents(PdfWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.RadPdf.PdfStream.WriteToCore(PdfWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.RadPdf.PdfObject.WriteTo(PdfWriter writer) at Telerik.Windows.Documents.FormatProviders.Pdf.RadPdf.PdfWriter.WritePdfObject(PdfObject obj) at Telerik.Windows.Documents.FormatProviders.Pdf.PdfDocumentExporter.Export() at Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider.Export(RadDocument document, Stream output) at IP_DocumentProcessor.MailMerge.IP_MailMerge.<>c__DisplayClass14.<ExportToPDF>b__13() in d:\VB Projects + Silverlight\VS2012APP\IP_DocumentProcessor\IP_DocumentProcessor\MailMerge\IP_MailMerge.cs:line 476 at IP_DocumentProcessor.MailMerge.IP_MailMerge.<>c__DisplayClass1a.<StartSTATask>b__19() in d:\VB Projects + Silverlight\VS2012APP\IP_DocumentProcessor\IP_DocumentProcessor\MailMerge\IP_MailMerge.cs:line 500--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at IP_DocumentProcessor.MailMerge.IP_MailMerge.<StartSTATask>d__1c.MoveNext() in d:\VB Projects + Silverlight\VS2012APP\IP_DocumentProcessor\IP_DocumentProcessor\MailMerge\IP_MailMerge.cs:line 510--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at IP_DocumentProcessor.MailMerge.IP_MailMerge.<ExportToPDF>d__16.MoveNext() in d:\VB Projects + Silverlight\VS2012APP\IP_DocumentProcessor\IP_DocumentProcessor\MailMerge\IP_MailMerge.cs:line 474--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at IP_DocumentProcessor.MailMerge.IP_MailMerge.<GenerateStreams>d__7.MoveNext() in d:\VB Projects + Silverlight\VS2012APP\IP_DocumentProcessor\IP_DocumentProcessor\MailMerge\IP_MailMerge.cs:line 282--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch()Your help would be highly appreciated as I don't know how to handle this problem.
Thank you.
Robert
