PDF open from TabPanel

  1. #1

    PDF open from TabPanel

    Hi,
    I am trying to open a PDF from an asp.net page inside a TabPanel and then show save/open dialog of either IE or FF the code is
            Response.ContentType = "application/pdf";
            Response.Cache.SetCacheability( System.Web.HttpCacheability.Public );
            Response.AppendHeader( "Content-Type", "application/pdf" );
            Response.AppendHeader( "Content-Disposition", "attachment; filename=testD.pdf" );
            Response.OutputStream.Write( PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length );
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
    I have a button that fires an AjaxEvent but the browser returns this response,
    Status code: 200
    Status text: BADRESPONSE: Syntax error



    I should add that from a GridPanel it works fine as in this example
    http://forums.ext.net/showthread.php...?Highlight=pdf
    and from a TabPanel in AutoLoad as in this example
    http://forums.ext.net/showthread.php...?Highlight=pdf

    Can I change the Response inside a TabPanel and is there a way to display a Save\Open dialog window from a TabPanel?
  2. #2

    RE: PDF open from TabPanel

    Ok this is the exact code that I'm using, you will need iTextSharp
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using iTextSharp.text;
    using System.IO;
    using iTextSharp.text.pdf;
    
    public partial class TabPanel: System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
    
        }
        protected void btnPrintPDF_Click( object sender, EventArgs e )
        {
            HttpContext.Current.Response.Clear(); ;
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.BinaryWrite( CreatePDF() );
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
    
        public static byte[] CreatePDF()
        {
            Document doc = new Document( PageSize.LETTER, 72, 72, 72, 72 );
            MemoryStream ms = new MemoryStream();
            PdfWriter writer = PdfWriter.GetInstance( doc, ms );
            doc.Open();
            doc.Add( new Paragraph( "Sample PDF" ) );
            doc.Close();
            return ms.ToArray();
        }
    }
    This is the markup
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TabPanel.aspx.cs" Inherits="TabPanel" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager runat="server">
        </ext:ScriptManager>
        <ext:TabPanel ID="TabPanel1" runat="server" ActiveTabIndex="1" Height="300">
            <Tabs>
                <ext:Tab runat="server" Title="Tab 1">
                    <AutoLoad Mode="IFrame" Url="http://localhost:5041/Test/PDF.aspx" />
                </ext:Tab>
                <ext:Tab runat="server" Title="Tab 2">
                    <Body>
                        <ext:Button runat="server" ID="btnPrintPDF" Text="Print">
                            <AjaxEvents>
                                <Click OnEvent="btnPrintPDF_Click" />
                            </AjaxEvents>
                        </ext:Button>
                    </Body>
                </ext:Tab>
                <ext:Tab runat="server" Title="Tab 3">
                    <Body>
                    </Body>
                </ext:Tab>
            </Tabs>
        </ext:TabPanel>
        </form>
    </body>
    </html>
    Tab1 AutoLoads to a asp.net page with the same code to spit out a PDF using iTextSharp and it works fine

    When I click button in tab 2 this is what I get,
    Status code: 200
    Status text: BADRESPONSE: Syntax error.
    Does anyone know if there is a solution?
    Any help is appreciated,
    Tim <title></title><link href="/Test/extjs/resources/css/ext-all-embedded-css/coolite.axd?v=2802" type="text/css" rel="stylesheet">
  3. #3

    RE: PDF open from TabPanel

    Ok just a quick update
    I have changed the ajaxevent to this
    tab2.AutoLoad.Url = "http://localhost:5041/Test/PDF.aspx";
    tab2.LoadContent();
    I changed the ajax event to reload with the PDF from an ASP.net page and it displays but not with an open save dialog.

    Does anybody know how to do this?
    Tim
  4. #4

    RE: PDF open from TabPanel

    Ok,
    Problem Solvered!
    I changed the AjaxEvent.IsUpload to true and it let's it through!!!!!
    Thanks for all your help.
    Tim
  5. #5
    though this thread has been solved, i still like to make a little contribution on how to open pdf from other path with pdf software, here is a piece of sample codes i am using, check out.

    /// <summary>
    /// Load PDF From Stream
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    public PDFDocument LoadPDFDocumentFromStreamDemo(Stream s)
    {
        PDFDocument doc = new PDFDocument(s);
    Last edited by Daniil; May 21, 2014 at 6:16 AM. Reason: Please use [CODE] tags

Similar Threads

  1. [CLOSED] How to keep all open tabs in the same line in tabpanel?
    By pdcase in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 23, 2011, 10:59 AM
  2. [CLOSED] Ext.Net's tabpanel and ExtJs tabpanel anchor
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 21, 2011, 11:57 AM
  3. Replies: 4
    Last Post: Nov 24, 2010, 6:06 AM
  4. Replies: 3
    Last Post: Aug 21, 2009, 2:24 PM
  5. Get TabPanel ActiveTab inside Other TabPanel.
    By grmontero in forum 1.x Help
    Replies: 1
    Last Post: Jul 16, 2009, 11:45 AM

Posting Permissions