Pages 2 and onward show No Preview Available

I just upgraded our installation.

Pages 2 and onward show No Preview Available:

image.png (319.8 KB)

@NancyJane307,

To help diagnose the problem, could you provide me with the following information?

  • The file that is causing the error.
  • The version of .NET that you are using.
  • Any other information you deem relevant.

With this information, I will be able to help you to resolve this issue.

The file causing the error is any pdf over 1 page.

The .NET version is 4.7.2

When I open a file directly it works such as:

ctlDoc.OpenDocument(Server.MapPath("~/Files/Sample.pdf"), new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });

But we store our documents in Azure, we retrieve a Blob, and send a Memory Stream converted to a Byte Array to Doconut as follows:

MemoryStream _ms = BbbReferral.Shared.AzureHelper.GetBlobAsStream(BbbReferral.Shared.AzureHelper.ContainerName.document, MyDocumentEntity.AzureFileId, ref Message);

ctlDoc.OpenDocument(BbbReferral.Shared.Utility.StreamToByte(_ms), MyDocumentEntity.FileExtension);

This worked before the upgrade. But now only page 1 shows up and the other pages say no preview available.

@NancyJane307,

If you send as a third parameter the correct config, should fix this issue.

var token = ctlDoc.OpenDocument(bytes, extension, new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });

Hi,

I tried adding the third parameter but the issue persists.
ctlDoc.OpenDocument(BbbReferral.Shared.Utility.StreamToByte(_ms), MyDocumentEntity.FileExtension, new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true })

image.png (337.1 KB)

@NancyJane307,

As a workaround, in the meantime, if you can save the file to disk and load it directly it will work.

Note: can you send me an app sample with your code? I tested the code I previously posted and it does work in the sample, including a PDF sample with no private data.

Hi,

I have attached a sample pdf that gets stored in Azure. The aspx code with the viewer. The .cs code behind, I don’t know how you will be able to replicate.

If you want to give me your code converting a sample file to byte array that you do that might work.

I can’t use your workaround b/c we don’t want to store the file locally to display it.

scrie-short-form-renewal.pdf (178.2 KB)

Javascript

using DotnetDaddy.DocumentConfig;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Document_ViewerTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BbbReferral.Dal.EntityClasses.DocumentEntity objDocument = null;
if (GetId(ref objDocument))
DisplayDocument(objDocument);
}

    //ctlDoc.OpenDocument(Server.MapPath("~/Files/Sample.pdf"), new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });
}

private bool DisplayDocument(BbbReferral.Dal.EntityClasses.DocumentEntity MyDocumentEntity)
{

    if ((MyDocumentEntity == null) || (MyDocumentEntity.Fields.State != EntityState.Fetched))
        return false;

    var Message = "";
    string _fileExtension = "";
    

    #region azure

    if (MyDocumentEntity.AzureStorage)
    {
        MemoryStream _ms = BbbReferral.Shared.AzureHelper.GetBlobAsStream(BbbReferral.Shared.AzureHelper.ContainerName.document, MyDocumentEntity.AzureFileId, ref Message);
        if (_ms == null)
            return false;

        _ms.Position = 0;
        ctlDoc.Visible = true;
        DotnetDaddy.DocumentConfig.PdfConfig myconfig = new DotnetDaddy.DocumentConfig.PdfConfig();

        
        myconfig.AllowSearch = true;
        myconfig.AllowCopy = true;
        myconfig.DefaultRender = true;
        myconfig.ExtractHyperlinks = true;
        
        //var _openDoc = ctlDoc.OpenDocument(_ms.ToArray(), MyDocumentEntity.FileExtension, new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });
        var _openDoc = ctlDoc.OpenDocument(BbbReferral.Shared.Utility.StreamToByte(_ms), MyDocumentEntity.FileExtension, new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });


    }
    #endregion
    return true;
}

private int? DocumentId
{
    get
    {
        object obj = this.ViewState["DocumentIdForView"];
        return (obj == null) ? (int?)null : (int)obj;
    }
    set { this.ViewState["DocumentIdForView"] = value; }
}

private bool GetId(ref BbbReferral.Dal.EntityClasses.DocumentEntity objDocument)
{
    int _id = -1;
    if (int.TryParse(BitByBit.Web.Request.GetString("Id").Trim(), out _id))
    {
        //edit existing
        objDocument = new BbbReferral.Dal.EntityClasses.DocumentEntity(_id);
        if ((objDocument.Fields.State == SD.LLBLGen.Pro.ORMSupportClasses.EntityState.Fetched) && (objDocument.AccountId.HasValue) && (objDocument.AccountId.Value == BbbReferral.Shared.User.AccountId))
        {
            DocumentId = objDocument.Id;
            return true;
        }
    }

    //DisplayMessage(String.Format("Unable to fetch Referral Document.  ID = {0}", _id > 0 ? _id.ToString() : "N/A"), BbbReferral.Shared.Bootstrap.Alert.AlertType.Danger, false, true);
    return false;
}

}

I just tried this simple code with the sample file I sent you.

The viewer does work if you open a physical file from the server.

But if I read this file into a memory stream and then convert to a byte array. I am getting the same problem. Only the first page shows up.

var myPath = Server.MapPath("~/Files/Sample.pdf");

        var pdfContent = new MemoryStream(System.IO.File.ReadAllBytes(myPath));
        pdfContent.Position = 0;

        var _openDoc = ctlDoc.OpenDocument(pdfContent.ToArray(), MyDocumentEntity.FileExtension, new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true });

@NancyJane307,

You can use the following example code to convert the byte array into a Stream object.

var config = new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true };
var fileInfo = new FileInfo(filePath);
var bytesArray = pdfContent.ToArray();
MemoryStream stream = new MemoryStream(bytesArray);

var token = viewer.OpenDocument(stream, fileInfo, config);

Let me know if this solution works for you.

Hi,

In my installation, I don’t have a filePath to create the fileInfo.

I receive a memory stream so I can pass that instead of the byte array.

But I don’t have a path to create a fileinfo.

@NancyJane307,

If you create a FileInfo object, it does not matter if it doesn’t have a real file name.

But it is very important that the name that is added as a parameter in the FileInfo has the extension, in this case, .pdf, otherwise it will not work. I see the extension is known because the config used is a PdfConfig.

Please test the following example and it will work.

var config = new PdfConfig { ExtractHyperlinks = true, AllowSearch = true, AllowCopy = true, DefaultRender = true };
var bytes = System.IO.File.ReadAllBytes(path);
MemoryStream stream = new MemoryStream(bytes);
var fileInfofakeName = new FileInfo("fakeName.pdf");
var token = viewer.OpenDocument(stream, fileInfofakeName, config);

Thank you so much!!

It worked!!!