List of usage examples for com.lowagie.text Element ALIGN_JUSTIFIED
int ALIGN_JUSTIFIED
To view the source code for com.lowagie.text Element ALIGN_JUSTIFIED.
Click Source Link
From source file:questions.stamppages.BookmarksToTOC1.java
@SuppressWarnings("unchecked") public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from ww w.j a v a2s .c o m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); writer.setPageEvent(new ParagraphBookmarkEvents(false)); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.add(Chunk.NEWLINE); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); Rectangle rect = reader.getPageSizeWithRotation(1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.insertPage(1, rect); ColumnText column = new ColumnText(stamper.getOverContent(1)); column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); column.addElement(new Paragraph("TABLE OF CONTENTS")); List<Map> list = SimpleBookmark.getBookmark(reader); Chunk link; PdfAction action; String info; int p = 1; float y = 10; for (Map<String, String> bookmark : list) { link = new Chunk(bookmark.get("Title")); info = bookmark.get("Page"); p = Integer.parseInt(info.substring(0, info.indexOf(' '))); y = Float.parseFloat(info.substring(info.lastIndexOf(' ') + 1) + "f"); action = PdfAction.gotoLocalPage(p, new PdfDestination(PdfDestination.FITH, y), stamper.getWriter()); link.setAction(action); column.addElement(new Paragraph(link)); } column.go(); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.stamppages.BookmarksToTOC2.java
@SuppressWarnings("unchecked") public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w ww. j ava 2 s .com*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); writer.setPageEvent(new ParagraphBookmarkEvents(true)); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.add(Chunk.NEWLINE); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); Rectangle rect = reader.getPageSizeWithRotation(1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.insertPage(1, rect); ColumnText column = new ColumnText(stamper.getOverContent(1)); column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); column.addElement(new Paragraph("TABLE OF CONTENTS")); List<Map> list = SimpleBookmark.getBookmark(reader); Chunk link; String dest; for (Map<String, String> bookmark : list) { link = new Chunk(bookmark.get("Title")); dest = bookmark.get("Named"); link.setAction(PdfAction.gotoLocalPage(dest, false)); column.addElement(new Paragraph(link)); } column.go(); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.stamppages.PageXofYRightAligned.java
public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w w w . j a v a2s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, baos); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); int n = reader.getNumberOfPages(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte page; Rectangle rect; BaseFont bf = BaseFont.createFont(); for (int i = 1; i < n + 1; i++) { page = stamper.getOverContent(i); rect = reader.getPageSizeWithRotation(i); page.beginText(); page.setFontAndSize(bf, 12); page.showTextAligned(Element.ALIGN_RIGHT, "page " + i + " of " + n, rect.getRight(36), rect.getTop(32), 0); page.endText(); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:s2s.luna.reports.Report_DOC_VAL_RSO.java
License:GNU General Public License
@Override public void doReport() throws DocumentException, IOException, BadElementException, Exception { SecurityWrapper Security = SecurityWrapper.getInstance(); lCOD_AZL = Security.getAziendaR(); IAziendaHome home_az = (IAziendaHome) PseudoContext.lookup("AziendaBean"); IAzienda bean_az = home_az.findByPrimaryKey(new Long(lCOD_AZL)); IValutazioneRischiHome home_vr = (IValutazioneRischiHome) PseudoContext.lookup("ValutazioneRischiBean"); IValutazioneRischi bean_vr = home_vr.findByPrimaryKey(new Long(lCOD_DOC_VLU)); IGestioniSezioniHome home_sez = (IGestioniSezioniHome) PseudoContext.lookup("GestioniSezioniBean"); IParagrafoHome home_prg = (IParagrafoHome) PseudoContext.lookup("ParagrafoBean"); IGestioneTabellareHome home_tab = (IGestioneTabellareHome) PseudoContext.lookup("GestioneTabellareBean"); ISchedeParagrafoHome home_sch = (ISchedeParagrafoHome) PseudoContext.lookup("SchedeParagrafoBean"); lCOD_UNI_ORG = bean_vr.getCOD_UNI_ORG(); String strAzienda = bean_az.getRAG_SCL_AZL(); boolean isUniOrg = false; String strUniOrgName = ""; if (lCOD_UNI_ORG != 0) { isUniOrg = true;/*from ww w . ja va2 s . c o m*/ IUnitaOrganizzativaHome home_uni = (IUnitaOrganizzativaHome) PseudoContext .lookup("UnitaOrganizzativaBean"); IUnitaOrganizzativa bean_uni = home_uni.findByPrimaryKey(new Long(lCOD_UNI_ORG)); strUniOrgName = bean_uni.getNOM_UNI_ORG(); } initDocumentEx("the doc"); setHeaders(); m_writer.setLinearPageMode(); m_handler.bShowHeader = false; m_handler.bShowDate = false; m_handler.strTopLeft = isUniOrg ? strUniOrgName : strAzienda; m_handler.strTopCenter = ApplicationConfigurator.LanguageManager .getString("Documento.di.valutazione.dei.rischi"); String documentName = getDocumentName(); if (StringManager.isNotEmpty(documentName)) { m_handler.strBottomLeft = ApplicationConfigurator.LanguageManager.getString("Nome.documento") + ": " + documentName + "\n" + ApplicationConfigurator.LanguageManager.getString("Datore.di.lavoro") + ": " + bean_az.getNOM_RSP_AZL(); } else { m_handler.strBottomLeft = ApplicationConfigurator.LanguageManager.getString("Datore.di.lavoro") + ":\n" + bean_az.getNOM_RSP_AZL(); } m_handler.strBottomRight = ApplicationConfigurator.LanguageManager.getString("Data.redazione") + ": " + Formatter.format(bean_vr.getDAT_DOC_VLU()) + "\n" + ApplicationConfigurator.LanguageManager.getString("Versione") + ": " + Formatter.format(bean_vr.getVER_DOC()); // Costruisce l'indice e lo scrive su un documento separato. calculateIndexPage(home_vr, bean_vr, home_sez, home_prg); Report reportIndex = new Report(); reportIndex.initDocumentEx("the doc"); reportIndex.m_handler = m_handler.copy(); reportIndex.m_document.open(); writeIndex(reportIndex); // Determina il numero di pagine occupate dall'indice. iIndexPageCount = reportIndex.m_writer.getPageNumber(); // Nella numerazione delle pagine, // tiene conto di quelle occupate dall'indice. m_handler.setIndexPageCount(iIndexPageCount); // Verifica se l'ultima pagina dell'indice e' pari o e' dispari ROOT.Children.clear(); m_document.open(); AddImage(); writeTitle("\n" + (ApplicationConfigurator.isModuleEnabled(MODULES.MOD_DVR_GSE) ? ApplicationConfigurator.LanguageManager.getString("MSG_REP_0014") : ApplicationConfigurator.LanguageManager.getString("MSG_REP_0007")) + "\n"); writeBig(ApplicationConfigurator.LanguageManager.getString("(D.Lgs.626/94.art.4.comma.2)")); writeTitle("\n"); if (isUniOrg) { Paragraph pr = new Paragraph(strUniOrgName, REPORT_SETTINGS.ftText16); pr.setAlignment(Element.ALIGN_CENTER); m_document.add(pr); } Paragraph pr = new Paragraph(bean_az.getRAG_SCL_AZL(), REPORT_SETTINGS.ftText18); pr.setAlignment(Element.ALIGN_CENTER); m_document.add(pr); pr = new Paragraph(bean_az.getCIT_AZL() + ", " + bean_az.getIDZ_AZL(), REPORT_SETTINGS.ftText3); pr.setAlignment(Element.ALIGN_CENTER); m_document.add(pr); m_handler.bShowHeader = true; // STAMPA SEZIONI - Inizio. Collection col_sez = home_vr.getValutazioneRischiSezioniByID_View(bean_vr.getCOD_DOC_VLU()); Iterator it_sez = col_sez.iterator(); { while (it_sez.hasNext()) { // Se la pagina precedente alla nuova sezione dispari (fronte del foglio), // viene aggiunta una pagina bianca pari (retro del foglio) // prima di proseguire con la stampa della sezione. // Questo, nella stampa fronte-retro, garantisce che la nuova sezione sia // sempre su pagina dispari (parte frontale del foglio). if ((m_writer.getPageNumber() + iIndexPageCount) % 2 == 1) { // Questa regola non applicata per GSE. if (ApplicationConfigurator.isModuleEnabled(MODULES.MOD_DVR_GSE) == false) { writePage(); } } // Scrive ogni sezione su una nuova pagina writePage(); boolean primoCapitoloDellaSezione = true; ValutazioneRischiSezioniByID_View sezione = (ValutazioneRischiSezioniByID_View) it_sez.next(); Pair SECTION = addPair(sezione.NOM_RSP_DOC, ROOT); writeSezione(sezione.NOM_RSP_DOC); { // STAMPA CAPITOLI - Inizio. Collection col_cap = home_sez.getReportGestioniSezioni_CplAre_View(sezione.COD_ARE, lCOD_AZL); Iterator it_cap = col_cap.iterator(); while (it_cap.hasNext()) { if (primoCapitoloDellaSezione) { writeLine(); } else { writePage(); } boolean primoParagrafoDelCapitolo = true; ReportGestioniSezioni_CplAre_View capitolo = (ReportGestioniSezioni_CplAre_View) it_cap .next(); Pair CAPITOLO = addPair(capitolo.NOM_CPL, SECTION); writeCapitolo(capitolo.NOM_CPL); CenterMiddleTable tbl = new CenterMiddleTable(1); tbl.BorderColor(); tbl.setDefaultHorizontalAlignment(Element.ALIGN_JUSTIFIED); tbl.addCell2(Formatter.format(capitolo.DES_CPL_ARE)); m_document.add(tbl); { // STAMPA PARAGRAFI - Inizio. Iterator it_prg = home_prg .getReportParagrafi_byAreCpl_View(sezione.COD_ARE, lCOD_AZL, capitolo.COD_CPL) .iterator(); boolean endWithNewPage = false; while (it_prg.hasNext()) { if (primoParagrafoDelCapitolo && StringManager.isEmpty(capitolo.DES_CPL_ARE)) { writeLine(); } else { writePage(); } ReportParagrafi_byAreCpl_View paragrafo = (ReportParagrafi_byAreCpl_View) it_prg .next(); addPair(paragrafo.NOM_PRG, CAPITOLO); writeParagrafo(Formatter.format(paragrafo.NOM_PRG)); if (StampaDescrizioneParagrafo(paragrafo) && checkContenutoParagrafo(home_tab, home_prg, home_sch, paragrafo.COD_PRG)) { writePage(); } // Stampa del tab "DOCUMENTI" - Inizio { /* NB, il metodo stampa documenti torna true * se la eventuale stampa dei documenti finisce * con una pagina nuova. */ endWithNewPage = StampaDocumenti(home_prg, paragrafo.COD_PRG, m_document, m_writer); } // Stampa del tab "DOCUMENTI" - Fine // Stampa del tab "TABELLE" - Inizio { /* NB, il metodo stampa tabelle torna true * se ho stampato una o piu tabelle. */ if (StampaTabelle(home_tab, paragrafo.COD_PRG, m_document) == true) { endWithNewPage = true; } } // Stampa schede - Inizio { /* NB, il metodo stampa schede torna true * se ho stampato una o piu schede di paragrafo. */ if (StampaSchede(bean_az, home_sch, paragrafo.COD_PRG, lCOD_AZL, endWithNewPage) == true) { endWithNewPage = false; } } // Stampa schede - Fine primoParagrafoDelCapitolo = false; } // STAMPA PARAGRAFI - Fine. if (it_cap.hasNext() && endWithNewPage == false) { // Non eliminare, valutare se aggiungere uno writePage(); } } primoCapitoloDellaSezione = false; } // STAMPA CAPITOLI - Fine. } } // STAMPA SEZIONI - Fine. if (ApplicationConfigurator.isModuleEnabled(MODULES.DVR_ALLEGATI) == true) { // STAMPA TABELLA "DOCUMENTI ALLEGATI" - Inizio Collection<ValutazioneRischiAllegati> allegati_dvr_list; allegati_dvr_list = home_vr.getValutazioneRischiAllegati(lCOD_DOC_VLU); if (allegati_dvr_list != null && allegati_dvr_list.isEmpty() == false) { writePage(); addPair("ALLEGATI", ROOT); writeParagraph1(ApplicationConfigurator.LanguageManager.getString("Documenti.allegati")); { CenterMiddleTable tbl = new CenterMiddleTable(1); tbl.setDeafaultOffset(); tbl.addHeaderCellB( ApplicationConfigurator.LanguageManager.getString("Titolo.del.documento")); tbl.endHeaders(); tbl.setDefaultHorizontalAlignment(Element.ALIGN_LEFT); for (ValutazioneRischiAllegati allegato : allegati_dvr_list) { tbl.addCell(allegato.TIT_DOC); } m_document.add(tbl); } } // STAMPA TABELLA "DOCUMENTI ALLEGATI" - Fine } // Scrive l'indice alla fine del documento. m_handler.startIndex(); writePage();// 3 PAGE writeIndex(this); m_handler.endIndex(); // Porta l'indice dopo la prima pagina. writePage(); reorderPages(); closeDocument(); } }
From source file:s2s.report.Report.java
License:GNU General Public License
public void writeParagraph2(String strText) throws BadElementException, DocumentException { Paragraph pr = new Paragraph(strText != null ? strText.trim() : "", REPORT_SETTINGS.ftParagraph2); pr.setAlignment(Element.ALIGN_JUSTIFIED); pr.setIndentationLeft(10f);/*from w w w . j ava 2 s .co m*/ m_document.add(pr); }
From source file:s2s.report.Report.java
License:GNU General Public License
public void writeParagraph3(String strText) throws BadElementException, DocumentException { Paragraph pr = new Paragraph(strText != null ? strText.trim() : "", REPORT_SETTINGS.ftParagraph3); pr.setAlignment(Element.ALIGN_JUSTIFIED); pr.setIndentationLeft(15f);// w ww. ja v a 2 s. c o m m_document.add(pr); }
From source file:s2s.report.Report.java
License:GNU General Public License
public void writeText2Justified(String strText) throws BadElementException, DocumentException { Paragraph pr = new Paragraph(strText != null ? strText.trim() : "", REPORT_SETTINGS.ftText2); pr.setAlignment(Element.ALIGN_JUSTIFIED); pr.setIndentationLeft(10f);// w w w. ja v a 2s . c o m m_document.add(pr); }
From source file:s2s.report.Report.java
License:GNU General Public License
public void writeText2JustifiedAndIndent(String strText, byte indentationLevel) throws BadElementException, DocumentException { Paragraph pr = new Paragraph(strText != null ? strText.trim() : "", REPORT_SETTINGS.ftText2); pr.setAlignment(Element.ALIGN_JUSTIFIED); if (indentationLevel < 1) indentationLevel = 1;/* w w w. j ava 2s . c om*/ pr.setIndentationLeft(10f + (20f * (indentationLevel - 1))); m_document.add(pr); }