Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to download a pdf file temp and extract pages into new pdf and send to browser?  RSS feed

 
Reuben Kurian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I dowloaded a blob file from db using this code.



My requirement is as below.
Clientside-The user clicks the download button
Serverside-the report shud be downloaded and this clients respective pages are there in this report which is to be
extracted page wise(which we know per client) and sent to the client. How do i achieve this? An example scenario is
as below. Client X clicks download. The report repwhole.pdf gets downloaded which has reports for all clients A-Z.
So I know X reports pages are 10 and 11. So i split that pdf separately as X.pdf and i send it to his browser and
it gets downloaded for him.

What i want to know mainly is
1)how do i download to a specific location in the above code?example "C:\TEmp\file.pdf"
2)How do i send the extracted new pdf file to the browser for the client when he
clicks download?
 
Christian Ludt
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reuben,

there is no way to tell the browser where to download a file to.

Regarding your second question: I think you should not download the whole PDF first but only the PDF the client is interested in. Here is what I (the servlet I wrote) would do:

I assume you can only access the full report, and the client can let the server know in which pages the client is interested in:
- get the full PDF
- extract the pages the client is interested in (there are PDF libraries out there, that can help, e.g. iText, see http://www.rgagnon.com/javadetails/java-0647.html)
- stream this PDF

If the client is not able to let the server know in which pages the client is interested in, the PDF must be split on the client side. I have never done this, so I cannot even tell if it is possible.


BTW, I am not sure what your samle code is supposed to do. Where does the "file" attribute come from? Could you post the entire servlet code?
Moreover, you cannot stream multiple files like you are doing in your code; the only way to achieve this (theoretically), is to use multipart content-type. But as far as I know, the current browsers do not support this. When I needed to stream / download multiple files, I created a zip with the files.

Best regards
Christian

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