RE: [iText-questions] SubTotals, count, ....

2002-04-02 Thread Paulo Soares

You are complicating too much, you don't need templates. Do as follows:

- read all the rows to a PdfPTable. You now have the total number of rows.
- place the table at a precise position 10 rows per page using
PdfPTable.writeSelectedRows().
- draw the text for the page using the total number of rows.

Best Regards

> -Original Message-
> From: Sergio Lopez Rodriguez [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, April 02, 2002 17:39
> To:   Bruno Lowagie
> Cc:   [EMAIL PROTECTED]
> Subject:      RE: [iText-questions] SubTotals, count, 
> 
> UFFA, READING TWICE OR THREE TIMES I REALIZED I NEED AN COURSE OF "LEARN
> IN
> 2 DAYS HOW TO MAKE QUESTIONS EASY TO UNDERSTAND" ...
> 
> My PDF has always a table with 10 rows (it could be that it's filled in
> the
> first 2 rows, and the rest are empty). So, for instance, if my PDF
> consists
> of 1 page and tha table only has 4 rows with data, the total rows printed
> it
> would be 4; if it consists of 2 pages, that's means that in the first page
> the table has all the 10 rows with data, and in the second page the table
> could have just data in one row, the first one, so altogether I have 11
> rows
> and in each page i have to print "Total number of rows:11" (Don't ask me
> why
> I have to do such a strange thing). So ...
> 
> 1. The first possible solution  'fitsPage'
> > If your data is in a table, working with fitsPage could be
> > a way to go. See example 13 in Chapter 5 of the tutorial.
> I guess it doesn't "fit" my problem as I will always have page with a
> fixed
> nmber of rows
> 
> 2. I thought in using the way is explained how to add the total number of
> pages with the GenericTagEvent
> So
>  i.-  I increase this counter in onGenericTag(...) method
> ii.-  as i have to show in each page the total of rows (similar to
> total
> number of pages) for the whole PDF I'll have to use the onCloseDocument()
> method, no?
> 
> Following the examples you give I'll have sth like
> 
>   // we override the onEndPage method
>   public void onEndPage(PdfWriter writer, Document document)
>   {
>   int pageN = writer.getPageNumber();
>   String text = "Page Number":  " + pageN + "/ ";
>   float len = bf.getWidthPoint(text, 7);
> 
>   // Rectangle for Total number of lines
>   cb.rectangle(...);
>   cb.setColorFill(...); // I set to White
>   cb.closePathFillStroke();
>   cb.setColorFill(); // I set it to Black
> 
>  // Rectangle for Number of Pages
>  cb.rectangle(...); // Different position of course ;-)
>   cb.setColorFill(..); // Again to White
>   cb.closePathFillStroke();
>   cb.setColorFill(...); // Again to Black
> 
>   cb.beginText();
>   cb.setFontAndSize(bf, 7);
>   cb.setTextMatrix(...); // In Position A
>   cb.showText(text);
>   cb.endText();
> 
>   cb.addTemplate(...);
> 
>   cb.beginText();
>   cb.setFontAndSize(bf, 7);
>   cb.setTextMatrix(...);  // In Position B
>   cb.endText();
>   }
> 
> and  I thought in a onCloseDocument like ...
> 
>   public void onCloseDocument(PdfWriter writer, Document document)
>   {
>  // Total of pages
>  template.beginText();
>   template.setFontAndSize(bf, 7);
>   template.showText(String.valueOf(writer.getPageNumber() - 1));
>   template.endText();
> 
>   // Total of rows
>   template.beginText();
>   template.setFontAndSize(bf, 7);
>   template.showText(String.valueOf(totalLines)); // The counter
>   template.endText();
>   }
> 
> it would work, but due to the the setMatrix at the end of onEndPage each
> showText i use in onCloseDocument will be related to the position
> indicated
> in the lastMatrix, won't it? I mean, i'll have in the same position the
> total number of pages and the total number of rows with data. I tried with
> a
> 
>   cb.beginText();
>   cb.setFontAndSize(bf, 7);
>   cb.setTextMatrix(...);  // In Position C
>   cb.endText();
> 
> in the onCloseDocument() between the block for total of pages and total of
> rows but no success. So, is there a way to write two texts in
> onCloseDocument in two different positions?
> 
> Uff, I hope this time managed to make a more clear question ;-)
> 
> Regards
> 
> Sergio
> 
> P.S: Hope u enjoyed Barcelona ;-)
> 
> ---
> Este

