• Post Reply Bookmark Topic Watch Topic
  • New Topic

Opening PDF taking Huge time in java  RSS feed

 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Currently iam having pdfs of having size more than 20 MB. When we try to open that PDF file in our application it is taking more time to open. My sample code is:

Is there any alternative to open those files quickly?
I taught that converting pdf to image will reduce size and it will open quickly. But after conversion,it couldn't find much difference in sizes. I tried it in another way

By using runtime.getruntime i found better diffference in opening that PDF. But i don't know wheather it is encouragable or not. I think if we want to use this one, who are accessing our application adobe must installed in system.Thats why i'm re- thinking on this. Could you provide me any better solution for this.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect your problem is nothing at all to do with Java. The "rundll" approach does not use the network and the implication of the setContentType() is that you actually need to read the file over a network so the question is how long does it take to download 20 MBytes on your network?

Also, the 'rundll' approach is on the client and the other code is on a server so they are in no way alternatives.
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Richard,
Here we dont download any files. We will have view Invoice details button, when we click on that we have to open that particular invoice PDF which is already stored in server only. For opening that file , we currently doing as
But for an 20MB file it is taking nearly 18- 20sec to open that PDF in browser. So i'm asking about is there any alternative for this problem to open my pdf quickly.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't understand what your Java code is doing! What is the 'response' object and where is the code being executed?

Why are you not using the Destop ? Something along the lines of
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard

Having seen similar code before, I suspect the code is being run within an application server and the snippet posted is within a doGet or doPost method of a servlet. The response object will be of type HttpServletResponse. Sarvesh, am I correct?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:Richard

Having seen similar code before, I suspect the code is being run within an application server and the snippet posted is within a doGet or doPost method of a servlet. The response object will be of type HttpServletResponse. Sarvesh, am I correct?


That is what I assumed from the use of response.setContentLength() but then the OP talks of using "rundll" which must run on the client and not the server! I can see there may be a case to have an application server running on the client but not just to display PDF files; that is what the Desktop class is used for!
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@James Yes your correct james. Response object is in my action class. Currently we are reading pdf file and writting it into browser( as we are setting response.setContentType("application/pdf") ). But while wrinting response into browser new window it taking huge time. For that one i'm checking for an alternative solution. By going some sites , i got that command to open a file directly with out writting it to browser. So i tried with that one and it is working , but my question is; am i going in the right way or not. If not could suggest me some other alternative for this problem. Thanks both of you for the reply.
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i'm not aware of both the commands dll and desktop. ours is web application not desktop application.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarvesh Vemana Sarvesh wrote:but my question is; am i going in the right way or not. If not could suggest me some other alternative for this problem..


As I have already said, the correct approach would be to use the Desktop class !
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Richard. I tried with Deskop class, and it is working fine. But here it my local system, will this works in my production i mean those who are accesing our web site. Sorry i'm new to development.
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Richard.
I understood what Destop will do.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarvesh Vemana wrote:@Richard. I tried with Deskop class, and it is working fine. But here it my local system, will this works in my production i mean those who are accesing our web site. Sorry i'm new to development.


Obviously one can't use either the 'rundll' approach or the Desktop approach on the Server !!! You are forced to go with reading the file and writing it to the 'response' object. In your position I would increase the buffer size to at least 16 KBytes but this may not scale well. The limiting factor is likely to be the speed of the Internet connection which of course you are probably unable to do anything about.
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard,
I verified this one in production server. I got an issue that file is opening at server location(where production server is running) not in client location/ client browser. Any suggestion??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard already said what you need to do in his last post - did you understand what he meant by that?
 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i increased buffer size also like



But still it taking same time to open
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
16K is a very small amount for a 20MB file; try upping that to at least 256KB or something like that. But keep in mind what Richard said about scalability.

As to the time it takes, does it download faster if you put the file directly on the server and download it by entering its address in the browser? If not, then the limiting factor is likely the network connectivity, as Richard said.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my experience that a buffer greater than 16K will make very little difference. The limiting factor is either going to be the network speed or the disk access speed and to my mind it is most likely the network speed. By modern standards I have a very slow Internet speed (2 MBit/second ish) and the best I can get is about 200 bytes per second which for a 20 MByte file is about 100 seconds to download. I download a lot of big PDF files and the download time is always significantly greater than the time taken to display the downloaded document in Adobe. The OP must establish the speed of his network//Internet connection before he goes any further.

 
Sarvesh Vemana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Richard for your patience. So i can go for download option instead of viewing file.Ill try that one. One more thing while surfing in net, i found a new info that mozilla fire fox will take huge time to open pdf. It is an issue in mozilla browser . I verified that one also , in IE and chrome my files are opening very fast there 50% performance difference between the Mozilla and other two browsers. I'm searching for solution for mozilla browser, Why because most of our clients use mozilla only. If you any solution please share with me. Thank you once again.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarvesh Vemana wrote:Thank you Richard for your patience. So i can go for download option instead of viewing file.Ill try that one.

I don't understand! You currently have a single operation process of downloading the file and then immediately displaying it which allows the display of the file to start before the whole file is downloaded! I can't believe two separate stages ( first downloading then displaying) can be faster than the all in one process!

One more thing while surfing in net, i found a new info that mozilla fire fox will take huge time to open pdf. It is an issue in mozilla browser . I verified that one also , in IE and chrome my files are opening very fast there 50% performance difference between the Mozilla and other two browsers. I'm searching for solution for mozilla browser, Why because most of our clients use mozilla only. If you any solution please share with me. Thank you once again.


I have noticed very little difference between using Cromium and Firefox. Until you establish the network/Internet speed and do some simple calculations about the theoretical time taken to download a file you are only guessing as to where your problem lies.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!