I am trying to convert a pdf into a ppt, but am getting this error. It doesn’t tell me much besides that.
Value cannot be null.
Parameter name: output
group-docs.jpg (64.1 KB)
This is the Json Response:
{"data":{"Message":"An error has occurred.","ExceptionMessage":"Value cannot be null.\r\nParameter name: output","ExceptionType":"GroupDocs.Conversion.Exceptions.GroupDocsConversionException","StackTrace":" at GroupDocs.Conversion.Converter.Convert(SaveDocumentStreamForFileType document, ConvertedDocumentStream documentCompleted, ConvertOptionsProvider convertOptionsProvider)\r\n at MotivUmbraco.Services.FileConverterService.<Convert>d__6.MoveNext() in C:\\MotivSolution\\Code\\MotivUmbracoV8\\Services\\FileConverterService.cs:line 34\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\r\n at MotivUmbraco.Controllers.MicrositeApiController.d__2.MoveNext() in C:\MotivSolution\Code\MotivUmbracoV8\Controllers\MicrositeApiController.cs:line 38\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"},"status":500,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/umbraco/api/MicrositeApi/ConvertToPpt","data":{},"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"Internal Server Error","xhrStatus":"complete"}
This is the class
`using GroupDocs.Conversion;
using GroupDocs.Conversion.Contracts;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
public class FileConverterService
{
private readonly Stream _stream;
public Stream OutputStream { get; private set; }
public FileConverterService(Stream stream)
{
this._stream = stream;
}
public async Task<Stream> Convert(string licensePath)
{
using (Converter converter = new Converter(GetFileStream))
{
License license = new License();
license.SetLicense(licensePath);
PossibleConversions conversions = converter.GetPossibleConversions();
SaveDocumentStream save = new SaveDocumentStream(SetOutputStream);
var convertOptions = converter.GetPossibleConversions()["ppt"].ConvertOptions;
try
{
converter.Convert(save, convertOptions);
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.Message);
throw;
}
await Task.FromResult(true);
return OutputStream;
}
}
private Stream GetFileStream() => _stream;
private Stream SetOutputStream() => OutputStream;
}`
I do have a temporary license applied
What am I doing wrong?
@ccasalicchio
Please share following details:
- API version that you are using (e.g. 20.5, 20.9)
- Problematic PDF file
- A simple console application (if possible) using that issue could be reproduced
Actually, I was able to get it to save to the local disk G:\test.ppt so the pdf is ok.
The final app will open a new browser tab and download the powerpoint file, without saving it to the server’s hard disk. So I need to save the converted file as a stream, so I can push it to the browser. Is that possible? I couldn’t find any examples in the documentation
id=“GroupDocs.Conversion” version=“20.11.0” targetFramework=“net472”
Here’s the code snippet
using GroupDocs.Conversion;
using GroupDocs.Conversion.Contracts;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
public class FileConverterService
{
private readonly Stream _stream;
public Stream OutputStream { get; private set; }
public FileConverterService(Stream stream)
{
this._stream = stream;
}
public async Task<Stream> Convert(string licensePath)
{
using (Converter converter = new Converter(GetFileStream))
{
License license = new License();
license.SetLicense(licensePath);
PossibleConversions conversions = converter.GetPossibleConversions();
SaveDocumentStream save = new SaveDocumentStream(SetOutputStream);
var convertOptions = converter.GetPossibleConversions()["ppt"].ConvertOptions;
try
{
converter.Convert("G:\\test.ppt", convertOptions);
//converter.Convert(save, convertOptions);
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.Message);
throw;
}
await Task.FromResult(true);
return OutputStream;
}
}
private Stream GetFileStream() => _stream;
private Stream SetOutputStream() => OutputStream;
}
@ccasalicchio
Please have a look at the code below:
var source = "source file";
using (var resultStream = new MemoryStream())
{
using (var converter = new Converter(source))
{
//converting source file to PDF
var options = new PdfConvertOptions();
converter.Convert(() => new MemoryStream(), convertedStream => convertedStream.CopyTo(resultStream), options);
}
}
You can save the result in memory stream. Let us know if it’ll help.
Great, I got it working. Thank you!
Now, is there a way to embed custom fonts into the power point file? Since the PDF uses Open Sans (Google fonts) but when opening in a computer without it installed, the power points looks ugly.
@ccasalicchio
You can set default font or substitute a font, please take a look at this API reference guide. Let us know if it helps.
Is there a way to use a pre-existing ppt that has the font embedded?
@ccasalicchio
Could you please further elaborate this?
Nevermind the previous question. I’ve tried setting Verdana as a Substitute font but it doesn’t appear to be doing anything. How can I confirm this?
using GroupDocs.Conversion;
using GroupDocs.Conversion.Contracts;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Load;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
public class FileConverterService
{
private readonly Stream _stream;
public FileConverterService(Stream stream)
{
this._stream = stream;
}
public async Task<MemoryStream> Convert(string licensePath)
{
var resultStream = new MemoryStream();
License license = new License();
license.SetLicense(licensePath);
LoadOptions getLoadOptions() => new PresentationLoadOptions
{
DefaultFont = "Open Sans",
Format = PresentationFileType.Pptx,
FontSubstitutes = new List<FontSubstitute>
{
FontSubstitute.Create("Open Sans","Verdana")
}
};
using (var converter = new Converter(GetFileStream, getLoadOptions))
{
var options = converter.GetPossibleConversions()["pptx"].ConvertOptions;
converter.Convert(() => new MemoryStream(), convertedStream => convertedStream.CopyTo(resultStream), options);
}
await Task.FromResult(true);
return resultStream;
}
private Stream GetFileStream() => _stream;
}
I’ve also tried changing the PDF font to Verdana, but now the conversion fails with this error:
"ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"GroupDocs.Conversion.Exceptions.GroupDocsConversionException","StackTrace":" at GroupDocs.Conversion.Converter.Convert(SaveDocumentStreamForFileType document, ConvertedDocumentStream documentCompleted, ConvertOptionsProvider convertOptionsProvider)\r\n at MotivUmbraco.Services.FileConverterService.<Convert>d__2.MoveNext() in C:\\MotivSolution\\Code\\MotivUmbracoV8\\Services\\FileConverterService.cs:line 38\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\r\n at MotivUmbraco.Controllers.MicrositeApiController.d__2.MoveNext() in C:\MotivSolution\Code\MotivUmbracoV8\Controllers\MicrositeApiController.cs:line 34\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
I’m not sure what is wrong now
@ccasalicchio
We’re investigating this issue. Your investigation ticket ID is CONVERSIONNET-4336. You’ll be notified as there’s any update.
I have another issue with conversion. In the pdf, the text renders correctly
image.png (12.4 KB)
But the ppt renders with a weird symbol. How can I fix this?
image.png (9.7 KB)
@ccasalicchio
Please share the problematic/source file and we’ll look into this issue.
Here you go. files.zip (2.7 MB)
@ccasalicchio
We’re investigating this issue. Your investigation ticket ID is CONVERSIONNET-4372. We’ll notify you in case of any update.
Hi Guys, any news on this? Pete Kuhtey, from MotivIndex [pete@motivindex.com] (mailto:pete@motivindex.com) has purchased a full license (I’m developing it for them).
@ccasalicchio
CONVERSIONNET-4372 is expected to be fixed in API version/release 21.1. As far as CONVERSIONNET-4336 is concerned, we did some changes in the code and it worked for us (for PDF case).
Conversion.Options.Load.LoadOptions getLoadOptions() => new PdfLoadOptions
{
DefaultFont = "Open Sans",
FontSubstitutes = new List<FontSubstitute>
{
FontSubstitute.Create("Algerian","Verdana")
}
};
using (Converter converter = new Converter("test.pdf", getLoadOptions))
{
PresentationConvertOptions options = new PresentationConvertOptions();
converter.Convert("output.pptx", options);
}
LoadOptions
should be PdfLoadOptions
in case of PDF. Please let us know if your issue is fixed this way.
The issues you have found earlier (filed as CONVERSIONNET-4336,CONVERSIONNET-4372) have been fixed in this update. This message was posted using Bugs notification tool by yevgen-nykytenko