use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.
the class WritePdf method writeConceptSheme.
/**
* ecri les information du ConceptSheme dans le PDF
*/
private void writeConceptSheme() {
PdfPTable table = new PdfPTable(2);
PdfPCell cell1 = new PdfPCell();
PdfPCell cell2 = new PdfPCell();
try {
SKOSResource thesaurus = xmlDocument.getConceptScheme();
for (SKOSLabel label : thesaurus.getLabelsList()) {
if (label.getLanguage().equals(codeLang)) {
String labelValue = label.getLabel();
if (label.getProperty() == SKOSProperty.prefLabel) {
cell1.addElement(new Paragraph(labelValue + " (" + codeLang + ")", titleFont));
}
}
}
cell1.setBorderWidth(Rectangle.NO_BORDER);
table.addCell(cell1);
if (!codeLang2.equals("")) {
for (SKOSLabel label : thesaurus.getLabelsList()) {
if (label.getLanguage().equals(codeLang2)) {
String labelValue = label.getLabel();
if (label.getProperty() == SKOSProperty.prefLabel) {
cell2.addElement(new Paragraph(labelValue + " (" + codeLang2 + ")", titleFont));
}
}
}
}
cell2.setBorder(Rectangle.NO_BORDER);
table.addCell(cell2);
document.add(new Paragraph(thesaurus.getUri(), subTitleFont));
document.add(table);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
} catch (DocumentException ex) {
Logger.getLogger(WritePdf.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.
the class WritePdf method writeTerm.
/**
* ajoute un paragraphe qui decri le term dans le document PDF
*
* @param concept
* @param paragraphs
*/
private void writeTerm(SKOSResource concept, ArrayList<Paragraph> paragraphs, String langue, String langue2) {
String id = getIdFromUri(concept.getUri());
int altLabelCount = 0;
ArrayList<Integer> tradList = idToIsTrad.get(id);
if (tradList != null) {
for (int lab : tradList) {
if (lab == SKOSProperty.altLabel) {
altLabelCount++;
}
}
}
int altLabelWrite = 0;
for (SKOSLabel label : concept.getLabelsList()) {
if (label.getLanguage().equals(langue) || label.getLanguage().equals(langue2)) {
String labelValue;
boolean prefIsTrad = false;
boolean altIsTrad = false;
if (label.getLanguage().equals(langue)) {
labelValue = label.getLabel();
} else {
if (tradList != null) {
if (tradList.contains(SKOSProperty.prefLabel) && label.getProperty() == SKOSProperty.prefLabel) {
prefIsTrad = true;
}
if (tradList.contains(SKOSProperty.altLabel) && label.getProperty() == SKOSProperty.altLabel) {
if (altLabelCount > altLabelWrite) {
altIsTrad = true;
}
altLabelWrite++;
}
}
labelValue = "-";
}
if (label.getProperty() == SKOSProperty.prefLabel && !prefIsTrad) {
Chunk chunk = new Chunk(labelValue, termFont);
chunk.setLocalDestination(id);
paragraphs.add(new Paragraph(chunk));
} else if (label.getProperty() == SKOSProperty.altLabel && !altIsTrad) {
paragraphs.add(new Paragraph(" USE: " + labelValue, textFont));
}
}
}
paragraphs.add(new Paragraph(" ID: " + id, textFont));
for (SKOSRelation relation : concept.getRelationsList()) {
int prop = relation.getProperty();
String codeRelation;
switch(prop) {
case SKOSProperty.broader:
codeRelation = "BT";
break;
case SKOSProperty.narrower:
codeRelation = "NT";
break;
case SKOSProperty.related:
codeRelation = "RT";
break;
case SKOSProperty.relatedHasPart:
codeRelation = "RHP";
break;
case SKOSProperty.relatedPartOf:
codeRelation = "RPO";
break;
case SKOSProperty.narrowerGeneric:
codeRelation = "NTG";
break;
case SKOSProperty.narrowerInstantial:
codeRelation = "NTI";
break;
case SKOSProperty.narrowerPartitive:
codeRelation = "NTP";
break;
case SKOSProperty.broaderGeneric:
codeRelation = "BTG";
break;
case SKOSProperty.broaderInstantial:
codeRelation = "BTI";
break;
case SKOSProperty.broaderPartitive:
codeRelation = "BTP";
break;
default:
continue;
}
String key = getIdFromUri(relation.getTargetUri());
String targetName = idToNameHashMap.get(key);
if (targetName == null) {
targetName = key;
}
Chunk chunk = new Chunk(" " + codeRelation + ": " + targetName, relationFont);
chunk.setLocalGoto(getIdFromUri(relation.getTargetUri()));
paragraphs.add(new Paragraph(chunk));
}
for (SKOSDocumentation doc : concept.getDocumentationsList()) {
if (!doc.getLanguage().equals(langue) && !doc.getLanguage().equals(langue2)) {
continue;
}
int docCount = 0;
if (tradList != null) {
for (int lab : tradList) {
if (lab == SKOSProperty.note) {
docCount++;
}
}
}
int docWrite = 0;
int prop = doc.getProperty();
String docTypeName;
switch(prop) {
case SKOSProperty.definition:
docTypeName = "definition";
break;
case SKOSProperty.scopeNote:
docTypeName = "scopeNote";
break;
case SKOSProperty.example:
docTypeName = "example";
break;
case SKOSProperty.historyNote:
docTypeName = "historyNote";
break;
case SKOSProperty.editorialNote:
docTypeName = "editorialNote";
break;
case SKOSProperty.changeNote:
docTypeName = "changeNote";
break;
case SKOSProperty.note:
docTypeName = "note";
break;
default:
docTypeName = "note";
break;
}
String docText = "";
boolean docIsTrad = false;
if (doc.getLanguage().equals(langue)) {
docText = doc.getText();
} else {
if (tradList != null && tradList.contains(SKOSProperty.note)) {
if (docCount > docWrite) {
docIsTrad = true;
}
docWrite++;
}
}
if (!docIsTrad) {
paragraphs.add(new Paragraph(" " + docTypeName + ": " + docText, textFont));
}
}
for (SKOSMatch match : concept.getMatchList()) {
int prop = match.getProperty();
String matchTypeName = null;
switch(prop) {
case SKOSProperty.exactMatch:
matchTypeName = "exactMatch";
break;
case SKOSProperty.closeMatch:
matchTypeName = "closeMatch";
break;
case SKOSProperty.broadMatch:
matchTypeName = "broadMatch";
break;
case SKOSProperty.relatedMatch:
matchTypeName = "relatedMatch";
break;
case SKOSProperty.narrowMatch:
matchTypeName = "narrowMatch";
break;
}
paragraphs.add(new Paragraph(" " + matchTypeName + ": " + match.getValue(), textFont));
}
SKOSGPSCoordinates gps = concept.getGPSCoordinates();
String lat = gps.getLat();
String lon = gps.getLon();
if (lat != null && lon != null) {
paragraphs.add(new Paragraph(" lat: " + lat, textFont));
paragraphs.add(new Paragraph(" lat: " + lon, textFont));
}
}
use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.
the class WritePdf method writeHieraTermInfo.
/**
* ecri les données d'un term pour le format hiérarchique
*
* @param key
* @param indenatation
* @param paragraphs
* @param idToDoc
*/
private void writeHieraTermInfo(String key, String indenatation, ArrayList<Paragraph> paragraphs, HashMap<String, ArrayList<String>> idToDoc) {
ArrayList<Integer> tradList = idToIsTradDiff.get(key);
String space = "";
for (int i = 0; i < indenatation.length(); i++) {
space += " ";
}
// doc
ArrayList<String> docList = idToDoc.get(key);
int docCount = 0;
if (tradList != null) {
for (int lab : tradList) {
if (lab == SKOSProperty.note) {
docCount++;
}
}
}
int docWrite = 0;
if (docList != null) {
for (String doc : docList) {
paragraphs.add(new Paragraph(space + doc, hieraInfoFont));
docWrite++;
}
}
if (docWrite < docCount) {
for (int i = 0; i < docCount; i++) {
paragraphs.add(new Paragraph(space + "-", hieraInfoFont));
}
}
// match
ArrayList<String> matchList = idToMatch.get(key);
if (matchList != null) {
for (String match : matchList) {
paragraphs.add(new Paragraph(space + match, hieraInfoFont));
}
}
String gps = idToGPS.get(key);
if (gps != null) {
paragraphs.add(new Paragraph(space + gps, hieraInfoFont));
}
}
use of com.itextpdf.text.Paragraph in project tutorials by eugenp.
the class PDF2TextExample method generatePDFFromTxt.
private static void generatePDFFromTxt(String filename) throws IOException, DocumentException {
Document pdfDoc = new Document(PageSize.A4);
PdfWriter.getInstance(pdfDoc, new FileOutputStream("src/output/txt.pdf")).setPdfVersion(PdfWriter.PDF_VERSION_1_7);
pdfDoc.open();
Font myfont = new Font();
myfont.setStyle(Font.NORMAL);
myfont.setSize(11);
pdfDoc.add(new Paragraph("\n"));
BufferedReader br = new BufferedReader(new FileReader(filename));
String strLine;
while ((strLine = br.readLine()) != null) {
Paragraph para = new Paragraph(strLine + "\n", myfont);
para.setAlignment(Element.ALIGN_JUSTIFIED);
pdfDoc.add(para);
}
pdfDoc.close();
br.close();
}
use of com.itextpdf.text.Paragraph in project specify by rhebecaabreu.
the class DocumentoReq method criaPDF.
/**
* @param args
* @throws FileNotFoundException
* @throws DocumentException
* @throws IOException
* @throws MalformedURLException
*/
public void criaPDF(JTable table_1, java.util.List<Integer> codigosReq) throws FileNotFoundException, DocumentException {
// Listing 1. Instantiation of document object
Document document = new Document();
try {
document.setPageSize(PageSize.A4);
document.setMargins(50, 50, 50, 50);
nomepdf = MeusProjetos.getNome_pdf() + ".pdf";
// Listing 2. Creation of PdfWriter object
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nomepdf));
ModelPDFRodape mf = new ModelPDFRodape();
mf.setTopo("Specify");
writer.setPageEvent(mf);
document.open();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String data = dateFormat.format(date);
// Listing 3. Creation of chapter object
Paragraph title1 = new Paragraph("JTFieldOnlyNumbers de Requisitos", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
title1.setAlignment(Element.ALIGN_CENTER);
Chapter chapter1 = new Chapter(title1, 1);
chapter1.setNumberDepth(0);
RequisitoDAO rdao = new RequisitoDAO();
// Listing 4. Creation of section object
ProjetoDAO pread = new ProjetoDAO();
for (Requisito r : rdao.readOrderBy()) {
for (Projeto p : pread.read()) {
for (int i = 0; i < codigosReq.size(); i++) {
if (r.getProjcodigo() == p.getCodigo() && r.getCodigo() == codigosReq.get(0)) {
Paragraph title_project2 = new Paragraph("Projeto: " + p.getNome(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD));
title_project2.setAlignment(Element.ALIGN_CENTER);
chapter1.add(title_project2);
break;
}
}
}
}
Paragraph data_hora = new Paragraph("Gerado em " + data, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL));
data_hora.setAlignment(Element.ALIGN_CENTER);
chapter1.add(data_hora);
Paragraph listRequirement = new Paragraph("Lista de Requisitos", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL));
Section section1 = chapter1.addSection(listRequirement);
RequisitoDAO rrdao = new RequisitoDAO();
Font f = FontFactory.getFont(FontFactory.HELVETICA, 13, Font.NORMAL);
Font ff = FontFactory.getFont(FontFactory.HELVETICA, 13, Font.BOLD);
for (Requisito r : rrdao.readOrderBy()) {
if (table_1.getSelectedRow() != -1) {
for (int j = 0; j < (codigosReq.size()); j++) {
if (r.getCodigo() == codigosReq.get(j)) {
if (r.getTipoReq().toString().equals("FUNCIONAL")) {
Paragraph o = new Paragraph();
o.setFont(ff);
o.add("Tipo de Requisito: ");
o.setFont(f);
o.add("Funcional" + " ");
o.setFont(ff);
o.add(" Código: ");
o.setFont(f);
o.add(String.valueOf(r.getCodigo()));
section1.add(o);
}
if (r.getTipoReq().toString().equals("NAOFUNCIONAL")) {
Paragraph o = new Paragraph();
o.setFont(ff);
o.add("Tipo de Requisito: ");
o.setFont(f);
o.add("Não-funcional" + " ");
o.setFont(ff);
o.add(" Código: ");
o.setFont(f);
o.add(String.valueOf(r.getCodigo()));
section1.add(o);
}
if (r.getTipoReq().toString().equals("USUARIO")) {
Paragraph o = new Paragraph();
o.setFont(ff);
o.add("Tipo de Requisito: ");
o.setFont(f);
o.add(" Usuário" + " ");
o.setFont(ff);
o.add(" Código: ");
o.setFont(f);
o.add(String.valueOf(r.getCodigo()));
section1.add(o);
}
if (r.getTipoReq().toString().equals("NEGOCIO")) {
Paragraph o = new Paragraph();
o.setFont(ff);
o.add("Tipo de Requisito: ");
o.setFont(f);
o.add(" Negócio" + " ");
o.setFont(ff);
o.add(" Código: ");
o.setFont(f);
o.add(String.valueOf(r.getCodigo()));
section1.add(o);
}
Paragraph p = new Paragraph();
Paragraph q = new Paragraph();
Paragraph rr = new Paragraph();
Paragraph s = new Paragraph();
Paragraph t = new Paragraph();
p.setFont(ff);
p.add("Identificador: ");
p.setFont(f);
p.add(r.getId());
q.setFont(ff);
q.add("O(a) " + r.getSujeito() + " deve ser capaz de " + r.getAcaoRestricao() + " para " + r.getValorRazao());
rr.setFont(ff);
rr.add("Grau Prioridade: ");
rr.setFont(f);
rr.add(r.getGrauPrioridade().toString());
s.setFont(ff);
s.add("Grau Dificuldade: ");
s.setFont(f);
s.add(r.getGrauDificuldade().toString());
t = new Paragraph(" ");
section1.add(p);
section1.add(q);
section1.add(rr);
section1.add(s);
section1.add(t);
}
}
}
}
// Listing 5. Addition of a chapter to the main document
document.add(chapter1);
document.add(Chunk.NEXTPAGE);
} catch (DocumentException ex) {
System.out.println("Error:" + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error:" + ex);
} finally {
document.close();
}
try {
Desktop.getDesktop().open(new File(nomepdf));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations