• Post Reply Bookmark Topic Watch Topic
  • New Topic

process html content if content type is set as pdf  RSS feed

 
Sree Lakshmi Sugunan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the servlet, I am setting the content type for the response as

res.setContentType("application/pdf") Then I add the pdf content as string. After that I add html content that intiates request to a server to disply an image.

eg. <IMG ALT=\"\" BORDER=\"0\" NAME=\"DCSIMG\" WIDTH=\"1\" HEIGHT=\"1\" SRC=\"http://xxxxx/njs.gif?dcsuri=/nojavascript&WT.js=No\">\n")

Will the html content will be processed as the content type is set as ("application/pdf")

Can I do the same if the content type is set as application/vnd.ms-excel
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I add the pdf content as string. After that I add html content that intiates request to a server to disply an image.


Why are you trying to do all this in one response?

It is the basic nature of web pages that each kind of content MUST be handled in its own request/response cycle. PDF content is binary and should never be treated as a String.

Bill
 
Sree Lakshmi Sugunan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want is to pass certain details to a server through the request header for logging purpose(using webtrend).

In the servlet, I get the details as html or PDF fomat or excel from another system, which I write to the outputstream. Also I add the line for image request so that a request with the required details is initated to the server.

For HTML, it is fine I can append the image with source as the server but for pdf and excel can I add the same? Will the Browser process this line and send the request?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You cannot mix HTML and a binary stream.
 
Sree Lakshmi Sugunan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I have an issue with implementing. Hope someone can suggest an option.

From a page I submit to generate a pdf report. In the servlet part it gets the report from another system and it is writen in to output.

java.io.PrintWriter out = res.getWriter();
res.setContentType("application/pdf");
res.setHeader("Content-disposition","inline; filename=lossfocus.pdf");
out.println(report.getContentString().toString());

Now is there a option that I can include calls to certain java scripts functions and "<IMG ALT=\"\" BORDER=\"0\" NAME=\"DCSIMG\" WIDTH=\"1\" HEIGHT=\"1\" SRC=\"http://XXXXX/njs.gif?dcsuri=/nojavascript&WT.js=No\">\n") so that the functions are executed and a request goes to te url.

The javascripts are to collect the tags and other details like

function dcsMeta(){var elems;
if (document.all){elems=document.all.tags("meta");}

like this.

Thanks in Advance
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you can't send both streams in the same request/response, you've got to do it in two. And since you can't do anything active in PDF, don't send that first. Rather, send the HTML/JavaScript response, that in turn, initiates a new request to serve the PDF.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!