本文整理汇总了Java中com.lowagie.text.pdf.PdfStamper类的典型用法代码示例。如果您正苦于以下问题:Java PdfStamper类的具体用法?Java PdfStamper怎么用?Java PdfStamper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PdfStamper类属于com.lowagie.text.pdf包,在下文中一共展示了PdfStamper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Merges an XFDF file with a PDF form.
*/
@Test
public void main() throws Exception {
// merging the FDF file
PdfReader pdfreader = new PdfReader(PdfTestBase.RESOURCES_DIR + "SimpleRegistrationForm.pdf");
PdfStamper stamp = new PdfStamper(pdfreader, PdfTestBase.getOutputStream("registered_xfdf.pdf"));
XfdfReader fdfreader = new XfdfReader(PdfTestBase.RESOURCES_DIR + "register.xfdf");
AcroFields form = stamp.getAcroFields();
form.setFields(fdfreader);
stamp.close();
}
示例2: main
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Writes an FDF file and merges it with a PDF form.
*/
@Test
public void main() throws Exception {
// writing the FDF file
FdfWriter fdf = new FdfWriter();
fdf.setFieldAsString("name", "Bruno Lowagie");
fdf.setFieldAsString("address", "Baeyensstraat 121, Sint-Amandsberg");
fdf.setFieldAsString("postal_code", "BE-9040");
fdf.setFieldAsString("email", "[email protected]");
fdf.setFile(PdfTestBase.RESOURCES_DIR + "SimpleRegistrationForm.pdf");
fdf.writeTo(PdfTestBase.getOutputStream("SimpleRegistrationForm.fdf"));
// merging the FDF file
PdfReader pdfreader = new PdfReader(PdfTestBase.RESOURCES_DIR + "SimpleRegistrationForm.pdf");
PdfStamper stamp = new PdfStamper(pdfreader, PdfTestBase.getOutputStream("registered_fdf.pdf"));
FdfReader fdfreader = new FdfReader(PdfTestBase.OUTPUT_DIR + "SimpleRegistrationForm.fdf");
AcroFields form = stamp.getAcroFields();
form.setFields(fdfreader);
stamp.close();
}
示例3: modifyPdf
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
public static void modifyPdf(InputStream pdfTemplate, OutputStream modifiedPdf, String name, LocalDate startDate) throws IOException, DocumentException {
// NOTE: Can we use this?
// PdfReader.unethicalreading = true;
PdfReader reader = new PdfReader(pdfTemplate);
PdfStamper stamper = new PdfStamper(reader, modifiedPdf);
fill(stamper.getAcroFields(), name, startDate);
stamper.setFormFlattening(true);
stamper.partialFormFlattening(INITIATIVE_NAME);
stamper.partialFormFlattening(INITIATIVE_DAY);
stamper.partialFormFlattening(INITIATIVE_MONTH);
stamper.partialFormFlattening(INITIATIVE_YEAR);
stamper.close();
reader.close();
}
示例4: renameFieldsIn
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
*
* @param template the path to the original form
* @param list the replacement list
* @return
* @throws IOException
* @throws DocumentException
*/
protected byte[] renameFieldsIn(String template, Map<String, String> list) throws IOException, DocumentException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create the stamper
PdfStamper stamper = new PdfStamper(new PdfReader(template), baos);
// Get the fields
AcroFields fields = stamper.getAcroFields();
// Loop over the fields
for (String field : list.keySet()) {
fields.setField(field, list.get(field));
}
// close the stamper
stamper.close();
return baos.toByteArray();
}
示例5: generatePdfTesi
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Genera il pdf per la richiesta della tesi
*
* @param tesiView Vista con il form per raccogliere i dati
* @param path Path del file di destinazione
* @throws IOException
* @throws DocumentException
*/
public void generatePdfTesi(FormTesi tesiView, String path) throws IOException, DocumentException {
// Lettura del template
PdfReader pdfTemplate = new PdfReader(template);
// Apertura del file di destinazione
FileOutputStream fileOutputStream = createOutputStream(path);
// Popolazione del template con i dati
PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);
stamper.setFormFlattening(true);
stamper.getAcroFields().setField("nome", tesiView.getNome().getText());
stamper.getAcroFields().setField("cognome", tesiView.getCognome().getText());
stamper.getAcroFields().setField("matricola", tesiView.getMatricola().getText());
stamper.getAcroFields().setField("dataNascita", tesiView.getDataNascita().getText());
stamper.getAcroFields().setField("luogoNascita", tesiView.getLuogoNascita().getText());
stamper.getAcroFields().setField("eMail", tesiView.getEmail().getText());
stamper.getAcroFields().setField("annoCorso", tesiView.getAnnoCorso().getText());
stamper.getAcroFields().setField("professoreRelatore", tesiView.getProfRelatore().getText());
stamper.getAcroFields().setField("titoloTesi", tesiView.getTitoloTesi().getText());
pdfTemplate.close();
stamper.close();
fileOutputStream.close();
}
示例6: main
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Writes an FDF file and merges it with a PDF form.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
try {
// writing the FDF file
FdfWriter fdf = new FdfWriter();
fdf.setFieldAsString("name", "Bruno Lowagie");
fdf.setFieldAsString("address", "Baeyensstraat 121, Sint-Amandsberg");
fdf.setFieldAsString("postal_code", "BE-9040");
fdf.setFieldAsString("email", "[email protected]");
fdf.setFile("SimpleRegistrationForm.pdf");
String path = android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "SimpleRegistrationForm.fdf";
fdf.writeTo(new FileOutputStream(path));
// merging the FDF file
PdfReader pdfreader = new PdfReader(PdfTestRunner.getActivity().getResources().openRawResource(R.raw.simpleregistrationform));
PdfStamper stamp = new PdfStamper(pdfreader, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "registered_fdf.pdf"));
FdfReader fdfreader = new FdfReader(path);
AcroFields form = stamp.getAcroFields();
form.setFields(fdfreader);
stamp.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: main
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Merges an XFDF file with a PDF form.
*
* @param args
* no arguments needed
*/
public static void main(String[] args) {
try {
// merging the FDF file
PdfReader pdfreader = new PdfReader(PdfTestRunner.getActivity().getResources().openRawResource(R.raw.simpleregistrationform));
String path = android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "registered_xfdf.pdf";
PdfStamper stamp = new PdfStamper(pdfreader, new FileOutputStream(path));
InputStream inputStream = PdfTestRunner.getActivity().getResources().openRawResource(R.raw.register);
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
XfdfReader fdfreader = new XfdfReader(buffer);
AcroFields form = stamp.getAcroFields();
form.setFields(fdfreader);
stamp.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: renderMergedOutputModel
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
@Override
protected final void renderMergedOutputModel(
Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
// IE workaround: write into byte array first.
ByteArrayOutputStream baos = createTemporaryOutputStream();
PdfReader reader = readPdfResource();
PdfStamper stamper = new PdfStamper(reader, baos);
mergePdfDocument(model, stamper, request, response);
stamper.close();
// Flush to HTTP response.
writeToResponse(response, baos);
}
示例9: setStamper
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
private void setStamper(PdfStamper stamper) {
this.stamper = stamper;
}
示例10: generateBarcode
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Generate barcode in the form
*
* @param pdfStamper
* @throws DocumentException
*/
private void generateBarcode(PdfStamper pdfStamper, String userId) throws DocumentException {
// add barcode on the first page
PdfContentByte cb = pdfStamper.getOverContent(BARCODE_PAGE);
// barcode format 128C
Barcode128 code128 = new Barcode128();
// barcode format e.g. *1502A1234567890
// asterisk - * [constant]
// WebPOS Transaction - 1502 [constant]
// Form Version - A [constant for MyPost 1.5]
// 10-digit APCN
code128.setCode(ASTERISK + WEBPOS_TRANSACTIION + MYPOST_FORM_VERSION + userId);
code128.setCodeType(Barcode128.CODE128);
// convert barcode into image
Image code128Image = code128.createImageWithBarcode(cb, null, null);
// set barcode position x pixel, y pixel
code128Image.setAbsolutePosition(BARCODE_POSITION_X, BARCODE_POSITION_Y);
code128Image.scalePercent(BARCODE_SCALE_PERCENTAGE);
// add barcode image into PDF template
cb.addImage(code128Image);
}
示例11: generateQRCode
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Generate a QR code including URL on the page
*
* @param pdfStamper
* @throws DocumentException
*/
private void generateQRCode(PdfStamper pdfStamper) throws DocumentException {
// add barcode on the first page
PdfContentByte pdfContentByte = pdfStamper.getOverContent(APPENDED_PAGE);
BarcodeQRCode qrcode = new BarcodeQRCode("http://www.vendian.org/mncharity/dir3/paper_rulers/", 200, 200, null);
Image qrcodeImage = qrcode.getImage();
qrcodeImage.setAbsolutePosition(360,500);
qrcodeImage.scalePercent(100);
pdfContentByte.addImage(qrcodeImage);
}
示例12: generatePdfTirocinio
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Genera il pdf per la richiesta di tirocinio
*
* @param tirocinioView Vista con il form per raccogliere i dati
* @param path Path del file di destinazione
* @throws IOException
* @throws DocumentException
*/
public void generatePdfTirocinio(FormTirocinio tirocinioView, String path) throws IOException, DocumentException {
// Lettura del template
PdfReader pdfTemplate = new PdfReader(template);
// Apertura del file di destinazione
FileOutputStream fileOutputStream = createOutputStream(path);
// Popolazione del template con i dati
PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);
stamper.setFormFlattening(true);
stamper.getAcroFields().setField("nome", tirocinioView.getNome().getText());
stamper.getAcroFields().setField("cognome", tirocinioView.getCognome().getText());
stamper.getAcroFields().setField("matricola", tirocinioView.getMatricola().getText());
stamper.getAcroFields().setField("luogoNascita", tirocinioView.getLuogonascita().getText());
stamper.getAcroFields().setField("dataNascita", tirocinioView.getDatanascita().getText());
stamper.getAcroFields().setField("residenza", tirocinioView.getResidenza().getText());
stamper.getAcroFields().setField("provincia", tirocinioView.getProvincia().getText());
stamper.getAcroFields().setField("cap", tirocinioView.getCap().getText());
stamper.getAcroFields().setField("via", tirocinioView.getVia().getText());
stamper.getAcroFields().setField("codiceFiscale", tirocinioView.getCodicefiscale().getText());
pdfTemplate.close();
stamper.close();
fileOutputStream.close();
}
示例13: generatePdfImmatricolazione
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Genera il pdf per l'immatricolazione
*
* @param immatricolazioneView Vista che contiene il form per raccogliere i dati
* @param path Path del file di destinazione
* @throws IOException
* @throws DocumentException
*/
public void generatePdfImmatricolazione(FormImmatricolazione immatricolazioneView, String path) throws IOException, DocumentException {
// Lettura del template
PdfReader pdfTemplate = new PdfReader(template);
// Apertura del file di destinazione
FileOutputStream fileOutputStream = createOutputStream(path);
// Popolazione del template con i dati
PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream);
stamper.setFormFlattening(true);
stamper.getAcroFields().setField("nome", immatricolazioneView.getNome().getText());
stamper.getAcroFields().setField("cognome", immatricolazioneView.getCognome().getText());
stamper.getAcroFields().setField("matricola", immatricolazioneView.getMatricola().getText());
stamper.getAcroFields().setField("luogoNascita", immatricolazioneView.getLuogonascita().getText());
stamper.getAcroFields().setField("dataNascita", immatricolazioneView.getDatanascita().getText());
stamper.getAcroFields().setField("provinciaNascita", immatricolazioneView.getProvincia().getText());
stamper.getAcroFields().setField("codiceFiscale", immatricolazioneView.getCodicefiscale().getText());
stamper.getAcroFields().setField("tipologiaScuolaSuperiore", immatricolazioneView.getDiploma().getText());
stamper.getAcroFields().setField("voto", immatricolazioneView.getVoto().getText());
String primaParteAnnoScolastico = immatricolazioneView.getAnnoConseguimento1().getText();
stamper.getAcroFields().setField("anno1", primaParteAnnoScolastico);
stamper.getAcroFields().setField("anno2", Integer.toString(Integer.parseInt(primaParteAnnoScolastico) + 1));
pdfTemplate.close();
stamper.close();
fileOutputStream.close();
}
示例14: setMetaData
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Modifies the meta data of given PDF and stores it in a new {@link File}.
* <strong>Meta data example:"</strong> metadata.put("Title", "Example");
* metadata.put("Author", "Stefan Laubenberger"); metadata.put("Subject",
* "Example PDF meta data"); metadata.put("Keywords", "Example, PDF");
* metadata.put("Creator", "http://www.laubenberger.net/");
* metadata.put("Producer", "Silvan Spross");
*
* @param source
* {@link File}
* @param dest
* {@link File} for the modified PDF
* @param metadata
* list with the new meta data informations
* @throws DocumentException
* @throws IOException
* @since 0.0.1
*/
@SuppressWarnings("unchecked")
public static void setMetaData(final File source, final File dest, final Map<String, String> metadata)
throws IOException, DocumentException { // $JUnit$
if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(source, dest, metadata));
if (null == source) {
throw new RuntimeExceptionIsNull("source"); //$NON-NLS-1$
}
if (null == dest) {
throw new RuntimeExceptionIsNull("dest"); //$NON-NLS-1$
}
if (HelperObject.isEquals(source, dest)) {
throw new RuntimeExceptionIsEquals("source", "dest"); //$NON-NLS-1$ //$NON-NLS-2$
}
if (null == metadata) {
throw new RuntimeExceptionIsNull("metadata"); //$NON-NLS-1$
}
try (FileOutputStream fos = new FileOutputStream(dest)){
final PdfReader reader = new PdfReader(source.getAbsolutePath());
final PdfStamper stamper = new PdfStamper(reader, fos);
final HashMap<String, String> info = reader.getInfo();
info.putAll(metadata);
stamper.setMoreInfo(info);
stamper.close();
reader.close();
}
if (log.isDebugEnabled()) log.debug(HelperLog.methodExit());
}
示例15: main
import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
*/
@Test
public void main() throws Exception {
// we create a reader for a certain document
PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR +"ChapterSection.pdf");
int n = reader.getNumberOfPages();
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader,PdfTestBase.getOutputStream("watermark_pagenumbers.pdf"));
// adding some metadata
HashMap<String, String> moreInfo = new HashMap<String, String>();
moreInfo.put("Author", "Bruno Lowagie");
stamp.setMoreInfo(moreInfo);
// adding content to each page
int i = 0;
PdfContentByte under;
PdfContentByte over;
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR +"watermark.jpg");
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
// watermark under the existing page
under = stamp.getUnderContent(i);
under.addImage(img);
// text over the existing page
over = stamp.getOverContent(i);
over.beginText();
over.setFontAndSize(bf, 18);
over.setTextMatrix(30, 30);
over.showText("page " + i);
over.setFontAndSize(bf, 32);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE", 230, 430, 45);
over.endText();
}
// adding an extra page
stamp.insertPage(1, PageSize.A4);
over = stamp.getOverContent(1);
over.beginText();
over.setFontAndSize(bf, 18);
over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
over.endText();
// adding a page from another document
PdfReader reader2 = new PdfReader(PdfTestBase.RESOURCES_DIR +"SimpleAnnotations1.pdf");
under = stamp.getUnderContent(1);
under.addTemplate(stamp.getImportedPage(reader2, 3), 1, 0, 0, 1, 0, 0);
// closing PdfStamper will generate the new PDF file
stamp.close();
}