Java Code Examples for com.lowagie.text.pdf.PdfWriter#setViewerPreferences()

The following examples show how to use com.lowagie.text.pdf.PdfWriter#setViewerPreferences() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionalContentTest.java    From itext2 with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Demonstrates the use of layers.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("optionalcontent.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3: opening the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase(
			"Automatic layers, form fields, images, templates and actions",
			new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
	PdfLayerMembership m1 = new PdfLayerMembership(writer);
	m1.addMember(l2);
	m1.addMember(l3);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2 or layer 3");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
	cb.endLayer();
	cb.beginLayer(m1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
			"field1");
	ff.setBorderColor(Color.blue);
	ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
	ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
	ff.setText("I'm a form field");
	PdfFormField form = ff.getTextField();
	form.setLayer(l4);
	writer.addAnnotation(form);
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
			+ "pngnow.png");
	img.setLayer(l4);
	img.setAbsolutePosition(200, 550);
	cb.addImage(img);
	PdfTemplate tp = cb.createTemplate(100, 20);
	Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
			Font.NORMAL, Color.magenta));
	ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
	tp.setLayer(l4);
	tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
	cb.addTemplate(tp, 200, 500);
	ArrayList<Object> state = new ArrayList<Object>();
	state.add("toggle");
	state.add(l1);
	state.add(l2);
	state.add(l3);
	state.add(l4);
	PdfAction action = PdfAction.setOCGstate(state, true);
	Chunk ck = new Chunk("Click here to toggle the layers", new Font(
			Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
			Color.blue).setAction(action);
	ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
			250, 400, 0);
	cb.sanityCheck();

	// step 5: closing the document
	document.close();
}
 
Example 2
Source File: BookmarksTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: BookmarksTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: PageLabelsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Demonstrates some PageLabel functionality.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("PageLabels.pdf"));
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
	document.open();
	// step 4:
	// we add some content
	for (int k = 1; k <= 10; ++k) {
		document.add(new Paragraph(
				"This document has the logical page numbers: i,ii,iii,iv,1,2,3,A-8,A-9,A-10\nReal page " + k));
		document.newPage();
	}
	PdfPageLabels pageLabels = new PdfPageLabels();
	pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
	pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
	pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);
	writer.setPageLabels(pageLabels);

	// step 5: we close the document
	document.close();
}
 
Example 5
Source File: ViewerPreferencesTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates documents with different viewerpreferences.
 * 
 */
@Test
public void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document(PageSize.A6);

	// step 2:
	PdfWriter writer1 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("TwoColumnLeft.pdf"));
	PdfWriter writer2 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("HideMenuToolbar.pdf"));
	PdfWriter writer3 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("FullScreen.pdf"));
	PdfWriter writer4 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("WithTitle.pdf"));
	PdfWriter writer5 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NoScaling.pdf"));
	// step 3:
	writer1.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);
	writer2.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideMenubar);
	writer3.setViewerPreferences(PdfWriter.PageLayoutTwoColumnRight | PdfWriter.PageModeFullScreen
			| PdfWriter.NonFullScreenPageModeUseThumbs);
	writer4.setViewerPreferences(PdfWriter.DisplayDocTitle);
	writer5.setViewerPreferences(PdfWriter.PrintScalingNone);
	document.addTitle("Julius Caesar");
	document.open();
	// step 4: we grab the ContentByte and do some stuff with it
	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();
}
 
