Search code examples
c#winformspdfarraysfilestream

Display pdf from byte array to c# winforms


I have made a program that encrypts and decrypts pdf files. I want them to be locked for anyone but me and to open them via my program only. After I encrypt the pdf I have it in a byte array. Is there anyway to display the decrypted byte array of the pdf file to the form without deploying the file to the drive?


Solution

  • What you need is a WinForms PDF viewer component that can load a PDF from a byte array. With the PDF viewer from Gnostice PDFOne .NET, here is the code:

    PDFViewer PDFViewer1;
    byte[] baPDF; // load the decrypted PDF to this byte array
    ...
    PDFViewer1.LoadDocument(baPDF);
    

    http://www.gnostice.com/docs/pdfone_dot_net/Gnostice_PDFOne_Windows_PDFViewer_PDFViewer_LoadDocument@byte[].html

    NOTE: I work for this Gnostice company. Any other PDF viewer component, if it can load from a byte array, will work.

    There is no need to save the decrypted PDF to the disk.