当前位置: 首页>>代码示例>>Java>>正文


Java PdfStamper类代码示例

本文整理汇总了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();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:16,代码来源:XfdfExampleTest.java

示例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();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:FdfExampleTest.java

示例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();
    }
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:19,代码来源:SupportStatementPdf.java

示例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();
}
 
开发者ID:kuali,项目名称:kfs,代码行数:23,代码来源:ContractsGrantsInvoiceReportServiceImpl.java

示例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();
}
 
开发者ID:ilario-pierbattista,项目名称:studeasy,代码行数:34,代码来源:PdfGenerator.java

示例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();
	}

}
 
开发者ID:fc-dream,项目名称:PDFTestForAndroid,代码行数:31,代码来源:FdfExample.java

示例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();
	}

}
 
开发者ID:fc-dream,项目名称:PDFTestForAndroid,代码行数:25,代码来源:XfdfExample.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AbstractPdfStamperView.java

示例9: setStamper

import com.lowagie.text.pdf.PdfStamper; //导入依赖的package包/类
private void setStamper(PdfStamper stamper) {
	this.stamper = stamper;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:4,代码来源:PDFController.java

示例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);
}
 
开发者ID:TerrenceMiao,项目名称:camel-spring,代码行数:34,代码来源:PdfController.java

示例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);
}
 
开发者ID:TerrenceMiao,项目名称:camel-spring,代码行数:18,代码来源:PdfController.java

示例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();
}
 
开发者ID:ilario-pierbattista,项目名称:studeasy,代码行数:35,代码来源:PdfGenerator.java

示例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();
}
 
开发者ID:ilario-pierbattista,项目名称:studeasy,代码行数:37,代码来源:PdfGenerator.java

示例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());
}
 
开发者ID:slaubenberger,项目名称:wichtel,代码行数:50,代码来源:HelperPdf.java

示例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();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:52,代码来源:AddWatermarkPageNumbersTest.java


注:本文中的com.lowagie.text.pdf.PdfStamper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。