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


Java PdfWriter.setPageEvent方法代码示例

本文整理汇总了Java中com.lowagie.text.pdf.PdfWriter.setPageEvent方法的典型用法代码示例。如果您正苦于以下问题:Java PdfWriter.setPageEvent方法的具体用法?Java PdfWriter.setPageEvent怎么用?Java PdfWriter.setPageEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.pdf.PdfWriter的用法示例。


在下文中一共展示了PdfWriter.setPageEvent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: close

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
	try {
		float width = 0;
		float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
		for (int i = 0; i < iMaxWidth.length; i++)
			if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
		Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
		PdfWriter writer = PdfWriter.getInstance(document, iOutput);
		writer.setPageEvent(new PdfEventHandler());
		document.open();
		iTable.setWidths(w);
		document.add(iTable);
		document.close();
	} catch (DocumentException e) {
		throw new IOException(e.getMessage(), e);
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:PDFPrinter.java

示例2: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
    * Generates a document with a header containing Page x of y and with a Watermark on every page.
    */
@Test
public void main() throws Exception {
       	// step 1: creating the document
           Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
           // step 2: creating the writer
           PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
           // step 3: initialisations + opening the document
           writer.setPageEvent(new PageNumbersWatermarkTest());
           doc.open();
           // step 4: adding content
           String text = "some padding text ";
           for (int k = 0; k < 10; ++k) {
               text += text;
           }
           Paragraph p = new Paragraph(text);
           p.setAlignment(Element.ALIGN_JUSTIFIED);
           doc.add(p);
           // step 5: closing the document
           doc.close();
       
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:25,代码来源:PageNumbersWatermarkTest.java

示例3: initFooter

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
   * Initialize Pdf footer
   * @param document
   * @param outputStream
   * @return PdfWriter
   */
  public static PdfWriter initFooter(Document document, OutputStream outputStream) 
  		throws DocumentException, IOException {
  	
PdfWriter iWriter = PdfWriter.getInstance(document, outputStream);
iWriter.setPageEvent(new PdfEventHandler());
  	
return iWriter;
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:15,代码来源:PdfEventHandler.java

示例4: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Demonstrates the use of PageEvents.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 70, 70);

	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("endpage.pdf"));
	writer.setPageEvent(new EndPageTest());
	document.open();
	String text = "Lots of text. ";
	for (int k = 0; k < 10; ++k)
		text += text;
	document.add(new Paragraph(text));
	document.close();

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

示例5: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Creates a document with outlines.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A6);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Bookmarks.pdf"));
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
	document.open();
	// step 4: we grab the ContentByte and do some stuff with it
	writer.setPageEvent(new BookmarksTest());

	document.add(new Paragraph(
			"GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
			new Font(Font.HELVETICA, 12)));

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:38,代码来源:BookmarksTest.java

示例6: newInstance

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Creates a new instance of the PDF writer.
 * 
 * @param document
 * @param stream
 * @param settings
 * @return PdfWriter
 */
