Conversion Problems with two specific files

Hi Groupdocs,

We’re running into an issue attempting to convert a couple of specific files to PDF. I’m attaching them both here.

With the JPEG file in the zip, we receive this exception. Specifying the filename does not result in good output (and also seems to be unnecessary with any other file we’ve ever tested with):

GroupDocs.Viewer.Exception.GroupDocsViewerException was unhandled by user code
HResult=-2146233088
Message=Unable to determine file type from a stream. Please try to specify filename with extension explicitly.
Source=GroupDocs.Viewer
StackTrace:
at . (Stream , String )
at GroupDocs.Viewer.Handler.ViewerHandler1. (Stream , String ) at GroupDocs.Viewer.Handler.ViewerHandler1.GetPdfFile(Stream fileStream, PdfFileOptions pdfFileOptions)
at BlueMoon.DMS.Services.Repository.DocumentConversionRepository.<>c__DisplayClass3.b__0() in c:\Dev\DocumentManagement\Development\DocumentServices\BlueMoon.DMS.Services\Repository\DocumentConversionRepository.cs:line 51
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException:

With the Word file also in the ZIP, the PDF output contains an error replacing the header in the top left that you can see if you view the document as is. The API seems to not like some aspect of the formatting in the header.

Here is our code:

public async Task<Stream> RenderDocumentAsPdfAsync(Stream document, string documentName)
{
    Guard.ArgumentNotNull(document,"document");
    Guard.ArgumentNotNullOrEmpty(documentName, "documentName");
    
    var config = GetViewerConfig();
    var imgHandler = new ViewerImageHandler(config);
    var pdfOptions = GetPdfOptions();
    var fileContainer = new FileContainer();
    
    try
    {
        var memoryStream = new MemoryStream();
        await document.CopyToAsync(memoryStream); 
        fileContainer = await Task.Run(() => imgHandler.GetPdfFile(memoryStream, pdfOptions));

    }
    catch (Exception ex)
    {
        ApplicationLogger.LogError(string.Format("Conversion of document {0} to PDF failed.  Exception: {1}", documentName, ex.ToString()), 
            MethodBase.GetCurrentMethod(), exception: ex);
        return null;
    }
    return fileContainer.Stream;

    private static ViewerConfig GetViewerConfig()
{
  
    var config = new ViewerConfig()
    {                
        UseCache = false,
    };
    return config;            
}

Appreciate any help! :slight_smile: These problems seem rare enough, but just figured it would be worth it to send these files over to you guys - perhaps issues in these specific files could imply issues in other similar files.

GroupDocs Viewer version is at 17.8

TwoFiles.zip (86.9 KB)

@bdrake,

Thanks for using GroupDocs.Viewer and sharing your concerns with us.

We have tested to render the JPEG image into PDF using your provided code but unable to reproduce the exception. This exception is usually thrown in some cases when it becomes impossible for the API to detect the file type from the stream. However, in case of your provided JPEG file, the API is rendering it without any issue using the following code.

// Method body
public static async Task<Stream> RenderDocumentAsPdfAsync(Stream document, string documentName)
        {
//Guard.ArgumentNotNull(document, "document");
            //Guard.ArgumentNotNullOrEmpty(documentName, "documentName");
            var config = GetViewerConfig();
            var imgHandler = new ViewerImageHandler(config);
            var pdfOptions = new PdfFileOptions();
            var fileContainer = new FileContainer();

            try
            {
                var memoryStream = new MemoryStream();
                await document.CopyToAsync(memoryStream);
                fileContainer = await Task.Run(() => imgHandler.GetPdfFile(memoryStream, pdfOptions));

            }
            catch (Exception ex)
            { 
                return null;
            }
            return fileContainer.Stream;
        }
//--------------------------------------
// Calling method 
string guid = "astronaught_720.jpg";
Stream source = File.Open(@"D://storage//" + guid, FileMode.Open);
var output = RenderDocumentAsPdfAsync(source, guid);
SaveFile(Path.GetFileNameWithoutExtension(guid) + ".pdf", output.Result);
//------------------------------------------------------------------

Furthermore, to improve the quality in the output PDF, you can also use pdfOptions.JpegQuality property and set its value upto 100.

We are able to reproduce this issue at our end and it has been logged into our issue tracking system (with ID: VIEWERNET-1482) for further investigation. We’ll keep you informed in case of any updates.

@bdrake.

The above-mentioned issue has been resolved and the fix of this issue is expected to be the part of GroupDocs.Viewer for .NET 18.1. As soon as version 18.1 is released, we’ll inform you here.

Thank you!!!

@bdrake,

You are welcome.

@bdrake,

The issue you have found earlier (filed as VIEWERNET-1482) has been fixed in this update.