Load Multiple PDF files on ASPX page

Hi,

I am trying to load multiple pdf files on a web page using object tag. I need to traverse through these files using next, previous, first, last buttons on the page. Here is the scenario:-

1. I have one container page which loads the PDF from binary stored in SQL server.

2. I have second page which is the host page for the container page. This page has the buttons for traversal, buttons for save, clear tags etc. This page contains the object tag as:-

<object id="PDFObject" type="application/pdf" data="PDFContainer.aspx" width="100%" height="500"></object>

I need to load different PDFs on click of the buttons of traversal i.e. next, previous, first and last.

I have tried passing different querystrings to the Container page. However the object tag gets hanged while doing so.

Please help.

P.S. - I am using Javascipt in PDF files using Adobe Acrobat. I had also posted one query yesterday for displaying PDF in div tag.

PDF-Viewer.bmp
unifiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BardobraveCommented:
Changing PDF url on buttons click actions seems to be correct way of doing what you need.

However here you're getting a problem with object hanging when you do so. Maybe you should reload your container to allow object to unload first document before loading the second, maybe your problem cames from object gaping with oversized data.
0
unifiAuthor Commented:
Hi,
I am using following code to in the buttons:-

protected void btnPrevious_Click(object sender, EventArgs e)
{
PDFContainer.InnerHtml = "<object id=\"PDFObject\" type=\"application/pdf\" data=\"PDFContainer.aspx\"" + "?PdfId=1" + " width=\"100%\" height=\"500\"></object>";
}
However I get an error (image attached). Please let me know your thoughts

PDF-Viewer-Error.bmp
0
BardobraveCommented:
Well, as for the error it seems you're getting a temporary file instead of the PDF file you want to load.

You should review your code and ensure all paths to the physical files are correct.
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

unifiAuthor Commented:
Hi Bardobrave,
I am loading PDF from binary. The binary would be loaded from database. For now I am using a physical file to read binary data. I have checked the paths and they are good.
Please let me know your thoughts.
Arun
0
BardobraveCommented:
However Adobe Reader is prompting you an error of being unable of opening the file... I supose you store somewhat in memory the binary data that you load from file before sending it to the Reader object, maybe the problem is in this memory storing, the data could be corrupted or not completely formatted when you try to load it.

In your code, when you post binary data to container object post it also to an output file. Try to open the output file when you get the error. If adobe is unable to open that file probably there is some error in the binary flow of data from your source file to Reader object.
0
unifiAuthor Commented:
Bardobrave
All files load good independently. However I face problem when I try to change the loaded pdf with a different PDF.
I can send my source code if needed.
Thanks,
Arun
0
BardobraveCommented:
Have you tried to work with the PDF as a whole instead of working INTO it?

I'll try to explain myself better. Instead of changing object properties on click, changing it's url direction to new file's one, try to change the whole object.

This should force a complete reload, if the urls are correct and considering that the first load of any file is working correctly, althought probably you'll get a slighly decrease in the load speed I think this should correct your problem... I'm quite sure the problem is in some type of data messing during unload/reload inside the object, so completely rebuilding it should do the trick.
0
unifiAuthor Commented:
Hi Bardobrave,
I have tried the following:-

PDFContainer.InnerHtml = "<object id=\"PDFObject\" type=\"application/pdf\" data=\"PDFContainer.aspx\"" + "?PdfId=2" + " width=\"100%\" height=\"500\"></object>";

ClientScript.RegisterClientScriptBlock(this.GetType(), "ChangePDF", "document.getElementById(\"PDFContainer\").object.location.href = PDFContainer.aspx?PdfId=2;");

ClientScript.RegisterClientScriptBlock(this.GetType(), "ChangePDF", "document.getElementById(\"PDFContainer\").setAttribute(\"data\", \"PDFContainer.aspx?PdfId=2\");");  
None of them seems to work. Can you provide some code snippet that can help me?
Thanks,
Arun
0
BardobraveCommented:
Unluckily I'm not used to work in C# so I can't provide you a code snippet (not a reliable one at least).

Are you getting same error after your last test or did it change?
0
unifiAuthor Commented:
yes I am getting same error.
0
BardobraveCommented:
You said that independent files open correctly. Have you tried to load into your object these independent files?
0
unifiAuthor Commented:
Hi Bardobrave,
I have been able to load both binary files independently.
However, not been able to change them programmatically. Please send your email address so that I can send you my sample app.
Thanks,
Arun
0
BardobraveCommented:
Attach your PDFContainer.aspx code. I'll try to check it to see if I get an idea of what could be happening.
0
BardobraveCommented:
Well... I've seeing your code and apparently it's all ok.

When you load the pdf <object> you obtain the PDF url through an .aspx page that calls a c# code from behind, who makes some type of byte-streaming of the pdf file.

I think this should be much easier. When you press a button to change from one pdf to another you should have an internal logic that gives you the url address of your .pdf, then your <object> must have only this url on it's data attribute

<object id="PDFObject" type="application/pdf" data="<PDF_url_get_from_your_logic>" width="100%" height="500"></object>

I think all your problems come from here. Data should have only the direction where the PDF is.
0
BardobraveCommented:
To extend a bit more...

Data attribute expects an URL to the object you're loading. Somewhat your byte-streaming is sending the real bunch of data that PDF is, while <object> tag is there to load this info from the url, is like you're doing it's work... surprisingly this seems to work in your first call, but makes a mess in the following ones.
0
unifiAuthor Commented:
Do you think it can be solved this way. I have still not been able to load multiple pdfs in such manner. I have tried using iframe which does work. Howver, iframe stops the working of the javascript that is embedded in the pdf (using adobe acrobat) and does not registers events correctly. So using iframe is out of question.
If you still have any other thoughts do let me know.
Thanks for your efforts though.
0
BardobraveCommented:
I'm not talking about using Iframes. The problem, attending at the error you've posted, cames from the byte-stream procces that you made in the c# part of your app.

You're using the <object> tag in a way that's not intended for. You should use your logic to obtain an url and pass this url to the object, rather than use your logic to load a byte stream of data and pass this stream of data to the object. All the stream processing that you're overloading in your logic is automatically managed by <object> tag.

Make a test, in your onchange function make the PDFContainer.innerHTMK equal to <object data="<url_pdf1>"> or <object data="<url_pdf2>"> depending on the parameter you pass to the function, and see if this way you get your pdfs loaded.

I'm not sure to be explaining myself well...
0
unifiAuthor Commented:
Hi Bardobrave,
The application I have send is just a sample and therefore I am loading PDF file into a binary stream.
In the actual application the PDFs would be stored in a database would always be available as binary. Writing the binary to a pdf file has already been ruled out by the management. So I have only option to load via binary streams only. There could be 10 or more binary PDFs that may be required to be loaded.
Do let me know your thoughts.
Thanks,
Arun
0
BardobraveCommented:
You should use the binary stream to write a temporary pdf file in the hard disk and pass it's url to <object> tag erasing the files when the object is unload or when user session ends, or whenever you need. On the other hand you maybe could find another way to load the PDFs different from using <object> tag, but I really think that the error that you're getting comes from the load of the strim in such an object.

However I could be mistaken, you should make a test.
0
ps316Commented:
Hi Arun,
You should use complete virtual directory path in Data attribute here as it sometimes refer to different path while accessing it from JavaScript,

"<object id=\"PDFObject\" type=\"application/pdf\" data=\"PDFContainer.aspx\"" + "?PdfId=1" + " width=\"100%\" height=\"500\"></object>";
I hope it will work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.