public static PdfWriter newInstance(Document document, OutputStream stream, FontSettings settings) {
	PdfWriter result;
	try {
		result = PdfWriter.getInstance(document, stream);
	} catch (DocumentException e) {
		MiscUtils.getLogger().error("Unable to create new PdfWriter instance", e);
		return null;
	}

	String confidentialtyStatement = OscarProperties.getConfidentialityStatement();
	PromoTextStamper pts = new PromoTextStamper(confidentialtyStatement, 30);
	pts.setFontSize(settings.getFontSize());
	result.setPageEvent(pts);

	SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
	String promoText = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") + " " + f.format(new Date());
	pts = new PromoTextStamper(promoText, 20);
	pts.setFontSize(settings.getFontSize());
	result.setPageEvent(pts);

	PageNumberStamper pns = new PageNumberStamper(10);
	pns.setFontSize(settings.getFontSize());
	result.setPageEvent(pns);

	return result;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:35,代码来源:PdfWriterFactory.java

示例7: printPdf

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void printPdf() throws IOException, DocumentException{

        // check that we have data to print
        if (handler == null)
            throw new DocumentException();

        //response.setContentType("application/pdf");  //octet-stream
        //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\"");

        //Create the document we are going to write to
        document = new Document();
        //PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        // PdfWriter writer = PdfWriter.getInstance(document, os);
        PdfWriter writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

        //Set page event, function onEndPage will execute each time a page is finished being created
        writer.setPageEvent(this);

        document.setPageSize(PageSize.LETTER);
        document.addTitle("Title of the Document");
        document.addCreator("OSCAR");
        document.open();

        //Create the fonts that we are going to use
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 9, Font.NORMAL);
        boldFont = new Font(bf, 10, Font.BOLD);
      //  redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

        // add the header table containing the patient and lab info to the document
        createInfoTable();

        // add the tests and test info for each header
        ArrayList<String> headers = handler.getHeaders();
        for (int i=0; i < headers.size(); i++)
            addLabCategory( headers.get(i) ,null);

        for(MessageHandler extraHandler:handlers) {
        	ArrayList<String> extraHeaders = extraHandler.getHeaders();
            for (int i=0; i < extraHeaders.size(); i++)
                addLabCategory( extraHeaders.get(i) , extraHandler);
        }
        // add end of report table
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setPhrase(new Phrase("  "));
        table.addCell(cell);
        cell.setBorder(15);
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPhrase(new Phrase("END OF REPORT", boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        document.add(table);

        document.close();

        os.flush();
    }
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:62,代码来源:LabPDFCreator.java

示例8: toPdfTable

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void toPdfTable(OutputStream out, HttpServletRequest request, SessionContext context, Collection distPrefs, Long examTypeId) throws Exception {
      WebTable.setOrder(context,"examDistPrefsTable.ord",request.getParameter("order"),4);
      
      PdfWebTable tbl = new PdfWebTable(4, 
              ExamTypeDAO.getInstance().get(examTypeId).getLabel()+" Examination Distribution Preferences",  
              null,
              new String[] {" Preference ", " Type ", " Exam ", " Class/Course " },
              new String[] { "left", "left", "left", "left"},
              new boolean[] { true, true, true, true} );
      
      int nrPrefs = 0;

      for (Iterator i1=distPrefs.iterator();i1.hasNext();) {
          DistributionPref dp = (DistributionPref)i1.next();
          
          if (!context.hasPermission(dp, Right.ExaminationDistributionPreferenceDetail)) continue;
          
          nrPrefs++;
          
          String examStr = "";
          String objStr = "";
          
          
          for (Iterator i2=dp.getOrderedSetOfDistributionObjects().iterator();i2.hasNext();) {
              DistributionObject dO = (DistributionObject)i2.next();
              Exam exam = (Exam)dO.getPrefGroup();
              examStr += dO.preferenceText();
              for (Iterator i3=exam.getOwners().iterator();i3.hasNext();) {
                  ExamOwner owner = (ExamOwner)i3.next();
                  objStr += owner.getLabel();
                  if (i3.hasNext()) {
                      examStr += "\n";
                      objStr += "\n";
                  }
              }
              if (i2.hasNext()) {
                  examStr += "\n";
                  objStr += "\n";
              }
          }

          String distType = dp.getDistributionType().getLabel();
          String prefLevel = dp.getPrefLevel().getPrefName();
          
          tbl.addLine(
                  null, 
                  new String[] { 
                          prefLevel,
                          distType,
                          examStr, 
                          objStr
                      }, 
                  new Comparable[] { null, distType, examStr, objStr });
          
      }       
      
      if (nrPrefs==0)
          tbl.addLine(null,  new String[] { "No preferences found", "", "", "" }, null);
      
      int ord = WebTable.getOrder(context,"examDistPrefsTable.ord");
      ord = (ord>0?1:-1)*(1+Math.abs(ord));
  	
  	PdfPTable table = tbl.printPdfTable(ord);
  	
  	float width = tbl.getWidth();
  	
  	Document doc = new Document(new Rectangle(60f + width, 60f + 1.30f * width),30,30,30,30); 

PdfWriter iWriter = PdfWriter.getInstance(doc, out);
iWriter.setPageEvent(new PdfEventHandler());
doc.open();

if (tbl.getName()!=null)
	doc.add(new Paragraph(tbl.getName(), PdfFont.getBigFont(true)));

doc.add(table);

doc.close();
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:80,代码来源:ExamDistributionPrefsTableBuilder.java

示例9: exportPdf

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void exportPdf(OutputStream out, int ordCol) throws Exception {
PdfPTable table = printPdfTable(ordCol);
  	
float width = getWidth();
	
Document doc = new Document(new Rectangle(60f + width, 60f + 0.75f * width),30,30,30,30); 

PdfWriter iWriter = PdfWriter.getInstance(doc, out);
iWriter.setPageEvent(new PdfEventHandler());
doc.open();
	
if (iName!=null)
	doc.add(new Paragraph(iName, PdfFont.getBigFont(true)));
	
doc.add(table);
	
doc.close();
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:PdfWebTable.java

示例10: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Creates a document with outlines.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A6);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("bookmarks.pdf"));
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
	document.open();
	// step 4: we grab the ContentByte and do some stuff with it
	writer.setPageEvent(new BookmarksTest());

	document.add(new Paragraph(
			"GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.",
			new Font(Font.HELVETICA, 12)));
	document.add(new Paragraph(
			"Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
			new Font(Font.HELVETICA, 12)));

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:39,代码来源:BookmarksTest.java

示例11: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Converts a play in XML into PDF.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 80, 50, 30, 65);

	// step 2:
	// we create a writer that listens to the document
	// and directs a XML-stream to a file
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("RomeoJuliet.pdf"));

	// create add the event handler
	MyPageEvents events = new EventsTest().getPageEvents();
	writer.setPageEvent(events);

	// step 3: we create a parser and set the document handler
	SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

	// step 4: we parse the document
	parser.parse(PdfTestBase.RESOURCES_DIR + "playRomeoJuliet.xml",
			new EventsTest().getXmlHandler(document));

	document.newPage();
	Speaker speaker;
	for (Iterator i = events.getSpeakers().iterator(); i.hasNext();) {
		speaker = (Speaker) i.next();
		document.add(new Paragraph(speaker.getName() + ": "
				+ speaker.getOccurrence() + " speech blocks"));
	}
	document.close();

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