Example 6
Source File: OrderedLayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates how to order optional content groups.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("orderedlayers.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3
	document.open();
	// step 4
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase("Ordered layers", new Font(
			Font.HELVETICA, 20, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayerMembership m1 = new PdfLayerMembership(writer);
	m1.addMember(l2);
	m1.addMember(l3);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2 or layer 3");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
	cb.endLayer();
	cb.beginLayer(m1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	cb.sanityCheck();

	PdfOCProperties p = writer.getOCProperties();
	PdfArray order = new PdfArray();
	order.add(l1.getRef());
	order.add(l2.getRef());
	order.add(l3.getRef());
	PdfDictionary d = new PdfDictionary();
	d.put(PdfName.ORDER, order);
	p.put(PdfName.D, d);
	// step 5
	document.close();
}
 
Example 7
Source File: LayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * Layer radio group and zoom.
    */
@Test
public void main() throws Exception {
       	// step 1
           Document document = new Document(PageSize.A4, 50, 50, 50, 50);
           // step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "layers.pdf"));
           writer.setPdfVersion(PdfWriter.VERSION_1_5);
           writer.setViewerPreferences(PdfWriter.PageModeUseOC);
           // step 3
           document.open();
           // step 4
           PdfContentByte cb = writer.getDirectContent();
           Phrase explanation = new Phrase("Layer radio group and zoom", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
           PdfLayer title = PdfLayer.createTitle("Layer radio group", writer);
           PdfLayer l1 = new PdfLayer("Layer 1", writer);
           PdfLayer l2 = new PdfLayer("Layer 2", writer);
           PdfLayer l3 = new PdfLayer("Layer 3", writer);
           PdfLayer l4 = new PdfLayer("Layer 4", writer);
           title.addChild(l1);
           title.addChild(l2);
           title.addChild(l3);
           l4.setZoom(2, -1);
           l4.setOnPanel(false);
           l4.setPrint("Print", true);
           l2.setOn(false);
           l3.setOn(false);
           ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>();
           radio.add(l1);
           radio.add(l2);
           radio.add(l3);
           writer.addOCGRadioGroup(radio);
           Phrase p1 = new Phrase("Text in layer 1");
           Phrase p2 = new Phrase("Text in layer 2");
           Phrase p3 = new Phrase("Text in layer 3");
           Phrase p4 = new Phrase("Text in layer 4");
           cb.beginLayer(l1);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
           cb.endLayer();
           cb.beginLayer(l2);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
           cb.endLayer();
           cb.beginLayer(l3);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
           cb.endLayer();
           cb.beginLayer(l4);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0);
           cb.endLayer();
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("<< Zoom here!", new Font(Font.COURIER, 12, Font.NORMAL, Color.blue)), 150, 450, 0);
           // step 5
           document.close();

   }
 
Example 8
Source File: AutomaticTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Automatic grouping and nesting.
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("automatic.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3
	document.open();
	// step 4
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase("Automatic layer grouping and nesting",
			new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l12 = new PdfLayer("Layer nesting", writer);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer title = PdfLayer.createTitle("Layer grouping", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayer l4 = new PdfLayer("Layer 4", writer);
	l12.addChild(l1);
	l12.addChild(l2);
	title.addChild(l3);
	title.addChild(l4);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2");
	Phrase p3 = new Phrase("Text in layer 3");
	Phrase p4 = new Phrase("Text in layer 4");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
	cb.endLayer();
	cb.beginLayer(l2);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	cb.beginLayer(l4);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0);
	cb.endLayer();
	cb.sanityCheck();

	// step 5
	document.close();
}
 
Example 9
Source File: NestedLayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates the use of nested layers
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("nestedlayers.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3
	document.open();
	// step 4
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase("Layer nesting", new Font(
			Font.HELVETICA, 20, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l23 = new PdfLayer("Top Layer 2 3", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
	cb.endLayer();
	cb.beginLayer(l23);
	cb.beginLayer(l2);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	cb.endLayer();
	cb.sanityCheck();

	PdfOCProperties p = writer.getOCProperties();
	PdfArray order = new PdfArray();
	order.add(l1.getRef());
	order.add(l23.getRef());
	PdfArray group = new PdfArray();
	group.add(l2.getRef());
	group.add(l3.getRef());
	order.add(group);
	PdfDictionary d = new PdfDictionary();
	d.put(PdfName.ORDER, order);
	p.put(PdfName.D, d);
	// step 5
	document.close();
}
 
Example 10
Source File: ContentGroupsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * Demonstrates how to group optional content.
    */
@Test
public void main() throws Exception {
       	// step 1
           Document document = new Document(PageSize.A4, 50, 50, 50, 50);
           // step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "contentgroups.pdf"));
           writer.setPdfVersion(PdfWriter.VERSION_1_5);
           writer.setViewerPreferences(PdfWriter.PageModeUseOC);
           // step 3
           document.open();
           // step 4
           PdfContentByte cb = writer.getDirectContent();
           Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
           PdfLayer l1 = new PdfLayer("Layer 1", writer);
           PdfLayer l2 = new PdfLayer("Layer 2", writer);
           PdfLayer l3 = new PdfLayer("Layer 3", writer);
           PdfLayerMembership m1 = new PdfLayerMembership(writer);
           m1.addMember(l2);
           m1.addMember(l3);
           Phrase p1 = new Phrase("Text in layer 1");
           Phrase p2 = new Phrase("Text in layer 2 or layer 3");
           Phrase p3 = new Phrase("Text in layer 3");
           cb.beginLayer(l1);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
           cb.endLayer();
           cb.beginLayer(m1);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
           cb.endLayer();
           cb.beginLayer(l3);
           ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
           cb.endLayer();
           cb.sanityCheck();
           
           PdfOCProperties p = writer.getOCProperties();
           PdfArray order = new PdfArray();
           order.add(l1.getRef());
           PdfArray group = new PdfArray();
           group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
           group.add(l2.getRef());
           group.add(l3.getRef());
           order.add(group);
           PdfDictionary d = new PdfDictionary();
           d.put(PdfName.ORDER, order);
           p.put(PdfName.D, d);
           // step 5
           document.close();
   }
 
Example 11
Source File: ChapterSectionTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a document with outlines.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ChapterSection.pdf"));
	// step 3: we open the document
	writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
	document.open();
	// step 4: we add content to the document
	// we define some fonts
	Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
	Font sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
	Font subsectionFont = FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));
	// we create some paragraphs
	Paragraph blahblah = new Paragraph(
			"blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");
	Paragraph blahblahblah = new Paragraph(
			"blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");
	// this loop will create 7 chapters
	for (int i = 1; i < 8; i++) {
		Paragraph cTitle = new Paragraph("This is chapter " + i, chapterFont);
		Chapter chapter = new Chapter(cTitle, i);
		// in chapter 4 we change the alignment to ALIGN_JUSTIFIED
		if (i == 4) {
			blahblahblah.setAlignment(Element.ALIGN_JUSTIFIED);
			blahblah.setAlignment(Element.ALIGN_JUSTIFIED);
			chapter.add(blahblah);
		}
		// in chapter 5, the alignment is changed again
		if (i == 5) {
			blahblahblah.setAlignment(Element.ALIGN_CENTER);
			blahblah.setAlignment(Element.ALIGN_RIGHT);
			chapter.add(blahblah);
		}
		// the alignment is changed to ALIGN_JUSTIFIED again
		if (i == 6) {
			blahblahblah.setAlignment(Element.ALIGN_JUSTIFIED);
			blahblah.setAlignment(Element.ALIGN_JUSTIFIED);
		}
		// in every chapter 3 sections will be added
		for (int j = 1; j < 4; j++) {
			Paragraph sTitle = new Paragraph("This is section " + j + " in chapter " + i, sectionFont);
			Section section = chapter.addSection(sTitle, 1);
			// for chapters > 2, the outine isn't open by default
			if (i > 2)
				section.setBookmarkOpen(false);
			// in all chapters except the 1st one, some extra text is added
			// to section 3
			if (j == 3 && i > 1) {
				section.setIndentationLeft(72);
				section.add(blahblah);
				section.add(new Paragraph("test"));
			}
			// in every section 3 subsections are added
			for (int k = 1; k < 4; k++) {
				Paragraph subTitle = new Paragraph("This is subsection " + k + " of section " + j, subsectionFont);
				Section subsection = section.addSection(subTitle, 3);
				// in the first subsection of section 3, extra text is added
				if (k == 1 && j == 3) {
					subsection.add(blahblahblah);
				}
				subsection.add(blahblah);
			}
			// in the section section of every chapter > 2 extra text is
			// added
			if (j == 2 && i > 2) {
				section.add(blahblahblah);
			}
			// a new page is added after the second section in Chapter 1
			if (j == 2 && i == 1) {
				section.add(Chunk.NEXTPAGE);
			}
		}
		document.add(chapter);
	}

	// step 5: we close the document
	document.close();
}
 
Example 12
Source File: OutlineActionsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates some PageLabel functionality.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	Document remote = new Document();
	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OutlineActions.pdf"));
	PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
	document.open();
	remote.open();
	// step 4:
	// we add some content
	document.add(new Paragraph("Outline action example"));
	// we add the outline
	PdfContentByte cb = writer.getDirectContent();
	PdfOutline root = cb.getRootOutline();
	PdfOutline links = new PdfOutline(root, new PdfAction("http://www.lowagie.com/iText/links.html"),
			"Useful links");
	links.setColor(new Color(0x00, 0x80, 0x80));
	links.setStyle(Font.BOLD);
	new PdfOutline(links, new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
	new PdfOutline(links, new PdfAction("http://itextpdf.sourceforge.net/"), "Paulo's iText site");
	new PdfOutline(links, new PdfAction("http://sourceforge.net/projects/itext/"), "iText @ SourceForge");
	PdfOutline other = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), "other actions", false);
	other.setStyle(Font.ITALIC);
	new PdfOutline(other, new PdfAction("remote.pdf", 1), "Go to yhe first page of a remote file");
	new PdfOutline(other, new PdfAction("remote.pdf", "test"), "Go to a local destination in a remote file");
	new PdfOutline(other, PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");

	remote.add(new Paragraph("Some remote document"));
	remote.newPage();
	Paragraph p = new Paragraph("This paragraph contains a ");
	p.add(new Chunk("local destination").setLocalDestination("test"));
	remote.add(p);

	// step 5: we close the document
	document.close();
	remote.close();
}
 
Example 13
Source File: DestinationsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a document with some goto actions.
 * 
 */
@Test
public void main() throws Exception {

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

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

	// we create a PdfTemplate
	PdfTemplate template = cb.createTemplate(25, 25);

	// we add some crosses to visualize the destinations
	template.moveTo(13, 0);
	template.lineTo(13, 25);
	template.moveTo(0, 13);
	template.lineTo(50, 13);
	template.stroke();

	// we add the template on different positions
	cb.addTemplate(template, 287, 787);
	cb.addTemplate(template, 187, 487);
	cb.addTemplate(template, 487, 287);
	cb.addTemplate(template, 87, 87);

	// we define the destinations
	PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
	PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
	PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
	PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
	PdfDestination d5 = new PdfDestination(PdfDestination.FIT);

	// we define the outlines
	PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
	PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
	new PdfOutline(out1, d3, "sub 2");
	new PdfOutline(out2, d4, "sub 2.1");
	new PdfOutline(out2, d5, "sub 2.2");

	// step 5: we close the document
	document.close();
}
 
Example 14
Source File: LayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates some Layer functionality.
 * 
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();
	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Layers.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	document.open();
	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayerMembership m1 = new PdfLayerMembership(writer);
	m1.addMember(l2);
	m1.addMember(l3);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2 or layer 3");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
	cb.endLayer();
	cb.beginLayer(m1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	PdfOCProperties p = writer.getOCProperties();
	PdfArray order = new PdfArray();
	order.add(l1.getRef());
	PdfArray group = new PdfArray();
	group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
	group.add(l2.getRef());
	group.add(l3.getRef());
	order.add(group);
	PdfDictionary d = new PdfDictionary();
	d.put(PdfName.ORDER, order);
	p.put(PdfName.D, d);

	// step 5: we close the document
	document.close();
}
 
Example 15
Source File: AbstractPdfView.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Prepare the given PdfWriter. Called before building the PDF document,
 * that is, before the call to {@code Document.open()}.
 * <p>Useful for registering a page event listener, for example.
 * The default implementation sets the viewer preferences as returned
 * by this class's {@code getViewerPreferences()} method.
 * @param model the model, in case meta information must be populated from it
 * @param writer the PdfWriter to prepare
 * @param request in case we need locale etc. Shouldn't look at attributes.
 * @throws DocumentException if thrown during writer preparation
 * @see com.lowagie.text.Document#open()
 * @see com.lowagie.text.pdf.PdfWriter#setPageEvent
 * @see com.lowagie.text.pdf.PdfWriter#setViewerPreferences
 * @see #getViewerPreferences()
 */
protected void prepareWriter(Map<String, Object> model, PdfWriter writer, HttpServletRequest request)
		throws DocumentException {

	writer.setViewerPreferences(getViewerPreferences());
}
 
Example 16
Source File: AbstractPdfView.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Prepare the given PdfWriter. Called before building the PDF document,
 * that is, before the call to {@code Document.open()}.
 * <p>Useful for registering a page event listener, for example.
 * The default implementation sets the viewer preferences as returned
 * by this class's {@code getViewerPreferences()} method.
 * @param model the model, in case meta information must be populated from it
 * @param writer the PdfWriter to prepare
 * @param request in case we need locale etc. Shouldn't look at attributes.
 * @throws DocumentException if thrown during writer preparation
 * @see com.lowagie.text.Document#open()
 * @see com.lowagie.text.pdf.PdfWriter#setPageEvent
 * @see com.lowagie.text.pdf.PdfWriter#setViewerPreferences
 * @see #getViewerPreferences()
 */
protected void prepareWriter(Map<String, Object> model, PdfWriter writer, HttpServletRequest request)
		throws DocumentException {

	writer.setViewerPreferences(getViewerPreferences());
}
 
Example 17
Source File: AbstractPdfView.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Prepare the given PdfWriter. Called before building the PDF document,
 * that is, before the call to {@code Document.open()}.
 * <p>Useful for registering a page event listener, for example.
 * The default implementation sets the viewer preferences as returned
 * by this class's {@code getViewerPreferences()} method.
 * @param model the model, in case meta information must be populated from it
 * @param writer the PdfWriter to prepare
 * @param request in case we need locale etc. Shouldn't look at attributes.
 * @throws DocumentException if thrown during writer preparation
 * @see com.lowagie.text.Document#open()
 * @see com.lowagie.text.pdf.PdfWriter#setPageEvent
 * @see com.lowagie.text.pdf.PdfWriter#setViewerPreferences
 * @see #getViewerPreferences()
 */
protected void prepareWriter(Map<String, Object> model, PdfWriter writer, HttpServletRequest request)
		throws DocumentException {

	writer.setViewerPreferences(getViewerPreferences());
}
 
Example 18
Source File: AbstractPdfView.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Prepare the given PdfWriter. Called before building the PDF document,
 * that is, before the call to {@code Document.open()}.
 * <p>Useful for registering a page event listener, for example.
 * The default implementation sets the viewer preferences as returned
 * by this class's {@code getViewerPreferences()} method.
 * @param model the model, in case meta information must be populated from it
 * @param writer the PdfWriter to prepare
 * @param request in case we need locale etc. Shouldn't look at attributes.
 * @throws DocumentException if thrown during writer preparation
 * @see com.lowagie.text.Document#open()
 * @see com.lowagie.text.pdf.PdfWriter#setPageEvent
 * @see com.lowagie.text.pdf.PdfWriter#setViewerPreferences
 * @see #getViewerPreferences()
 */
protected void prepareWriter(Map<String, Object> model, PdfWriter writer, HttpServletRequest request)
		throws DocumentException {

	writer.setViewerPreferences(getViewerPreferences());
}