Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, then I explain what I have to do: within the Immagine variable there is a pdf, I should convert it into a memory steam and view it through the application default from the operating system to open the pdf, do you have any advice on how to do?

What I have tried:

using System;
using System.Drawing;
using System.IO;

namespace App.View
{
    public partial class VisualizzazioneDocumenti : MaterialSkin.Controls.MaterialForm
    {
        public byte[] Immagine;

        public VisualizzazioneDocumenti()
        {
            InitializeComponent();
        }

        private static Bitmap ByteToImage(byte[] blob)
        {
            MemoryStream mStream = new MemoryStream();
            byte[] pData = blob;
            mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
            Bitmap bm = new Bitmap(mStream, false);
            mStream.Dispose();
            return bm;
        }

        private void VisualizzazioneDocumenti_Load(object sender, EventArgs e)
        {
            this.pictureBoxImmagine.Image = ByteToImage(Immagine);
        }
    }
}
Posted
Updated 8-Apr-18 19:11pm
v2

As far as I know there is no way to hand a memory stream to any existing PDF viewer app, so you would have to use a PDF viewer component within your application. And I wouldn;t expect such to exist, given that a stream is part of the memory allocated to your app, and that isn't normally available to external applications.

There are some available which will do it: Free PDF Viewer Component - Read/View/Print PDF in C#,VB.NET | Spire.PDFViewer[^] provides a "community edition" which is limited to 10 pages but which can work directly from a stream. There may be others, but you'll have to work with Google to find out.
 
Share this answer
 
Comments
rikidev 6-Apr-18 5:39am    
thanks
OriginalGriff 6-Apr-18 5:44am    
You're welcome!
Better open the pdf with default application.

Code:

System.Diagnostics.Process.Start(@"c:\MYPDF.pdf");


or

Try to add COM components of Adobe Reader or other Pdf Viewer.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900