Re: [iText-questions] Page Number problem when table ends at the complete end of the page

2009-09-08 Thread 1T3XT info
suresh.chennup...@judiciary.state.nj.us wrote:
> 
> I had implemented your solution:
> 
> Sample Code in event listener:

There are two things wrong with:

> onEndPage(){

You forgot the parameters, it should be:
public void onEndPage(PdfWriter writer, Document document)

> *final* *int* page = writer.getPageNumber();
> String text = "Page " + page;
> m_BaseFont = 
> BaseFont./createFont/(BaseFont./HELVETICA/, BaseFont./CP1252/, 
> BaseFont./NOT_EMBEDDED/);
> m_Cb = writer.getDirectContent();
> *if*(m_Cb!=*null*){
> m_Cb.beginText();
> m_Cb.setFontAndSize(m_BaseFont, 8);
> 
> m_Cb.showTextAligned(PdfContentByte./ALIGN_RIGHT/,text,410,20,0);
> m_Cb.endText();

You're only adding "Page X" here, you forgot to add the template.

> }
> }


Why do you say:
> Sample code in program:

This method should be in the event class:

> createNewTemplate(PdfWriter arg0){
> m_Cb = arg0.getDirectContent();
> m_Template = m_Cb.createTemplate(85,87);

NO NEED TO ADD "Page X of Y" here!!!

> }

This method should also be in the event class:

> fillOutTemplate(PdfWriter arg0) {
> 
> System./out/.println("fillOutTemplate:"+arg0.getPageNumber());
> 
> m_Template.beginText();
> m_Template.setFontAndSize(m_BaseFont, 8);
> String text = "of " + (arg0.getPageNumber() );
> m_Template.showTextAligned(PdfContentByte./ALIGN_LEFT/, 
> text, 65, 0, 0);
> m_Template.endText();
> }

This is your actual class:

event.createNewTemplate(writer);
> document.add(employeesTable);
event.fillOutTemplate(writer);

> When this code is executed, it displays page 1 of X in first page, but 
> page 2 , page 3 in rest of the pages.
> When a new table starts it displays againg page 1 of Y, followed by page 
> 2 and page 3.

Reading your code, that's exactly the behavior I'd expect.

> Please let me know, why template is not filled out at end of every page?

Because you didn't grasp the concept I was trying to explain: 
createNewTemplate and fillOutTemplate should be methods that are part of 
the event. m_Template needs to be used on the onEndPage method!

> Do i need to use, onChapter & onChapterEnd to fill the template?

Please stop talking about onChapter and onChapterEnd!
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/


Re: [iText-questions] Page Number problem when table ends at the complete end of the page

2009-09-08 Thread suresh . chennupati
I had implemented your solution:

Sample Code in event listener:

