本文整理匯總了Java中com.lowagie.text.pdf.Barcode類的典型用法代碼示例。如果您正苦於以下問題:Java Barcode類的具體用法?Java Barcode怎麽用?Java Barcode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Barcode類屬於com.lowagie.text.pdf包,在下文中一共展示了Barcode類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.lowagie.text.pdf.Barcode; //導入依賴的package包/類
/**
* Generates a StudentCard
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("StudentCard");
// step 1: creation of a document-object
Rectangle rect = new Rectangle(243, 153);
rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
Document document = new Document(rect, 10, 10, 10, 10);
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "studentcard.pdf"));
// step 3: we open the document
document.open();
// step 4:
Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
Paragraph p = new Paragraph("Ghent University", font);
p.setAlignment(Element.ALIGN_CENTER);
document.add(p);
PdfContentByte cb = writer.getDirectContent();
Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
PdfPTable outertable = new PdfPTable(3);
outertable.setTotalWidth(200);
outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
float[] outer = { 60, 25, 15 };
outertable.setWidths(outer);
PdfPTable innertable = new PdfPTable(2);
float[] inner = { 35, 65 };
innertable.setWidths(inner);
innertable.addCell(new Paragraph("name:", f));
innertable.addCell(new Paragraph("Bruno Lowagie", f));
innertable.addCell(new Paragraph("date of birth:", f));
innertable.addCell(new Paragraph("June 10th, 1970", f));
innertable.addCell(new Paragraph("Study Program:", f));
innertable.addCell(new Paragraph("master in civil engineering", f));
innertable.addCell(new Paragraph("option:", f));
innertable.addCell(new Paragraph("architecture", f));
outertable.addCell(innertable);
outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
// outertable.addCell(Image.getInstance("bruno.jpg"));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(PdfTestRunner.getActivity().getResources(), R.drawable.bruno);
bitmap.compress(Bitmap.CompressFormat.JPEG /* FileType */,
100 /* Ratio */, stream);
Image img = Image.getInstance(stream.toByteArray());
outertable.addCell(img);
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("8010012529736");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
imageEAN.setRotationDegrees(90);
outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
outertable.addCell(imageEAN);
outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
示例2: main
import com.lowagie.text.pdf.Barcode; //導入依賴的package包/類
/**
* Generates a StudentCard
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle rect = new Rectangle(243, 153);
rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
Document document = new Document(rect, 10, 10, 10, 10);
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf"));
// step 3: we open the document
document.open();
// step 4:
Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
Paragraph p = new Paragraph("Ghent University", font);
p.setAlignment(Element.ALIGN_CENTER);
document.add(p);
PdfContentByte cb = writer.getDirectContent();
Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
PdfPTable outertable = new PdfPTable(3);
outertable.setTotalWidth(200);
outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
float[] outer = { 60, 25, 15 };
outertable.setWidths(outer);
PdfPTable innertable = new PdfPTable(2);
float[] inner = { 35, 65 };
innertable.setWidths(inner);
innertable.addCell(new Paragraph("name:", f));
innertable.addCell(new Paragraph("Bruno Lowagie", f));
innertable.addCell(new Paragraph("date of birth:", f));
innertable.addCell(new Paragraph("June 10th, 1970", f));
innertable.addCell(new Paragraph("Study Program:", f));
innertable.addCell(new Paragraph("master in civil engineering", f));
innertable.addCell(new Paragraph("option:", f));
innertable.addCell(new Paragraph("architecture", f));
outertable.addCell(innertable);
outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("8010012529736");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
imageEAN.setRotationDegrees(90);
outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
outertable.addCell(imageEAN);
outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());
// step 5: we close the document
document.close();
}
示例3: main
import com.lowagie.text.pdf.Barcode; //導入依賴的package包/類
/**
* List with different Barcode types.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("barcodes.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content to the document
PdfContentByte cb = writer.getDirectContent();
Barcode39 code39 = new Barcode39();
code39.setCode("CODE39-1234567890");
code39.setStartStopText(false);
Image image39 = code39.createImageWithBarcode(cb, null, null);
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);
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);
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
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)));
document.add(table);
// step 5: we close the document
document.close();
}