• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending Multiple PDF in response stream

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you can zip them?
 
jaffrin abdul salam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic