|
Hi Paulo,
code below sets the table to the right
y-position however its not right aligned or can it span more than the one
page.
***** code ******
import java.awt.Color; import
java.io.*;
import com.lowagie.text.*; import
com.lowagie.text.pdf.*;
public class Chap0907 {
public static void main(String[] args) {
System.out.println("Chapter 9 example 7: Barcodes without ttf");
Document
document = new Document(PageSize.A4, 50, 50, 50, 50);
try
{
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("/NTFSAREA/SupportedBarcodes2.pdf"));
PdfPTable table = new
PdfPTable(2);
//table.setWidthPercentage(100);
table.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.setTotalWidth(100);
document.open();
BaseFont
bf1 = BaseFont.createFont ( "/java/ttf/arial.ttf" , BaseFont.WINANSI ,
BaseFont.EMBEDDED )
; BaseFont
bf = BaseFont.createFont("/java/ttf/arial.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
BaseFont bf2 = BaseFont.createFont("/java/ttf/arialbd.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
//BaseFont bf3 = BaseFont.createFont("/java/ttf/FourState.TTF",
BaseFont.WINANSI,
BaseFont.EMBEDDED);
BaseFont bf4 = BaseFont.createFont("/java/ttf/CODE39.TTF", BaseFont.WINANSI,
BaseFont.EMBEDDED);
PdfContentByte cb = writer.getDirectContent();
Barcode39 code39 = new
Barcode39();
code39.setCode("CODE39-1234567890");
code39.setStartStopText(false);
Image image39 = code39.createImageWithBarcode(cb, null,
null);
image39.scaleToFit(125,80);
image39.setRotationDegrees(90);
Barcode39 code39ext = new Barcode39();
code39ext.setCode("The
willows.");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
Image image39ext = code39ext.createImageWithBarcode(cb, null,
null);
Barcode128 code128 = new
Barcode128();
code128.setCode("1Z234786
hello");
Image image128 = code128.createImageWithBarcode(cb, null,
null);
BarcodeEAN codeEAN = new
BarcodeEAN();
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null,
null);
BarcodeInter25 code25 = new
BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
Image image25 = code25.createImageWithBarcode(cb, null,
null);
BarcodePostnet codePost = new
BarcodePostnet();
codePost.setCode("12345");
Image imagePost = codePost.createImageWithBarcode(cb, null,
null);
BarcodePostnet codePlanet = new
BarcodePostnet();
codePlanet.setCode("50201402356");
codePlanet.setCodeType(Barcode.PLANET);
Image imagePlanet = codePlanet.createImageWithBarcode(cb, null,
null);
PdfTemplate tp = cb.createTemplate(0,
0);
PdfTemplate ean = codeEAN.createTemplateWithBarcode(cb, null,
Color.blue);
BarcodeEAN codeSUPP = new
BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("54995");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN,
codeSUPP);
Image imageEANSUPP = eanSupp.createImageWithBarcode(cb, null, Color.blue);
//table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
//table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
//table.getDefaultCell().setFixedHeight(130);
table.addCell("CODE
39");
table.addCell(new Phrase(new Chunk(image39, 0,
0)));
table.addCell("CODE 39
EXTENDED");
table.addCell(new Phrase(new Chunk(image39ext, 0,
0)));
table.addCell("CODE
128");
table.addCell(new Phrase(new Chunk(image128, 0,
0)));
table.addCell("CODE
EAN");
table.addCell(new Phrase(new Chunk(imageEAN, 0,
0)));
table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL
5");
table.addCell(new Phrase(new Chunk(imageEANSUPP, 0,
0)));
table.addCell("CODE
INTERLEAVED");
table.addCell(new Phrase(new Chunk(image25, 0,
0)));
table.addCell("CODE
POSTNET");
table.addCell(new Phrase(new Chunk(imagePost, 0,
0)));
table.addCell("CODE
PLANET");
table.addCell(new Phrase(new Chunk(imagePlanet, 0, 0)));
table.addCell("CODE
39");
table.addCell(new Phrase(new Chunk(image39, 0,
0)));
table.addCell("CODE 39
EXTENDED");
table.addCell(new Phrase(new Chunk(image39ext, 0,
0)));
table.addCell("CODE
128");
table.addCell(new Phrase(new Chunk(image128, 0,
0)));
table.addCell("CODE
EAN");
table.addCell(new Phrase(new Chunk(imageEAN, 0,
0)));
table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL
5");
table.addCell(new Phrase(new Chunk(imageEANSUPP, 0,
0)));
table.addCell("CODE
INTERLEAVED");
table.addCell(new Phrase(new Chunk(image25, 0,
0)));
table.addCell("CODE
POSTNET");
table.addCell(new Phrase(new Chunk(imagePost, 0,
0)));
table.addCell("CODE
PLANET");
table.addCell(new Phrase(new Chunk(imagePlanet, 0, 0)));
table.setTotalWidth(300);
table.writeSelectedRows(0, -1, 100, 300,
writer.getDirectContent());
//document.add(table);
} catch (Exception de)
{
de.printStackTrace(); }
// step 5: we close the
document
document.close(); } }
**** code ****
because we don't use "document.add(table);" we can not span more than one
page however the position of the table doesn't work if we don't use
writeSelectedRows. What I want is the ability to set the initial position of the
table on the first page and have the option of spaning more than one page how
can I do this ?
Kind Regards,
George Shafik
----- Original Message -----
Sent: Monday, September 06, 2004 9:21
PM
Subject: RE: [iText-questions] PdfPTable
absolute position multiple spaning page example
Why do you have the
writeSelectedRows() and document.add(table)? Choose one or the other. If you
choose the former you must set the width with setTotalWidth() and the width
percentage is ignored..
Best Regards,
Paulo Soares
Hi Paulo,
please fix code below as I getting an exception
"table with must be greater than zero" - remember that the problem is
aligning the table right, having start say half way down the page and span
more than one page.
******************************************************************************************************************************************
import java.awt.Color; import
java.io.*;
import com.lowagie.text.*; import
com.lowagie.text.pdf.*;
public class Chap0907 {
public static void main(String[] args) {
System.out.println("Chapter 9 example 7: Barcodes without
ttf");
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try
{
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(".pdf"));
PdfPTable table = new
PdfPTable(2);
table.setWidthPercentage(70);
table.setHorizontalAlignment(Element.ALIGN_RIGHT);
document.open();
PdfContentByte cb =
writer.getDirectContent();
table.writeSelectedRows(0, -1, 20, 400, cb);
BaseFont bf1 = BaseFont.createFont ( "/java/ttf/arial.ttf" ,
BaseFont.WINANSI , BaseFont.EMBEDDED ) ;
Barcode39 code39 = new
Barcode39();
code39.setCode("CODE39-1234567890");
code39.setStartStopText(false);
Image image39 = code39.createImageWithBarcode(cb, null,
null);
image39.scaleToFit(100,50);
Barcode39 code39ext = new
Barcode39();
code39ext.setCode("The
willows.");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
Image image39ext = code39ext.createImageWithBarcode(cb, null,
null);
Barcode128 code128 = new
Barcode128();
code128.setCode("1Z234786
hello");
Image image128 = code128.createImageWithBarcode(cb, null,
null);
BarcodeEAN codeEAN = new
BarcodeEAN();
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null,
null);
BarcodeInter25 code25 = new
BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
Image image25 = code25.createImageWithBarcode(cb, null,
null);
BarcodePostnet codePost = new
BarcodePostnet();
codePost.setCode("12345");
Image imagePost = codePost.createImageWithBarcode(cb, null,
null);
BarcodePostnet codePlanet = new
BarcodePostnet();
codePlanet.setCode("50201402356");
codePlanet.setCodeType(Barcode.PLANET);
Image imagePlanet = codePlanet.createImageWithBarcode(cb, null,
null);
PdfTemplate tp = cb.createTemplate(0,
0);
PdfTemplate ean = codeEAN.createTemplateWithBarcode(cb, null,
Color.blue);
BarcodeEAN codeSUPP = new
BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("54995");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN,
codeSUPP);
Image imageEANSUPP = eanSupp.createImageWithBarcode(cb, null,
Color.blue);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
table.getDefaultCell().setFixedHeight(70);
table.addCell("CODE
39");
table.addCell(new Phrase(new Chunk(image39, 0,
0)));
table.addCell("CODE 39
EXTENDED");
table.addCell(new Phrase(new Chunk(image39ext, 0,
0)));
table.addCell("CODE
128");
table.addCell(new Phrase(new Chunk(image128, 0,
0)));
table.addCell("CODE
EAN");
table.addCell(new Phrase(new Chunk(imageEAN, 0,
0)));
table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL
5");
table.addCell(new Phrase(new Chunk(imageEANSUPP, 0,
0)));
table.addCell("CODE
INTERLEAVED");
table.addCell(new Phrase(new Chunk(image25, 0,
0)));
table.addCell("CODE
POSTNET");
table.addCell(new Phrase(new Chunk(imagePost, 0,
0)));
table.addCell("CODE
PLANET");
table.addCell(new Phrase(new Chunk(imagePlanet, 0, 0)));
table.addCell("CODE
39");
table.addCell(new Phrase(new Chunk(image39, 0,
0)));
table.addCell("CODE 39
EXTENDED");
table.addCell(new Phrase(new Chunk(image39ext, 0,
0)));
table.addCell("CODE
128");
table.addCell(new Phrase(new Chunk(image128, 0,
0)));
table.addCell("CODE
EAN");
table.addCell(new Phrase(new Chunk(imageEAN, 0,
0)));
table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL
5");
table.addCell(new Phrase(new Chunk(imageEANSUPP, 0,
0)));
table.addCell("CODE
INTERLEAVED");
table.addCell(new Phrase(new Chunk(image25, 0,
0)));
table.addCell("CODE
POSTNET");
table.addCell(new Phrase(new Chunk(imagePost, 0,
0)));
table.addCell("CODE
PLANET");
table.addCell(new Phrase(new Chunk(imagePlanet, 0, 0)));
document.add(table);
} catch (Exception de)
{
de.printStackTrace();
}
//
step 5: we close the document
document.close(); } }
******************************************************************************************************************************************
code should look very familiar
Cheers,
George
----- Original Message -----
Sent: Sunday, September 05, 2004 8:29
PM
Subject: Re: [iText-questions] PdfPTable
absolute position multiple spaning page example
> I fail to see the problem but I can give you some clues: >
> - lower the top and bottom margin, see Document.setMargins(),
before opening > the doc > -
PdfPTable.setWidthPercentage() > -
PdfPTable.setHorizontalAlignment() > > Best Regards, >
Paulo Soares > > ----- Original Message ----- > From:
"George Shafik" <[EMAIL PROTECTED]> > To: "Paulo Soares" <[EMAIL PROTECTED]>; >
<[EMAIL PROTECTED]> > Sent: Saturday, September 04, 2004
12:49 > Subject: Re: [iText-questions] PdfPTable absolute position
multiple spaning > page example > > > Hi
Paulo, > > Still doesn't work - please provide a simple example
of creating a table in > the middle of the first page of a pdf (right
align), make the table width > half the size of a A4 page and have the
table span 2 pages. I've tried your > solution with all the current
versions of iText and I get the same result, > the table just appears
in the middle of the page starting at the top of the > given pdf page.
(table can have 3 columns so that you don't have to code > much)
Also I am using table event. > > This is a very critical
problem that needs a solution so any help would be > greatly
appriciated. > > Kind Regards, > George Shafik >
----- Original Message ----- > From: Paulo
Soares > To: George Shafik ; [EMAIL PROTECTED] > Sent: Monday, August 30, 2004 8:03 PM >
Subject: RE: [iText-questions] PdfPTable absolute position multiple >
spaning page example > > > Place the table at an
absolute position with > PdfPTable.writeSelectedRows(). You can do
whatever you want that way. > > Best Regards, >
Paulo Soares > > > >
---------------------------------------------------------------------------- >
From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]
On Behalf Of George > Shafik > Sent: Monday,
August 30, 2004 3:07 PM > To: [EMAIL PROTECTED] > Subject: [iText-questions] PdfPTable absolute
position multiple spaning > page example > > >
Hi All, > > I urgently
need the following sample of code. > > Using
PdfPTable with say 7 columns and enough rows to span more than 1 >
PAGE. > I need to position the PdfPTable as I
see fit on the initial page it > first appears on while also altering
the width of the PdfPTable. For example > lets say I want this
PdfPTable to appear on the middle of the second page > and its fully
LEFT aligned to the physical page where the PdfPTable is half > the
size of the physical page. For demo purposes a dummy array of data
will > do fine. > > Many many many
thanks in advance for any one who takes up the challenge! >
Also please state what version of iText.jar you are
using. > > Kind Regards, >
George Shafik > > > > >
> > > > > > > >
> > > >
------------------------------------------------------- > This SF.Net
email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise
J2EE developer tools! > Get your free copy of BEA WebLogic Workshop
8.1 today. > http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click >
_______________________________________________ > iText-questions
mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/itext-questions
|