on 04-12-2007 6:46 AM
Hi all,
I have webdynpro application with data in context elements. Now, i would like to display context data/results in pdf document on click of a button in webdynpro application. I don't want to use Interactive Forms.
Please let me know how to proceed and accomplish this task.
Thank you,
Prasad
Hi,
we used the following code to display pdf in a new window (NW 2004):
final IWDCachedWebResource resource =
WDWebResource.getWebResource(
wdContext.currentContextElement().getPdfSource(),
WDWebResourceType.PDF);
try {
final IWDWindow window =
wdComponentAPI.getWindowManager().createExternalWindow(
resource.getAbsoluteURL(),"Window title",false);
window.open();
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(
e.getMessage(),false);
}
You have to be aware that the code above uses deprecated methods though. In a future version of NW 2004s those methods may not be avalaible anymore.
regards
Dirk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dirk,
Thank you for your response.
I used the code that you have sent to me.
Still it opens a new window but pdf and pdf content doesn't displays.
Do I pass right parameters in bytes? Do I need to make any changes to display PDF in a new window along with content.
Please let me know where am I doing mistake? Thank you for your co-operation.
Prasad
You can use the following code to display your pdf from a WebDynpro:
byte pdf[] = ...
final IWDResource resource = WDResourceFactory.createResource(
pdf, "",WDWebResourceType.PDF);
final IWDWindow window =wdComponentAPI.getWindowManager()
.createNonModalExternalWindow(
resource.getUrl(
WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()), "");
window.removeWindowFeature(WDWindowFeature.ADDRESS_BAR);
window.removeWindowFeature(WDWindowFeature.TOOL_BAR);
window.removeWindowFeature(WDWindowFeature.MENU_BAR);
window.removeWindowFeature(WDWindowFeature.STATUS_BAR);
window.open();
For more information have a close look at the IWDWindow- and IWDResource -API at
https://help.sap.com/javadocs/NW04S/current/wd/index.html.
regards
Dirk
PS: The code above is geared towards Netweaver 2004s. Netweaver 2004 will require the use of some deprecated features.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dirik,
I wrote the following code
try {
Document document = new Document(PageSize.A4);
PdfWriter.getInstance(document, new FileOutputStream("C:
Paragraphs.pdf"));
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell;
cell = new PdfPCell(new Paragraph("ONE"));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TWO"));
table.addCell(cell);
document.add(table);
document.close();
byte[] part = new byte[1000 * 1024];
part = document.toString().getBytes("UTF-8");
messageMgr.reportSuccess("PDF"+ part.length);
wdContext.currentContextElement().setPdfSource(part);
final IWDCachedWebResource resource =
WDWebResource.getWebResource(
wdContext.currentContextElement().getPdfSource(),
WDWebResourceType.PDF);
final IWDWindow window =
wdComponentAPI.getWindowManager().createExternalWindow(
resource.getAbsoluteURL(),"Window title",false);
window.open();
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(
e.getMessage(),false);
}
This enables me to display new window with the specified name with .pdf extension, but it doesn't display pdf and pdfcontent. It appears as normal HTML page.
Kindly suggest me for any corrections in this code.
Thanks
Prasad
Message was edited by:
Prasad Kothamasu
Message was edited by:
Prasad Kothamasu
Hi Dirk,
Thank you for the response.
I included jar file as External Library DC and able to deploy application without any errors. Now, I'm unable to display PDF with the code that I shown in my earlier posting. Please let me know any changes that I need to do for the above code to display PDF with content in a new window.
Thanks
Prasad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
you have to create a new DC of type external library and add the iText jars to this component.
Deploy it (don't forget to build it as a reference at compile time and run time). Then in your project you reference this DC.
At compile time (if you use NWDI) the above mentioned external library DC will be referenced, so that the Phrase class can be found.
regards
Dirk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Omri,
Thank you for the response.
I have gone through the link and written the following code:
try{
Document document = new Document(PageSize.A4);
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell;
cell = new PdfPCell(new Paragraph("ONE"));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TWO"));
table.addCell(cell);
document.add(table);
document.close();
byte[] b = new byte[100 * 1024];
b = document.toString().getBytes("UTF-8");
IWDCachedWebResource pdfRes = WDWebResource.getPublicCachedWebResource(b, WDWebResourceType.PDF, WDScopeType.CLIENTSESSION_SCOPE, wdThis.wdGetAPI().getComponent().getDeployableObjectPart(),"FileNameHelloText");
}catch(Exception e)
{
}
Also, included itext-2.0.1.jar in the application.
Deployed and Run the application. It displays the following message and unable to go further.
java.lang.NoClassDefFoundError: com/lowagie/text/Phrase
Verified jar file and downloaded from different places to ensure for all classes in jar file. But could not go further.
Please let me know how to display/generate PDF from the above code. Do I need to do anything else?
Thank you,
Prasad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad Kothamasu,
You can always use external libraries like <a href="http://itextdocs.lowagie.com/tutorial/#part1">this</a>
Regards,
Omri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.