cancel
Showing results for 
Search instead for 
Did you mean: 

Creating PDF using ITEXT API's - error

Former Member
0 Kudos

Hi,

In my WebDynpro Application I want to generate a PDF (using ITEXT API's) out of the data retrieved from back end system .

I used this source code.

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"));

I have used Window Manager to create a external window with the URL from pdfRes.getUrl() method.

After execution i get a pop up window with out PDF document.

Please let me know your thoughts & solutions to the above mentioned problem.

Thanks

Senthil

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Folks,

Use the following snippet of the code to generate PDF using ITEXT API.

Document document = new Document(PageSize.A4);

ByteArrayOutputStream bos = new ByteArrayOutputStream();

PdfWriter.getInstance(document, bos);

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 [] byteContent = bos.toByteArray();

IWDCachedWebResource cachedResource =

WDWebResource.getPublicCachedWebResource(

byteContent,

WDWebResourceType.PDF,

WDScopeType.CLIENTSESSION_SCOPE,

wdThis

.wdGetAPI()

.getComponent()

.getDeployableObjectPart(),

"TestPDF");

IWDWindow externalWindow =

wdComponentAPI

.getWindowManager()

.createExternalWindow(cachedResource.getURL(), "PDF Window",true);

externalWindow.open();

// .....

Thanks and Regards,

Gopi

Former Member
0 Kudos

Hi,

There was some issues related to URL generation. I fixed it. It works now.

Thanks

Senthil

Former Member
0 Kudos

Hi Senthil,

I'm working on the same application to generate PDF. I'm also stuck up at this point. When I write the same code that you have used, it displays application in new window without a PDF document.

You said you have URL issue and it is fixed to resolve issue.

can you kindly share what was the issue and how to resolve it? I'm also at the same point to create PDF.

Your response will be great help.

Thank you

Prasad

kai_mattern2
Explorer
0 Kudos

Take a look into this Thread maybe it helps you