示例12: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Generic page event.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	// we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Glossary.pdf"));
	GlossaryTest generic = new GlossaryTest();
	writer.setPageEvent(generic);

	// step 3: we open the document
	document.open();
	// step 4:
	String[] f = new String[14];
	f[0] = "Courier";
	f[1] = "Courier Bold";
	f[2] = "Courier Italic";
	f[3] = "Courier Bold Italic";
	f[4] = "Helvetica";
	f[5] = "Helvetica bold";
	f[6] = "Helvetica italic";
	f[7] = "Helvetica bold italic";
	f[8] = "Times New Roman";
	f[9] = "Times New Roman bold";
	f[10] = "Times New Roman italic";
	f[11] = "Times New Roman bold italic";
	f[12] = "Symbol";
	f[13] = "Zapfdingbats";
	Font[] fonts = new Font[14];
	fonts[0] = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL);
	fonts[1] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD);
	fonts[2] = FontFactory.getFont(FontFactory.COURIER, 12, Font.ITALIC);
	fonts[3] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD | Font.ITALIC);
	fonts[4] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
	fonts[5] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
	fonts[6] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC);
	fonts[7] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD | Font.ITALIC);
	fonts[8] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	fonts[9] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
	fonts[10] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.ITALIC);
	fonts[11] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD | Font.ITALIC);
	fonts[12] = FontFactory.getFont(FontFactory.SYMBOL, 12, Font.NORMAL);
	fonts[13] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL);
	for (int i = 0; i < 14; i++) {
		Chunk chunk = new Chunk("This is font ", fonts[i]);
		Paragraph p = new Paragraph(chunk);
		p.add(new Phrase(new Chunk(f[i], fonts[i]).setGenericTag(f[i])));
		document.add(p);
		if (i % 4 == 3) {
			document.newPage();
		}
	}

	// we add the glossary
	document.newPage();
	for (Iterator<String> i = generic.glossary.keySet().iterator(); i.hasNext();) {
		String key = (String) i.next();
		int page = ((Integer) generic.glossary.get(key)).intValue();
		Paragraph g = new Paragraph(key);
		g.add(" : page ");
		g.add(String.valueOf(page));
		document.add(g);
	}

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:73,代码来源:GlossaryTest.java

示例13: printPdf

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void printPdf() throws IOException, DocumentException{

        // check that we have data to print
        if (report == null)
            throw new DocumentException();

         //Create the document we are going to write to
        document = new Document();
  
        PdfWriter writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);

        //Set page event, function onEndPage will execute each time a page is finished being created
        writer.setPageEvent(this);

        document.setPageSize(PageSize.LETTER);
        document.addTitle("HRM Report");
        document.addCreator("OSCAR");
        document.open();

        //Create the fonts that we are going to use
        bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        font = new Font(bf, 9, Font.NORMAL);
        boldFont = new Font(bf, 10, Font.BOLD);
      //  redFont = new Font(bf, 9, Font.NORMAL, Color.RED);

        
        // add the header table containing the patient and lab info to the document
        createInfoTable();

        // add end of report table
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.setPhrase(new Phrase("  "));
        table.addCell(cell);
        cell.setBorder(15);
        cell.setBackgroundColor(new Color(210, 212, 255));
        cell.setPhrase(new Phrase("END OF REPORT", boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        document.add(table);

        document.close();

        os.flush();
    }
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:49,代码来源:HrmPDFCreator.java


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