RE: [iText-questions] SubTotals, count, ....

2002-04-02 Thread Sergio Lopez Rodriguez

UFFA, READING TWICE OR THREE TIMES I REALIZED I NEED AN COURSE OF "LEARN IN
2 DAYS HOW TO MAKE QUESTIONS EASY TO UNDERSTAND" ...

My PDF has always a table with 10 rows (it could be that it's filled in the
first 2 rows, and the rest are empty). So, for instance, if my PDF consists
of 1 page and tha table only has 4 rows with data, the total rows printed it
would be 4; if it consists of 2 pages, that's means that in the first page
the table has all the 10 rows with data, and in the second page the table
could have just data in one row, the first one, so altogether I have 11 rows
and in each page i have to print "Total number of rows:11" (Don't ask me why
I have to do such a strange thing). So ...

1. The first possible solution  'fitsPage'
> If your data is in a table, working with fitsPage could be
> a way to go. See example 13 in Chapter 5 of the tutorial.
I guess it doesn't "fit" my problem as I will always have page with a fixed
nmber of rows

2. I thought in using the way is explained how to add the total number of
pages with the GenericTagEvent
So
 i.-  I increase this counter in onGenericTag(...) method
ii.-  as i have to show in each page the total of rows (similar to total
number of pages) for the whole PDF I'll have to use the onCloseDocument()
method, no?

Following the examples you give I'll have sth like

  // we override the onEndPage method
  public void onEndPage(PdfWriter writer, Document document)
  {
  int pageN = writer.getPageNumber();
  String text = "Page Number":  " + pageN + "/ ";
  float len = bf.getWidthPoint(text, 7);

  // Rectangle for Total number of lines
  cb.rectangle(...);
  cb.setColorFill(...); // I set to White
  cb.closePathFillStroke();
  cb.setColorFill(); // I set it to Black

 // Rectangle for Number of Pages
 cb.rectangle(...); // Different position of course ;-)
  cb.setColorFill(..); // Again to White
  cb.closePathFillStroke();
  cb.setColorFill(...); // Again to Black

  cb.beginText();
  cb.setFontAndSize(bf, 7);
  cb.setTextMatrix(...); // In Position A
  cb.showText(text);
  cb.endText();

  cb.addTemplate(...);

  cb.beginText();
  cb.setFontAndSize(bf, 7);
  cb.setTextMatrix(...);  // In Position B
  cb.endText();
  }

and  I thought in a onCloseDocument like ...

  public void onCloseDocument(PdfWriter writer, Document document)
  {
 // Total of pages
 template.beginText();
  template.setFontAndSize(bf, 7);
  template.showText(String.valueOf(writer.getPageNumber() - 1));
  template.endText();

  // Total of rows
  template.beginText();
  template.setFontAndSize(bf, 7);
  template.showText(String.valueOf(totalLines)); // The counter
  template.endText();
  }

it would work, but due to the the setMatrix at the end of onEndPage each
showText i use in onCloseDocument will be related to the position indicated
in the lastMatrix, won't it? I mean, i'll have in the same position the
total number of pages and the total number of rows with data. I tried with a

  cb.beginText();
  cb.setFontAndSize(bf, 7);
  cb.setTextMatrix(...);  // In Position C
  cb.endText();

in the onCloseDocument() between the block for total of pages and total of
rows but no success. So, is there a way to write two texts in
onCloseDocument in two different positions?

Uff, I hope this time managed to make a more clear question ;-)

Regards

Sergio

P.S: Hope u enjoyed Barcelona ;-)

---
Este mensaje y los documentos, que en su caso, lleve anexos, pueden
contener informacion confidencial y ataƱe exclusivamente a las personas
a las que va dirigido. Cualquier opinion en el contenida, es exclusiva de
su autor y no representa necesariamente la opinion de AZERTIA.
Si usted no es el destinatario de este mensaje, considerese advertido de
que lo ha recibido por error y que cualquier uso, difusion o copia estan
prohibidos legalmente. Si ha recibido este mensaje por error, le rogamos
que nos lo comunique por la misma via o al telefono 93 207 55 11 y proceda
a destruirlo inmediatamente.  

