how can one set the title of a new window containing a PDF document?
how can one set the title of a new window containing a PDF document?
- Subject: how can one set the title of a new window containing a PDF document?
- From: Ray Kiddy <email@hidden>
- Date: Fri, 30 Jan 2015 14:57:11 -0800
I am using the apache pdfbox code to generate a PDF file dynamically. I
was setting the MIME type of the response and the user was seeing an
attachment-open dialog from their browser.
The user requested that the new window have a reasonable title. Right
now, the title of the page is something like:
3.0.9.3.1.1.1.0.0
So, a few things occurred to me. I am using ERXJSOpenWindowHyperlink to
generate the page. That component inserts a window.open() JS call into
the page.
I can set the header as so:
aResponse.setHeader("attachment; filename=\"" + fileName + "\"",
"Content-Disposition");
No.
The window.open() is bypassed (somehow?) and I get the attachment
dialog again. i can remove the "attachment;" from the string above and
it does not matter. I still get the attachment dialog.
I could set the title of the resulting page in the window.open().
No.
There is no parameter for this in the open method. If I was sending it
an HTML page, I could of course set the TITLE tag. So, since I am
sending it a PDF, maybe I can do the equivalent. I see how to set the
PDF title. I can use the PDDocumentInformation setTitle(String) method.
I can either get my document's PDDocumentInformation or create one and,
in both cases, set it back into the PDDocument object. The browser
should see the title of the PDF document and use that as the title of
the browser window.
No.
Then I had a thunk. There is a JS window.setName() method. So, change
the ERXJSOpenWindowHyperlink class to add that to the JS fragment. It
puts in and set the name.
No.
First, the name of the window is still "3.0.9.3.1.1.1.0.0". Also,
instead of getting a new window with the PDF and seeing the old page
left alone, now I see a new window with the PDF _and_ the main window
content gets replaced with the PDF. So now I have two copies of the PDF
open and the original page is not visible. Yes, the user can press the
browser back button but they do not want to do that. For one thing,
they sometimes get form-resubmission alerts and it scares them.
Unnecessarily, but there it is. Maybe the setName() should be before
the win.focus() call in the fragment? No. No change.
Any ideas? :-) I do love a puzzle.
The title is obviously coming from the URL of the page being opened. But
there is no way to change that, is there? I could do a Direct Action just
to get the URL to be the right thing. Wow. That would be obnoxious. And I
could not include the date and time in the title. Unless I dynamically add
a method to the DirectAction class. Um. Just kidding.
- ray
FYI,the <A> tag produced by the ERXJSOpenWindowHyperlink class looks
like this:
<a onclick="javascript:win=window.open('/cgi-bin/WebObjects/FarmLogixConsole.woa/wo AbuqmzEtJsTtUfgDDZayO0/3.0.9.3.1.1.1.0.0','null','width=null,height=null,location=no,scrollbars=null,menubar=null,toolbar=null,titlebar=null,resizable=null,dependant=yes'); win.focus(); return false;" href="/cgi-bin/WebObjects/FarmLogixConsole.woa/wo/AbuqmzEtJsTtUfgDDZayO0/3.0.9.3.1.1.1.0.0">Invoice</a>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden