Skip to content

C# code for Printing & Previewing PDF'S without using Proces

LavanKumar R

Asked Jul 20, 2015, 1:44 AM EDT3 answers
Share
LinkedInX

I have to print and preview the pdf's  separately in 2 different functionalities

i.e without using the 

System.Diagnostics.Process.Start(@filePath); code . As this code is not acceptable by our security platform scan.kindly help..

below is the code
C#
private void PreviewFile(byte[] blobData, string fileName)
        {
            if (blobData != null)
            {
                string filePath;
                PDFPreviewHandler pdf = new PDFPreviewHandler();
 
Java
                string tempDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Template");
                if (!Directory.Exists(tempDirectory))
                    Directory.CreateDirectory(tempDirectory);
                filePath = Path.Combine(tempDirectory, fileName);

                try
                {

                    FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    bool isfile = false;


                    fileStream.Write(blobData, 0, blobData.GetUpperBound(0));
                    fileStream.Flush();
                    fileStream.Close();
                    fileStream.Dispose();
                    //Displaying the file
                    if (File.Exists(@filePath))
                    {
                        isfile = true;
                    }
                    if (isfile && File.Exists(@filePath))
                        System.IO.File.OpenRead(filePath);

                    wb1.Navigate(@filePath);
                   //     byte[] byteArray = System.IO.File.ReadAllBytes(@filePath);
                    //  System.Diagnostics.Process.Start(@filePath);

                }

              


 




































 



 

System.Diagnostics.Process.Start(@filePath);

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • +1
    There's a lot of white space in your question, so I'm not sure if it contains all the text you wanted to put in it. In any case, if I understand it correctly, you want a way to view and print the pdf files inside your own program without invoking external programs like Adobe Reader. I think you can't do this using .NET alone because it doesn't have support for viewing PDF files, so you will probably have to use a library that has the ability to load and display PDFs such as Lead Tools or iTextSharp.
    +1
  • +1
    I don't think there's a way to simply "invoke ... any pdf library" installed on the computer. When using a library, you have to add explicit references to that library in your project. You cannot easily code it so as to use different libraries if they happen to be installed. You must deploy the library you use with your EXE.
    +1
  • 0

    ya I got u.. thanks for the reply..

    sorry by mistake that white space has come..all code except the last line

    i.e System.Diagnostics.Process.Start(@filePath); is not in the code,ignore it
     
    but  I need to write the code ( default )which will invoke the installed any pdf library as it is a console application .
    0