Java/PDF RTF/Image Position
Содержание
Image Absolute Positions
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
public class ImageAbsolutePositionsPDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImageAbsolutePositionsPDF.pdf"));
document.open();
Image png = Image.getInstance("logo.png");
png.setAbsolutePosition(170, 250);
document.add(png);
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Image Alignment in PDF document
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
public class ImageAlignmentPDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImageAlignmentPDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.RIGHT);
Image imageCenter = Image.getInstance("logo.png");
imageCenter.setAlignment(Image.MIDDLE);
Image imageLeft = Image.getInstance("logo.png");
imageLeft.setAlignment(Image.LEFT);
document.add(imageRight);
document.add(imageCenter);
document.add(imageLeft);
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Images Alignment with Text
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class ImagesAlignmentWithTextPDF {
public static void main(java.lang.String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImagesAlignmentWithTextPDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.RIGHT|Image.TEXTWRAP);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
document.add(imageRight);
for (int i = 0; i < 150; i++) {
document.add(new Phrase("Text "));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Images Default WRAP
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class ImagesDefaultWRAPPDF {
public static void main(java.lang.String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImagesDefaultWRAPPDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.LEFT);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
document.add(imageRight);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Images: Default WRAP In a New Line
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class ImagesDefaultWRAPInANewLinePDF {
public static void main(java.lang.String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImagesDefaultWRAPInANewLinePDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.LEFT);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
document.add(Chunk.NEWLINE);
document.add(imageRight);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Image Sequence Demo
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class ImageSequencePDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImageSequencePDF.pdf"));
document.open();
Image image = Image.getInstance("logo.png");
for(int i=0;i<20;i++){
document.add(image);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Images: TEXTWRAP
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class ImagesTEXTWRAPPDF {
public static void main(java.lang.String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImagesTEXTWRAPPDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.TEXTWRAP);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
document.add(imageRight);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Images: UNDERLYING
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class ImagesUNDERLYINGPDF {
public static void main(java.lang.String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("ImagesUNDERLYINGPDF.pdf"));
document.open();
Image imageRight = Image.getInstance("logo.png");
imageRight.setAlignment(Image.UNDERLYING);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
document.add(imageRight);
for (int i = 0; i < 100; i++) {
document.add(new Phrase("Text "));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Strict Image Sequence
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class StrictImageSequencePDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("StrictImageSequencePDF.pdf"));
writer.setStrictImageSequence(true);
document.open();
Image image = Image.getInstance("logo.png");
for(int i=0;i<20;i++){
document.add(image);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}