Not sure if this is were I should post this question. I have created a dotnet standard assembly to use with my controller with the PDFViewer that will translate a Word document (docx) to a pdf. I have tried several different methods and get the same error. The error I receive is: "Can not export other than Jpeg and Jpeg2000 and ImageQuality different than High". The document is pretty straight forward with text a barcpde and a table if that helps (a small image of the doc attached). Does anyone have an idea how to fix this? I also created a "this is a test" document and when it is displayed it shows: "PDF file fails to process." I have attached the document.
System.NotSupportedException
HResult=0x80131515
Message=Can not export other than Jpeg and Jpeg2000 and ImageQuality different than High
Source=Telerik.Documents.Fixed
StackTrace:
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.DoOnUnknownData(Byte[] unknownData, ImageQuality imageQuality, Action`1 doOnEncodedData)
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.InitializeImageInfoFromUnknownData(Byte[] unknownData, ImageQuality imageQuality)
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.EnsureImageInfo()
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.get_Width()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Objects.ImageXObject.CopyPropertiesFrom(IPdfExportContext context, ImageSource imageSource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportContext.GetResource(ImageSource resource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfContentExportContext.GetResource(ImageSource imageSource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ImageWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, Image element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.MarkableContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentRootWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, IContentRootElement element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.ContentStream.BuildContentData(IPdfExportContext context, IResourceHolder resourceHolder, IContentRootElement contentRootElement)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.Page.CopyPropertiesFrom(IPdfExportContext context, RadFixedPage fixedPage)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyRadFixedPageProperties(RadFixedPage source, Page destination, IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPagePropertiesFrom(IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPropertiesFrom(IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExporter.Export(IRadFixedDocumentExportContext context, Stream output)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFixedDocument document, Stream output)
at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
at Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFlowDocument document, Stream output)
at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
at TexasProtax.Document.Pdf.ConvertToPdf.FromWord(String filename) in D:\#bitbucket\TexasProtax\texasprotax.appraisalportal\TexasProtax.Document\Pdf\ConvertToPdf.cs:line 36
at TexasProTax.AppraisalPortal.Web.Areas.Document.Controller.ViewerController.GetDocument(String location) in D:\#bitbucket\TexasProtax\texasprotax.appraisalportal\TexasProtax.AppraisalPortal.Web\Areas\Document\Controller\ViewerController.cs:line 43
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
Here is the method:
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Telerik.Windows.Documents.Common.FormatProviders;
using Telerik.Windows.Documents.Flow.FormatProviders.Docx;
using Telerik.Windows.Documents.Flow.FormatProviders.Pdf;
using Telerik.Windows.Documents.Flow.Model;
...
public static Stream FromWord(string filename)
{
using (Stream inStream = File.OpenRead(filename))
using (Stream outStream = new MemoryStream())
{
IFormatProvider<
RadFlowDocument
> fileFormatProvider = new DocxFormatProvider();
RadFlowDocument document = null;
using (Stream input = File.OpenRead(filename))
{
document = fileFormatProvider.Import(input);
}
//byte[] renderedBytes = null;
IFormatProvider<
RadFlowDocument
> formatProvider = new PdfFormatProvider();
using (MemoryStream ms = new MemoryStream())
{
formatProvider.Export(document, ms);
//renderedBytes = ms.ToArray();
return ms;
}
}
}