Link to home
Start Free TrialLog in
Avatar of tbittner
tbittner

asked on

Streaming two pdf's to two different browser windows.

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
Avatar of Justin_W
Justin_W

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.
Avatar of tbittner

ASKER

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.
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
Oops, you do not need to make the <tr> tags server controls.  The JavaScript will be what shows or hides them.

John
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.
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
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.
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
>> 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.
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!
ASKER CERTIFIED SOLUTION
Avatar of jnhorst
jnhorst

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial