Java/PDF RTF/Line

Материал из Java эксперт
Версия от 06:00, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Drawing Lines using PdfContentByte

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class DrawLineUsingPdfContentBytePDF {
  public static void main(String[] args) throws Exception{
      Rectangle pageSize = new Rectangle(780, 525);
      Document document = new Document(pageSize);
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("DrawLineUsingPdfContentBytePDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 24);
      cb.moveTo(370, 0);
      cb.lineTo(370, 525);
      cb.moveTo(410, 525);
      cb.lineTo(410, 0);
      cb.stroke();
      document.close();
  }
}





Draw Line Cap

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class DrawLineCapPDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter
          .getInstance(document, new FileOutputStream("DrawLineCapPDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate template = cb.createTemplate(500, 200);
      template.setLineCap(1);
      template.setLineWidth(12f);
      template.arc(15f, 75f, 25f, 85f, 0f, 160f);
      template.stroke();
      template.setLineWidth(12f);
      cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}





Shape: DashLine

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class ShapeDashLinePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ShapeDashLinePDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      cb.setLineWidth(10f);
      cb.setLineDash(3, 3, 0);
      cb.moveTo(100, 700);
      cb.lineTo(200, 800);
      cb.stroke();
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}





Shape: Line

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class ShapeLinePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ShapeLinePDF.pdf"));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      cb.setLineWidth(10f);
      cb.moveTo(100, 700);
      cb.lineTo(200, 800);
      cb.stroke();
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}