Java/PDF RTF/Barcode — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 06:00, 1 июня 2010

Barcode 128

import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class Barcode128Demo {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcode128.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      String code402 = "123456789012345" + Barcode128.FNC1;
      String code90 = "www.jexp.ru" + Barcode128.FNC1;
      String code421 = "123456";
      String data = code402 + code90 + code421;
      Barcode128 shipBarCode = new Barcode128();
      shipBarCode.setX(0.75f);
      shipBarCode.setN(1.5f);
      shipBarCode.setChecksumText(true);
      shipBarCode.setGenerateChecksum(true);
      shipBarCode.setSize(10f);
      shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
      shipBarCode.setBaseline(10f);
      shipBarCode.setCode(data);
      shipBarCode.setBarHeight(50f);
      Image imgShipBarCode = shipBarCode.createImageWithBarcode(cb, Color.black, Color.blue);
      document.add(imgShipBarCode);
    } catch (Exception e) {
      e.printStackTrace();
    }
    document.close();
  }
}





BarcodeEAN: SUPP5

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesSUPP5 {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesSUPP5.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodeEAN codeSUPP = new BarcodeEAN();
            codeSUPP.setCodeType(Barcode.SUPP5);
            codeSUPP.setCode("12345");
            codeSUPP.setBaseline(-2);
            Image imagePost = codeSUPP.createImageWithBarcode(cb, null, null);
            
            document.add(new Phrase(new Chunk(imagePost, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





BarcodePostnet

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodePostnet;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesPLANET {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesPLANET.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodePostnet codePlanet = new BarcodePostnet();
            codePlanet.setCode("50201402356");
            codePlanet.setCodeType(Barcode.PLANET);
            Image imagePlanet = codePlanet.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(imagePlanet, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





Barcodes 128 (2)

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class Barcodes128 {
  public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcodes128.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      Barcode128 code128 = new Barcode128();
      code128.setCode("www.jexp.ru");
      Image image128 = code128.createImageWithBarcode(cb, null, null);
      document.add(new Phrase(new Chunk(image128, 0, 0)));
    } catch (Exception de) {
      de.printStackTrace();
    }
    document.close();
  }
}





Barcodes 39

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class Barcodes39 {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcodes39.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            Barcode39 code39 = new Barcode39();
            code39.setCode("CODE39-1234567890");
            code39.setStartStopText(false);
            Image image39 = code39.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(image39, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





Barcodes 39 Ext

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class Barcodes39Ext {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcodes39Ext.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            Barcode39 code39 = new Barcode39();
            code39.setCode("www.jexp.ru");
            code39.setStartStopText(false);
            code39.setExtended(true);
            Image image39 = code39.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(image39, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





BarcodesEAN 13

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesEAN13 {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesEAN13.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodeEAN codeEAN = new BarcodeEAN();
            codeEAN.setCodeType(Barcode.EAN13);
            codeEAN.setCode("1234567812345");
            Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(imageEAN, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





BarcodesEAN SUPP

import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.BarcodeEANSUPP;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesEANSUPP {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesEANSUPP.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodeEAN codeEAN = new BarcodeEAN();
            codeEAN.setCodeType(Barcode.EAN13);
            codeEAN.setCode("9780123412344");
            BarcodeEAN codeSUPP = new BarcodeEAN();
            codeSUPP.setCodeType(Barcode.SUPP5);
            codeSUPP.setCode("12345");
            codeSUPP.setBaseline(-2);
            BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
            Image imageEANSUPP = eanSupp.createImageWithBarcode(cb, null, Color.blue);
            document.add(new Phrase(new Chunk(imageEANSUPP, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





BarcodesInter25

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BarcodeInter25;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesInter25 {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesInter25.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodeInter25 code25 = new BarcodeInter25();
            code25.setGenerateChecksum(true);
            code25.setCode("99-1234567890-001");
            Image image25 = code25.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(image25, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





BarcodesPostnet 2

import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BarcodePostnet;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class BarcodesPostnet {
  public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("BarcodesPostnet.pdf"));
            document.open();
            PdfContentByte cb = writer.getDirectContent();
            
            BarcodePostnet codePost = new BarcodePostnet();
            codePost.setCode("123451234");
            Image imagePost = codePost.createImageWithBarcode(cb, null, null);
            document.add(new Phrase(new Chunk(imagePost, 0, 0)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        document.close();
  }
}





Example BarcodePDF417

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.BarcodePDF417;
import com.lowagie.text.pdf.PdfWriter;
public class ExampleBarcodePDF417 {
  public static void main(String[] args) {
        try {
            BarcodePDF417 pdf417 = new BarcodePDF417();
            pdf417.setText("www.jexp.ru has some demo for PDF");
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ExampleBarcodePDF417.pdf"));
            document.open();
            Image img = pdf417.getImage();
            img.scalePercent(50, 50 * pdf417.getYHeight());
            document.add(img);
            document.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
  }
}