This email is confidential and intended solely for the use of the individual
to whom it is addressed. Any views or opinions presented are solely those
of the author and do not necessarily represent those of AZERTIA.
If you are not the intended recipient, be advised that you have received
this email in error and that any use, dissemination, forwarding, printing,
or copying of this email is strictly prohibited.
If you have received this email in error please notify it to AZERTIA
by telephone on number +34 93 207 55 11.
---

___
iText-questio

RE: [iText-questions] SubTotals, count, ....

2002-03-27 Thread Bruno Lowagie

Quoting Sergio Lopez Rodriguez <[EMAIL PROTECTED]>:

> > Isn't it simpler to
> > keep a counter in your loop that adds the different items
> > and add the results when the loop is finished?
> I THOUGHT IT IN THE SAME WAY, BUT FOR THE MOMENT, I THINK IT'S STUPID, I
> HAVE TO SHOW THE TOTAL OF PRINTED ROWS IN EACH PAGE!!! (LIKE THE TOTAL OF
> PAGES...).

Aha, you didn't say this before!

If your data is in a table, working with fitsPage could be
a way to go. See example 13 in Chapter 5 of the tutorial.
(But you'll have to use the fitsPage method that
not only takes a table, but also a margin.)

> > Why would you let a Servlet extend PdfPageHelper?
> > I don't understand the way you think.
> > No Servlet can ever extend PdfPageEventHelper (why should it
> > have to?).
> WELL, THE IDEA IT WAS TO REDUCE THE NUMBER OF CLASSES

This is not a very Object Oriented way of working.

> IF I WERE ABLE TO "EXTEND" OR IMPLEMENT
> EVENTS IN SOME WAY IT WOULD BE EASIER TO PASS SUBTOTAL, AVERAGE,.
> I WAS THINKING THE SUBTOTALS IN THE SAME WAY AS "NUMBER TOTAL OF PAGES"

But where would you trigger those Events?
You would have to change iText internally.
No, this is not an option.

To meet your needs a 'GenericTagEvent' is added.
You could pass a String (for instance "1;1.500") as a
generic tag. This String can be parsed in the EventHandler:
add 1.500 to the counter of column 1.

See example 9 of Chapter 2 for an example on generic tags.

So now you have a 'luxoury problem', instead of no solution,
you can chose between two solutions:

1. you put all your data in a table and keep track of
   all sums. As soon as the table doesn't fit the page,
   you delete the last row of data (and change the sums
   accordingly) and you add a row with the sums to the
   table before you add it to the document.
   You start with a new table on the next page.

2. you let the Event class handle all calculations.
   You pass all values with a generic tag and onPageEnd
   you put the sums at absolute positions on every page.

kind regards,
Bruno

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



Re: [iText-questions] SubTotals, count, ....

2002-03-27 Thread Bruno Lowagie

Quoting Sergio Lopez Rodriguez <[EMAIL PROTECTED]>:

> I need to add subtotals, count and other kind of group functions to a
> report. I think i must use Events, mustn't I? 

Why? What do you want to achieve?
Also keep in mind that iText is not like EXCEL.
How do you expect to pass the different values that need
to be calculated to the Event class? Isn't it simpler to
keep a counter in your loop that adds the different items
and add the results when the loop is finished?

> To create the PDF I'm using servlets that extends from a specific Servlet,
> let's say I have
>  
>   CarServlet extends OtherServlet
>  
> OtherServlet it's predefinined so I can't change its definition. First of
> all CarServlet can't extend PdfPageEventHelper, and I don't want CarServlet
> implementing PdfPageEvent because I will only need to use just
> onCloseDocument (total of pages and i guess subtotal,), onEndPage,
> onOpenDocument.

Why would you let a Servlet extend PdfPageHelper?
I don't understand the way you think.
No Servlet can ever extend PdfPageEventHelper (why should it
have to?).

Normally you create a seperate class MyHelper that extends
PdfPageHelper and in that class you define the behaviour of
your events. You use an instance of this class in the setEvent
method. It's as simple as that...

___
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions