• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Sending Multiple PDF in response stream

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody tell how do I send multiple PDF in a response stream.
I have program that sends PDF as a binary data in a response stream and prints silenlty in the local machine in a default printer.
But I need to send multiple PDF in a request.
Any help??
 
Marshal
Posts: 67365
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you can zip them?
 
jaffrin abdul salam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletOutputStream out=response.getOutputStream();
response.setContentType("application/pdf");
String path = this.getServletContext().getRealPath("existing.PDF");
PdfReader reader = new PdfReader(path);
int n = reader.getNumberOfPages();
Rectangle psize = reader.getPageSize(1);
float width = psize.width();
float height = psize.height();
Document document = new Document(new Rectangle(width, height));
PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());

writer.setViewerPreferences( PdfWriter.HideMenubar | PdfWriter.HideToolbar | PdfWriter.HideWindowUI);

document.open();
writer.addJavaScript(
"this.print({bUI: false,bSilent: false,bShrinkToFit: true});" +
"\r\n" +
"this.closeDoc();"
);

PdfContentByte cb = writer.getDirectContent();
int i = 0;
int p = 0;
while (i < n) {
document.newPage();
p++;
i++;
PdfImportedPage page1 = writer.getImportedPage(reader, i);
cb.addTemplate(page1, 0, 0);

This is the code that sends one PDF(existing.pdf) to servlet output stream.
This code adds javascript to pdf file(that is writer.addJavascript()) that prints to the printer.
Now I want to know how Do i read PDF one by one and add the javascript and sent to it to the out stream.

Thanks in advance
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't send multiple documents. Go with Bears suggestion.

It's not good UI design anyway to try and print documents unless the user specifically requests it.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!