利用itext往pdf追加图片

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.PdfReader;
import com.lowagie.text.pdf.PdfStamper;


public class PdfTest {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
PdfReader reader = new PdfReader("C:\\1.pdf");
  int n = reader.getNumberOfPages();
  Document document = new Document(reader.getPageSize(n));
  float width = document.getPageSize().width();
  // Create a stamper that will copy the document to a new file
  PdfStamper stamp = new PdfStamper(reader, 
    new FileOutputStream("c:\\text1.pdf"));
  PdfContentByte over;
  Image img = Image.getInstance("c:\\view.png");
  width = width - img.width();
  System.out.println("width:" + width);
  img.setAbsolutePosition(width, 0);
  img.setAlignment(Image.ALIGN_RIGHT);
  if(n > 0)
  {
    // Text over the existing page
    over = stamp.getOverContent(n);
    over.addImage(img);
  }
  stamp.close();
}
}


你可能感兴趣的:(C++,c,C#)