onEndPage(){
final int page = writer.getPageNumber();
String text = "Page " + page;
m_BaseFont = BaseFont.createFont(BaseFont.
HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
m_Cb = writer.getDirectContent();
if(m_Cb!=null){
m_Cb.beginText();
m_Cb.setFontAndSize(m_BaseFont, 8);
m_Cb.showTextAligned(PdfContentByte.
ALIGN_RIGHT,text,410,20,0);
m_Cb.endText();
}
}

Sample code in program:

createNewTemplate(PdfWriter arg0){
try {
m_BaseFont = BaseFont.createFont(BaseFont.
HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
m_Cb = arg0.getDirectContent();
m_Template = m_Cb.createTemplate(85,87);
final int page = arg0.getPageNumber();
String text = "Page " + page;

if(m_Cb!=null){
m_Cb.beginText();
m_Cb.setFontAndSize(m_BaseFont, 8);
m_Cb.showTextAligned(PdfContentByte.
ALIGN_RIGHT,text,410,20,0);
m_Cb.endText();
m_Cb.addTemplate(m_Template, 352.3f, 20);
}
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}
fillOutTemplate(PdfWriter arg0) {
System.out.println("fillOutTemplate:"
+arg0.getPageNumber());

m_Template.beginText();
m_Template.setFontAndSize(m_BaseFont, 8);
String text = "of " + (arg0.getPageNumber() );
m_Template.showTextAligned(PdfContentByte.ALIGN_LEFT, 
text, 65, 0, 0);
m_Template.endText();
}



this.createNewTemplate(writer);
document.add(employeesTable);
this.fillOutTemplate(writer);

When this code is executed, it displays page 1 of X in first page, but 
page 2 , page 3 in rest of the pages.
When a new table starts it displays againg page 1 of Y, followed by page 2 
and page 3.

Please let me know, why template is not filled out at end of every page?
Do i need to use, onChapter & onChapterEnd to fill the template?

Thanks,
Suresh






1T3XT info  
09/04/2009 12:14 PM
Please respond to
Post all your questions about iText here 



To
Post all your questions about iText here 

cc

Subject
Re: [iText-questions] Page Number problem when table ends at the complete 
end of the page






chennupati wrote:
> I am using ChapterAutoNumber,

Why? It adds complexity to your app,
and it makes your app error prone.

Don't use Chapters, but use document.newPage() every time
you've added a table.

Remove:
> public void onChapter(PdfWriter arg0, Document arg1, float arg2,
>Paragraph arg3) {

> public void onChapterEnd(PdfWriter arg0, Document arg1, float arg2) {

Replace them with normal methods, such as:

public void createNewTemplate()
and
public void fillOutTemplate()

(Or whichever name you think describes best what the method does.)

Call these methods before and after document.newPage().
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 
30-Day 
trial. Simplify your report design, integration and deployment - and focus 
on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: 
http://1t3xt.info/tutorials/keywords/

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

Re: [iText-questions] Page Number problem when table ends at the complete end of the page

2009-09-04 Thread 1T3XT info
chennupati wrote:
> I am using ChapterAutoNumber,

Why? It adds complexity to your app,
and it makes your app error prone.

Don't use Chapters, but use document.newPage() every time
you've added a table.

Remove:
> public void onChapter(PdfWriter arg0, Document arg1, float arg2,
>   Paragraph arg3) {

> public void onChapterEnd(PdfWriter arg0, Document arg1, float arg2) {

Replace them with normal methods, such as:

public void createNewTemplate()
and
public void fillOutTemplate()

(Or whichever name you think describes best what the method does.)

Call these methods before and after document.newPage().
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/


[iText-questions] Page Number problem when table ends at the complete end of the page

2009-09-03 Thread chennupati

I am trying to display mutiple tables in a single PDF and display page X of Y
at the end of each page.
X, Y should reset for every new table(Basically every new table should start
with a new page.)
Each table can vary and span accross multiple pages.I am ChapterAutoNumber,
PdfPTable & custome event handler.
I don't have problem while tables end in the middle of page(1 page of
multiple pages).
The problem comes when the table size matches page size. 

If a table size is approximately equal to page size.
Then onStartPage of new page(second) is invoked before onChapterEnds and
onEndPage are invoked.
So it displays page 1 of 2, when it has only one page.

For tables ending in the middle of page, if it has 3 pages, page numbers are
displayed correctly as 
1 of 3 , 2 of 3 , 3 of 3. But when table size ends at the end of page, if
there is 1 page, it display 1 of 2.


Code looks like below:

public void onChapter(PdfWriter arg0, Document arg1, float arg2,
Paragraph arg3) {

try {
m_BaseFont = BaseFont.createFont(BaseFont.HELVETICA, 
BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
m_Cb = arg0.getDirectContent();
m_Template = m_Cb.createTemplate(85,140);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void onChapterEnd(PdfWriter arg0, Document arg1, float arg2) {
m_Template.beginText();
m_Template.setFontAndSize(m_BaseFont, 8);
String text = "of " + (arg0.getPageNumber() );
m_Template.showTextAligned(PdfContentByte.ALIGN_LEFT, text, 65, 
0, 0);
m_Template.endText();

}

public void onEndPage(PdfWriter writer, Document arg1) {

final int page = writer.getPageNumber();
String text = "Page " + page;

if(m_Cb!=null){
m_Cb.beginText();
m_Cb.setFontAndSize(m_BaseFont, 8);

m_Cb.showTextAligned(PdfContentByte.ALIGN_RIGHT,text,410,20,0);
m_Cb.endText();
m_Cb.addTemplate(m_Template, 352.3f, 20);
}

}

Please help. 
-- 
View this message in context: 
http://www.nabble.com/Page-Number-problem-when-table-ends-at-the-complete-end-of-the-page-tp25283855p25283855.html
Sent from the iText - General mailing list archive at Nabble.com.


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/