我需要從PDF文件編輯特定的頁面,我有該頁面只保存爲單獨的PDF文件編輯在A4大小的PDF頁面。我已經成功完成了這項工作。輸入文件是字母大小的頁面。但現在我需要的是將編輯後的頁面保存爲A4大小。誰能幫我。我在等待答覆。保存利用iText
以下是我的代碼。
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class pdfEdit {
private static String INPUTFILE = "./pdf/eng.pdf";
private static String OUTPUTFILE = "./pdf/output.pdf";
private static String footerRight = "Web content and services";
private static String footerLeft = "All Rigths Reserved";
private static Document document;
public static void main(String[] args) throws IOException, DocumentException {
document = new Document();
document.open();
PdfReader reader = new PdfReader(INPUTFILE);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(OUTPUTFILE));
int editingPage = 3;
PdfContentByte cb = stamper.getOverContent(editingPage);
cb.rectangle(10, 10, 550, 30);
cb.setRGBColorFill(255, 255, 255);
cb.fill();
PdfContentByte cByte = stamper.getOverContent(editingPage);
editFooterText(cByte);
reader.selectPages(Integer.toString(editingPage));
stamper.close();
document.close();
}
private static void editFooterText(PdfContentByte cByte) throws DocumentException {
Font footerFont = new Font(Font.HELVETICA, 5f, Font.NORMAL, Color.BLACK);
ColumnText cTextLeft = new ColumnText(cByte);
Paragraph leftPara = new Paragraph();
cTextLeft.setAlignment(Element.ALIGN_LEFT);
cTextLeft.setSimpleColumn(document.left(), 10, 500, document.bottom());
Chunk strFooterLeft = new Chunk(footerLeft, footerFont);
leftPara.add(strFooterLeft);
cTextLeft.addElement(leftPara);
cTextLeft.go();
ColumnText cTextRight = new ColumnText(cByte);
cTextRight.setSimpleColumn(document.left(), 10, 430, document.bottom());
Paragraph Rightpara = new Paragraph();
Chunk strfooterRight = new Chunk(footerRight, footerFont);
Rightpara.setAlignment(Element.ALIGN_RIGHT);
Rightpara.add(strfooterRight);
cTextRight.addElement(Rightpara);
cTextRight.go();
}
}
朋友您好..請幫助我。 – 1355
還是我期待有一個答覆您的答覆 – 1355