import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("clipping_path.pdf"));
document.open();
Image img = Image.getInstance("dog.jpg");
float w = img.scaledWidth();
float h = img.scaledHeight();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
cb.circle(260, 700, 70);
cb.clip();
cb.newPath();
cb.addImage(img, w, 0, 0, h, 36, 620);
cb.restoreState();
document.close();
}
}
|