ASP.NET PDF Viewer Control
How to open, view a Tiff image file online in web browser using C# ASP.NET


How to read, display, annotate, redact, edit, convert TIFF image in web browser using C# ASP.NET PDF Viewer control.





EdgePDF is an ASP.NET PDF viewer and editor web control. However you could also read, view TIFF image file in web browser with EdgePDF using C# ASP.NET

  • Open, read a TIFF file from server side document system or database
  • EdgePDF will automatically convert loaded TIFF to PDF document in ASP.NET web server
  • Use OCR engine to convert TIFF image to editable PDF document if possible
  • View, comment, edit TIFF file online in web browser

How to view a TIFF image file programmatically in asp.net using C#

  1. Download EdgePDF asp.net PDF viewer web control
  2. Install EdgePDF demo project in IIS
  3. Follow step by step tutorial






Preparation



To run the following tutorial successfully, we need the following setup ready.



  1. Install EdgePDF demo project in IIS
  2. A demo TIFF image file in folder C:\temp\tiff-1.tif




How to read, view TIFF image online in web browser in ASP.NET C#?



The following steps and C# demo source code will show how to read, view TIFF image file online using ASP.NET C# code.

After you have completed the following guide, you can open, view a TIFF file online in web browser through url (a sample url http://localhost:56643/?yourtarget=tiff-1.tif)

  • Open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/
  • Go to method FileProcess()
  • Create a new byte[] object with viewed TIFF image file in byte array
  • Call method REProcessControl.PageLoadFile() to load, view TIFF file in EdgePDF. The TIFF file (tiff-1.tif) has been converted into PDF file and displayed in EdgePDF online in web browser


    public override PDFWebDocument FileProcess()
    {
        HttpRequest request = this.Context.Request;

        if (!String.IsNullOrEmpty(request.QueryString["yourtarget"]))
        {
            String docid = request.QueryString["yourtarget"];

            byte[] dataBytes = System.IO.File.ReadAllBytes(@"C:\\temp\" + docid);
                
            return REProcessControl.PageLoadFile(request, this.Manager, dataBytes, docid);
        }
        else
        {
            Logger.Log(">>> Unknown load file mode. Load default file defined in Web.config.", LogType.DEBUG);

            // load default file. defined in Web.config
            return REProcessControl.PageLoadFile(request, this.Manager, "", LoadType.Server);
        }
    }







How to view, comment, edit TIFF image file in web browser in ASP.NET C#?



The following steps and C# demo source code will show how to view, edit a TIFF image file content in web browser using ASP.NET C# code.

After you have completed the following guide, you can open, view a TIFF image file online in web browser through url (a sample url http://localhost:56643/?yourtarget=tiff-1.tif)



  • Open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/
  • Go to method FileProcess()
  • Create a new TIFFDocument object with tiff image file loaded
  • Use OCR to extract text content from TIFF file. Set OCR resource files location.
  • For each tiff image page, use method OCRHandler.Import() to convert to a OCRPage object
  • Call method PDFDocument.CombineDocument() to combine all OCRPage objects into a PDFDocument object
  • Call method REProcessControl.PageLoadFile() to load, view TIFF image in text content in EdgePDF. The TIFF file (tiff-1.tif) has been converted into editable PDF file and displayed in EdgePDF online in web browser


            // load file
            String docid = request.QueryString["yourtarget"];
            if (docid == null) docid = "0";
            String fileName = docid;

            TIFFDocument tiffDoc = new TIFFDocument(@"C:\\temp\" + docid);
            int pageCount = tiffDoc.GetPageCount();

            MemoryStream editableDoc = new MemoryStream();

            // The folder that contains OCR '.traineddata' files.
            OCRHandler.SetTrainResourcePath(@"C:\Sites\EdgePDF.Sample\OCRSource");

            MemoryStream[] streams = new MemoryStream[pageCount];
            for (int i = 0; i < tiffDoc.GetPageCount(); i++)
            {
                streams[i] = new MemoryStream();
                OCRPage page = OCRHandler.Import(tiffDoc.GetPage(i));
                page.Recognize();
                page.SaveTo(MIMEType.PDF, streams[i]);
            }
            PDFDocument.CombineDocument(streams, editableDoc);

            return REProcessControl.PageLoadFile(request, this.Manager, editableDoc, fileName);