i am generating a report in vb.net using itextsharp. sometimes the entire report does not fit on one page and i need to know when itextsharp is adding a page to the document. is there a way to detect this?
+3
A:
As long as you're implementing the PdfPageEvent
interface, you just need to override the public void onEndPage(PdfWriter writer, Document document)
method, which is called right before a new page is started.
Edit: here's some code explaining the procedure, without knowing what you want to do if a new page is created by iTextSharp, this is the most I can give you:
Public Class YourReport
Implements PdfPageEvent
'Your report code
Public Overrides Sub onEndPage(ByVal writer as PdfWriter,
ByVal doc as Document)
'if you get here, a new page was created by iTextSharp
'so do what you need to do.
End Sub
End Class
jball
2009-12-21 17:18:56
jball how do i do that?
I__
2009-12-21 17:19:46
Overrides Sub onEndPage(ByVal writer as PdfWriter, ByVal doc as Document)
jball
2009-12-21 17:24:02
so i just put that line into the sub and it will not generate a new page?
I__
2009-12-21 17:26:39
No, it will still generate a new page, but you will detect it in the `onEndPage` and you can then react accordingly.
jball
2009-12-21 17:29:44
Just to clarify, you are implementing the `PdfPageEvent` interface at the top of your class with something like `Public Class YourReport Implements PdfPageEvent`, correct?
jball
2009-12-21 17:32:00
im sorry im a beginner, can you plainly tell me how to check if i am adding a new page, could u paste some code please in your answer
I__
2009-12-21 17:40:52
thank you very much!!!!
I__
2009-12-21 17:55:43
hey jball, how do i detect if onendpage sub was triggered?
I__
2009-12-21 18:03:46
by the way, the string onendpage was not found in the entire solution
I__
2009-12-21 18:05:06
You need to add the `onEndPage` to your class. It's part of the iTextSharp library's `PdfPageEvent` interface, so you won't find it by a string search unless you've added it.
jball
2009-12-21 18:08:41
You should put your code in the `onEndPage` override that you create. It will get hit when iTextSharp finishes writing a page.
jball
2009-12-21 18:10:25
thank you very much. i am learning a lot. the thing is i dont have a class it's just a sub, and i dont think i am able to put a sub within a sub
I__
2009-12-21 18:15:14
Error 2 Statement cannot appear within a method body. End of method assumed.
I__
2009-12-21 18:16:19
Error 3 sub 'onEndPage' cannot be declared 'Overrides' because it does not override a sub in a base class.
I__
2009-12-21 18:16:51
You should create a class just to handle your report.
jball
2009-12-21 18:16:56
i copied and pasted exactly what you told me and now im getting these errors: Error 2 Type 'PdfPageEvent' is not defined.
I__
2009-12-21 18:21:42
Error 3 sub 'onEndPage' cannot be declared 'Overrides' because it does not override a sub in a base class.
I__
2009-12-21 18:22:29
You've included the iTextSharp dll in your project references?
jball
2009-12-21 18:25:59
yes i sure have and am referncing it no problem
I__
2009-12-21 18:27:05
Then you should be able to create a class and include the code I wrote in the answer without getting an error. `PdfPageEvent` is an interface provided by the iTextSharp library, so if you're referencing the dll no problem, you'll be able to implement that interface.
jball
2009-12-21 18:30:34
by the way this doesnt work either Implements iTextSharp.text.pdf.IPdfPageEvent
I__
2009-12-21 18:32:19
please see this screenshot http://img704.imageshack.us/img704/7882/fullscreencapture122120.png
I__
2009-12-21 18:34:35
please help!!!!!!
I__
2009-12-21 18:48:02
Ensure that you have the latest version of iTextSharp http://sourceforge.net/projects/itextsharp/files/ and read the overview of page events http://itextsharp.sourceforge.net/tutorial/ch12.html - beyond that, you may have some problem in your environment that's causing the iTextSharp dll to not be included properly.
jball
2009-12-21 18:54:28
it is included properly because i am using it all over the place
I__
2009-12-21 18:57:22
jball any help please
I__
2009-12-22 04:30:53
I've given you all the advice that I have, so you should post another question about not being able to implement an interface provided by iTextSharp in VB.net. Perhaps someone else will be able to solve that for you. Once you have the interface implemented, then my answer above should work for you.
jball
2009-12-22 17:37:41