on 11-15-2006 9:40 AM
Hi,
I want to display a PDF file in a browser which I have generated at runtime.
I do it in this way:
HttpServletResponse response = ((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletResponse();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
File pdfFile = new File("report1.pdf");
try{
baos.write(getBytesFromFile(pdfFile));
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
}
catch(IOException ioe){
}
If I put this code to a simple project (single view with this code only) its working fine. But if I want to display the file in a project which contains other functions and views it doesnt work (when the pdf should appear the application freezes).
Can anyone help me?
Ivo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, it seems you are trying to access the HTTP response stream directly from within a Web Dynpro app. This is not allowed and will not work - Web Dynpro is a client-agnostic technology, so what happens if your user's client is Flex, for example?
Even though your PDF is not interactive, you still have to use Web Dynpro techniques as if it were interactive. In this case, it means writing your file content to a PDF object in a Web Dynpro page.
If you follow the thread from the previous poster, you can use the code posted there. It doesn't matter that your PDF is not interactive.
Cheers,
Darren
Hi Ivo,
like already mentioned above, you should never ever hijack internal Web Dynpro FPIs.
Why do you not want to use the InteractiveForm UI element to display a dynamically generated PDF resource in it. It has a special mode for exactly this use case?
Are you using NW04 or NW04s?
Regards, Bertram
Another alternative might be to use an embedded HTML control in your Web Dynpro, and then write a separate servlet program to be called with a URL you specify which will render the PDF to the browser frame you get from the HTML control.
The first thing to do is raise a customer message with SAP over the fact that the Web Dynpro PDF control won't work with Firefox. Firefox is, I think, a supported browser for Web Dynpro.
- Darren
As you see Lohita showed you this topic:
That is only the part code where i saved the PDF into server, after that i get the URL and assign it to UI linktoURL.
I created the PDF using external JAR took from http://xmlgraphics.apache.org/fop/
public int CreaFilePdf( )
{
//@@begin CreaFilePdf()
////////////////////////////
int ret = 0;
byte[] pdfFoXMLFile = null;
byte[] pdfFile;
IWDCachedWebResource cachedPdfResource = null;
String fileName = new String();
String foText = new String();
////////////////////////////
try {
foText = this.toFoXML();
wdContext.currentContextElement().setFoText(foText);
pdfFoXMLFile = foText.getBytes("UTF-8");
fileName = "Equipment.pdf";
OutputStream outFo = new java.io.FileOutputStream("Equipment.pdf.fo");
try {
outFo.write(pdfFoXMLFile);
outFo.flush();
outFo.close();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
/////////////fo to PDF
// Construct driver
Driver driver = new Driver();
//Setup logger
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
driver.setLogger(logger);
MessageHandler.setScreenLogger(logger);
//Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);
OutputStream out = new java.io.FileOutputStream("EquipmentFromFo.pdf");
try {
driver.setOutputStream(out);
//Setup input
InputStream in = new java.io.FileInputStream("Equipment.pdf.fo");
try {
driver.setInputSource(new InputSource(in));
//Process FO
driver.run();
} finally {
in.close();
}
} finally {
out.close();
}
/////////////fo to PDF
// /////////////////////////////web resource
try {
// create Excel 2003 XML data as a byte array for the given context node, attributes and headers
// Deserialize from a file
File file = new File("EquipmentFromFo.pdf");
// Get some byte array data ----> THIS method is here: <a class="jive_macro jive_macro_message" href="" __jive_macro_name="message" modifiedtitle="true" __default_attr="2735976"></a>
pdfFile = getBytesFromFile(file);
//pdfFoXMLFile = this.toFoXML().getBytes("UTF-8");
// create a cached Web Dynpro XLS Resource for the given byte array and filename
//HERE create the URL object
cachedPdfResource = this.getCachedWebResource(pdfFile, fileName, WDWebResourceType.PDF);
// Store URL and filename of cached excel resource in context for UI linkToURL.
if (cachedPdfResource != null) {
wdContext.currentContextElement().setPdfFileURL(cachedPdfResource.getURL());
wdContext.currentContextElement().setPdfFileName(cachedPdfResource.getResourceName());
} else {
ret = 1;
}
}
catch (WDURLException e) {
ret = 1;
}
// /////////////////////////////
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (FOPException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
/////////////////////////////
return ret;
//@@end
}
Hi Ivo,
Firfox is not supported for the InteractiveForm UI element on NW04. Thats a limitation. In NW04, the solution is windows specific. Every Web Dynpro HTML client must have some DLLs installed to access interactive form. This limitation does not allow the application to be accessed on any other platform or browser except Windows + IE on NW04.
In SAP NetWeaver 04s the InteractiveForm UI element is also supported in Firefox.
Read SAP Notes
- NW 04: <a href="https://service.sap.com/sap/support/notes/863893">Note 863893 - Interactive forms: Release restrictions (NetWeaver '04)</a>
- NW 04s: <a href="https://service.sap.com/sap/support/notes/894389">Note 894389 - Rel. Restr.: SAP NW 2004s - Adobe Document Services</a>
Regards, Bertram
I done it.
Now haven´t the source, try to explain in other case i show you better also with CODE tomorrow morning.
Use normal UI linkToUrl, create your PDF and save it to the server like a deployable object.
After that you can get the URL and assign this URL to the UI linkToUrl.
All this code is done at the action binded to UI linkToUrl, but URL must come from component controller.
I know isn´t easy understand me :-P, but have faith 😄 tomorrow i will show you.
Bye.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.