Solved

Streaming two pdf's to two different browser windows.

Posted on 2004-09-08
14
619 Views
Last Modified: 2008-01-09
Hi all,

I created a web service that returns two pdf's to me in byte arrays.  I can stream one of the bytes arrays to the browser and acrobat displays it.  How do I get the second pdf displayed in a different browser window?  I want both pdf's displayed at the same time.

Here is the code I'm using to retrieve the pdf's and then stream it down to the browser:

        Dim serror As String = ws.RetrieveImages(aImgKeys, aNames, aValues, aPDF, aDataPDF)
        If InStr(serror, "Success!") Then
            Response.ContentType = "application/pdf"
            Response.Buffer = True
            Response.BinaryWrite(aPDF)
            Response.End()
            Response.ContentType = "application/pdf"
            Response.Buffer = True
            Response.BinaryWrite(aDataPDF)
            Response.End()
        Else
            Response.Write(serror)
        End If

Thanks in advance for advice!
Terry
0
Comment
Question by:tbittner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
14 Comments
 
LVL 24

Expert Comment

by:Justin_W
ID: 12012438
It can't be done.  Each PDF needs to be requested individually by a separate browser window (i.e. using 2 separate HTTP requests).  Your best bet is to spawn a 2nd window from the 1st window using JavaScript, then redirect both windows to a URL that will stream the PDFs.
0
 

Author Comment

by:tbittner
ID: 12012485
That's the conclusion I was coming up with.  I was trying to store the two byte arrays in module level variables and then have a page call the same asp web page twice so I could stream the pdf's down but I'm not having much luck.  Is there a way to mix javascript in with a pdf?  I don't mean embedding javascript inside the pdf, I mean send some javascript to the browser and then stream the pdf to it.  Then I could have the javascript open up a new browser window that I could then stream the second pdf into.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12012770
Here's a thought that might replace showing them in two browser windows.  Begin by saving the byte arrays to files with a .pdf extention in some folder in the website.  Then use the <iframe> tag as a server control by putting an id and runat=server attribute in it.  If you create an html table, and then have these rows:

<tr id="pdfOne" runat=server style="display:"></tr> and
<tr id="pdfTwo" runat=server style="display: none;"></tr>

then in the table cells in each row, put <iframe> tags (one iframe in each table row):

<iframe id="frmPDFOne" runat=server src=""></iframe> and
<iframe id="frmPDFTwo" runat=server src=""></iframe>

Then in your code behind when you get the byte arrays, save them to a file and then set the src attribute on the two iframe tags like this:

frmPDFOne.Attributes("src") = "relativepathtofolder/pfilefileone.pdf"
frmPDFTwo.Attributes("src") = "relativepathtofolder/pfilefiletwo.pdf"

Lastly, put a couple of div tags above the table to server as tabs.  Each div should have an onclick attribute to call a JavaScript routine that will hide one table row and show the other so you can click between the pdf files.

The only downside here is the files that will build up in the folder.  One option to get around that is to have a separate aspx page that takes the filename in the querystring and then uses Response.WriteFile() to stream it to its frame.  Both frames could call this single page, just with different filenames in the querystring.  After Response.WriteFile is called you can call System.IO.File.Delete(filename).

John
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 10

Expert Comment

by:jnhorst
ID: 12012775
Oops, you do not need to make the <tr> tags server controls.  The JavaScript will be what shows or hides them.

John
0
 

Author Comment

by:tbittner
ID: 12012906
That is also a great suggestion but my servers are VERY busy.  To the tune of 1,000's of requests per minute.  I really don't want to slow them down by writing the PDF's out to the disk.  One of the PDF files is created from a TIFF and the other is a table I create based on data captured from the orginal image.  I'm using Dynamic PDF for the creation and conversion.  EXCELLENT and FAST product.  My site server (a quad xeon with 16 gig mem) is the same server that my web service is running on.  The web service is also used by our production server (HP Itanium server with 16 processors) to archive the images so it really is a VERY busy server.

I've worked very hard to make sure everything stays in memory.  Not to mention the security issues of having sensitive data residing on disks.  Granted, once it is streamed down to the client, Acrobat is probably creating temporary files on the clients machine but maybe not since they are small pdf's (average 35k).

I'm considering putting the data into a content frame within the pdf so I only have a single PDF to deal with but I'm concerned that some users might be running 800 x 600 and the PDF wouldn't be usuable to them.  Whereas if the information was in two different windows, they could ALT-TAB between them.  Maybe the key is having more knowledge into the capabilities of PDF.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12013198
OK, how about using the iframe idea, but instead of Response.WriteFile(), the page would take a querystring value that would tell it which call to make to the webservice.  The webservice would return the byte array and you would Resopnse.BinaryWrite() that array to the frame.  The other frame would have a different querystring value, which would tell it to get the other byte array and write it out to its frame.

Also, you can have different page dimnesions in a single PDF.  One page can be landscape, for example, and another portait.  I do not know if that addresses your difficulty, though.

John
0
 

Author Comment

by:tbittner
ID: 12013258
That might possibly resolve the issue.  I'll try that out tomorrow and let you know how it works.  The problem with this solution is it's all embedded within one browser window and I'm concerned about the screen space available.  So a solutiion with two browser windows is very desirable.
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12017164
The prob with a two window approach is there is no way to spawn a new window from server-side code (in the codebehind).  If you have the iframes in table rows and you toggle their display style with <div> tags serving as tabs, each pdf is viewed using almost all of the screen.  Instead of alt-tabbing between the two browser windows, the user clicks the <div> tags to view one and hide the other .

John
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 12017953
>> Is there a way to mix javascript in with a pdf?
Technically, no.  But you can output JavScript that first spawns a window, then auto-redirects to a page/URL that just streams the 1st PDF.

>> The prob with a two window approach is there is no way to spawn a new window from server-side code (in the codebehind).
Not true.  You just have to have the server-side code output a JavaScript block that contains a window.open() call.
0
 

Author Comment

by:tbittner
ID: 12022468
Don't suppose you could show me a WORKING example.  I tried and it intereferes with the streaming down of the PDF file to the window that I sent the javascript too.

Thanks!
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 250 total points
ID: 12022850
Terry:

I just ginned up a page with the following Page_Load and it worked as expected.

private void Page_Load(object sender, System.EventArgs e)
{
      if (!this.IsPostBack)
      {
                                // Since I do not have your webservice, I opened the PDF to a stream, got a binary reader and converted it to a byte array.  
                                // You would look at your querystring and call your webservice accordingly to return the byte array.
            string pdf = Request.PhysicalApplicationPath + "PDFSamples\\test.pdf";
            Stream str = File.Open(pdf, FileMode.Open);
            BinaryReader br = new BinaryReader(str);
            Byte[] ba = br.ReadBytes(Convert.ToInt32(str.Length));

                                // this properly streamed the pdf.
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(ba);
            Response.Flush();
            Response.Close();
      }
}

This would be the page your two iframe tags would load with a querystring value determining which bye array your webservice returns.

John
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question