• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending Multiple PDF in response stream

 
jaffrin abdul salam
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??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!