Soft
Soft

Reputation: 1804

Loading PDF in Ext.Window

I have a servlet that returns a PDF. What i trying do is loading the PDF to Ext.Window. Below is the sample source

            Ext.getCmp('hisAmpPhyWin').load(
                    {
                        url:'servlet/Servlet/',
                        params: {xhtml:xhtmlData},
                        text: 'Loading PDF...',
                        scripts: false
                    });

Where 'hisAmpPhyWin' is a Ext.Window instance.

The thing is its showing the PDF content (i mean ascii characters) not the actual PDF in the browser.

Please help to fix this issue.

Upvotes: 1

Views: 2774

Answers (3)

vino20
vino20

Reputation: 429

Ext.onReady(function () {
    Ext.create({
        title: 'My PDF',
        xtype: 'panel',
        width: 600,
        height: 400,
        items: {
            xtype: 'box',
            autoEl: {
                tag: 'iframe',
                style: 'height: 100%; width: 100%',
                src: '/files/pdf-sample.pdf'
            }
        },
        renderTo: 'output'
    });
});

Upvotes: 0

Steven de Salas
Steven de Salas

Reputation: 21447

I think you might be better off using an IFRAME tag for this.

var win = new Ext.Window({
  title: 'PDF Content',
  width: 420,
  height: 320,
  plain:true,
  html: String.format(
      '<iframe src="servlet/Servlet?p1={0}&p2={1}" width="400" height="300" />',
      xhtmlData.p1, xhtmlData.p2)
})
win.show();

Note: A browser only opens your data as PDF if it knows the content type is application/pdf, in here you are using the AJAX .load() method which ignores the content type coming back from the servlet response, however if you refer to it directly using an IFRAME the browser will apply the correct MIME format.

Dont forget to make sure every instance of your window is destroyed (closeAction = 'close', which is set by default), otherwise it'll keep opening up the same PDF document over and over again.

Upvotes: 5

Jason
Jason

Reputation: 1183

I don't think you can do it natively, but there is a really good UX that should do it.

http://www.sencha.com/forum/showthread.php?23983-ux.Media-.Flash-Flex-Components-2.1.2&highlight=ux.Media

Upvotes: 0

Related Questions