557
|
1 package digilib.pdf;
|
509
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.MalformedURLException;
|
|
5 import java.net.URL;
|
|
6
|
|
7 import org.apache.log4j.Logger;
|
|
8
|
526
|
9 import com.itextpdf.text.Anchor;
|
|
10 import com.itextpdf.text.BadElementException;
|
|
11 import com.itextpdf.text.Chunk;
|
|
12 import com.itextpdf.text.Element;
|
|
13 import com.itextpdf.text.FontFactory;
|
|
14 import com.itextpdf.text.Image;
|
|
15 import com.itextpdf.text.Paragraph;
|
|
16
|
509
|
17
|
557
|
18 import digilib.io.DigilibInfoReader;
|
509
|
19 import digilib.io.DocuDirCache;
|
557
|
20 import digilib.servlet.PDFCache;
|
|
21 import digilib.servlet.PDFRequest;
|
509
|
22
|
|
23 /** A class for the generation of title pages for the generated pdf documents.
|
|
24 *
|
|
25 *
|
|
26 */
|
|
27 public class PDFTitlePage {
|
|
28
|
557
|
29 private PDFRequest job_info = null;
|
509
|
30 private DigilibInfoReader info_reader= null;
|
|
31 private DocuDirCache dirCache = null;
|
|
32 protected static Logger logger = Logger.getLogger("digilib.servlet");
|
|
33
|
|
34
|
511
|
35 /**
|
|
36 * Initialize a TitlePage
|
|
37 * @param pdfji
|
|
38 */
|
557
|
39 public PDFTitlePage(PDFRequest pdfji){
|
509
|
40 job_info = pdfji;
|
|
41 dirCache = (DocuDirCache) job_info.getDlConfig().getValue("servlet.dir.cache");
|
|
42
|
|
43 String fn = getBase(dirCache.getDirectory(pdfji.getImageJobInformation().getAsString("fn")).getDir().getPath()) + "presentation/info.xml";
|
|
44
|
|
45 info_reader = new DigilibInfoReader(fn);
|
|
46 }
|
|
47
|
511
|
48 /**
|
|
49 * generate iText-PDF-Contents for the title page
|
|
50 *
|
|
51 * @return
|
|
52 */
|
509
|
53 public Element getPageContents(){
|
|
54 Paragraph content = new Paragraph();
|
|
55 content.setAlignment(Element.ALIGN_CENTER);
|
|
56
|
|
57 // add vertical whitespace
|
|
58 for(int i=0; i<8; i++){
|
|
59 content.add(Chunk.NEWLINE);
|
|
60 }
|
|
61
|
|
62
|
|
63 // add logo
|
|
64 content.add(getLogo());
|
|
65 content.add(Chunk.NEWLINE);
|
|
66 content.add(Chunk.NEWLINE);
|
|
67
|
|
68 // add title
|
|
69 Anchor title = new Anchor(new Paragraph(getTitle(),FontFactory.getFont(FontFactory.HELVETICA,16)));
|
|
70 String burl = job_info.getImageJobInformation().getAsString("base.url");
|
|
71
|
|
72 title.setReference(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn"));
|
|
73 content.add(title);
|
|
74 content.add(Chunk.NEWLINE);
|
|
75
|
|
76 // add author
|
|
77 if(getDate()!=" ")
|
|
78 content.add(new Paragraph(getAuthor()+" ("+getDate()+")",FontFactory.getFont(FontFactory.HELVETICA,14)));
|
|
79 else
|
|
80 content.add(new Paragraph(getAuthor(),FontFactory.getFont(FontFactory.HELVETICA,14)));
|
|
81
|
|
82 content.add(Chunk.NEWLINE);
|
|
83
|
|
84 // add page numbers
|
|
85 content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12)));
|
|
86
|
|
87
|
|
88 content.add(Chunk.NEWLINE);
|
|
89 content.add(Chunk.NEWLINE);
|
|
90 content.add(Chunk.NEWLINE);
|
|
91
|
|
92 // add credits
|
|
93 content.add(new Paragraph("MPIWG Berlin 2009", FontFactory.getFont(FontFactory.HELVETICA,10)));
|
|
94
|
|
95 // add digilib version
|
|
96 content.add(new Paragraph(getDigilibVersion(),FontFactory.getFont(FontFactory.HELVETICA,10)));
|
|
97
|
|
98 for(int i=0; i<8; i++){
|
|
99 content.add(Chunk.NEWLINE);
|
|
100 }
|
|
101 Anchor address = new Anchor(
|
|
102 new Paragraph(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9))
|
|
103 );
|
|
104 address.setReference(burl+"digilib.jsp?fn="+job_info.getImageJobInformation().getAsString("fn"));
|
|
105
|
|
106 content.add(address);
|
|
107
|
|
108
|
|
109 return content;
|
|
110 }
|
|
111
|
511
|
112 /**
|
|
113 * return base directory of an image directory
|
|
114 *
|
|
115 * @param path
|
|
116 * @return
|
|
117 */
|
509
|
118 private String getBase(String path){
|
|
119 if(path.contains("/")){
|
|
120 String[] x = path.split("/");
|
|
121 String newpath = "";
|
|
122 for(int i=0; i<x.length-1; i++){
|
|
123 newpath += x[i]+"/";
|
|
124 }
|
|
125 return newpath;
|
|
126 }
|
|
127 else
|
|
128 return "";
|
|
129 }
|
|
130
|
511
|
131
|
|
132 /**
|
|
133 * Methods for the different attributes.
|
|
134 *
|
|
135 */
|
|
136
|
509
|
137
|
|
138 private Image getLogo(){
|
|
139 try {
|
|
140 URL url = new URL(job_info.getDlConfig().getAsString("pdf-logo"));
|
|
141 if(url!=null && !url.equals("")){
|
|
142 Image logo = Image.getInstance(url);
|
|
143 logo.setAlignment(Element.ALIGN_CENTER);
|
|
144 return logo;
|
|
145 }
|
|
146 } catch (BadElementException e) {
|
|
147 logger.error(e.getMessage());
|
|
148 e.printStackTrace();
|
|
149 } catch (MalformedURLException e) {
|
|
150 logger.error(e.getMessage());
|
|
151 e.printStackTrace();
|
|
152 } catch (IOException e) {
|
|
153 logger.error(e.getMessage());
|
|
154 e.printStackTrace();
|
|
155 }
|
|
156 return null;
|
|
157 }
|
|
158 private String getTitle(){
|
|
159 if(info_reader.hasInfo())
|
|
160 return info_reader.getAsString("title");
|
|
161 else
|
|
162 return job_info.getImageJobInformation().getAsString("fn");
|
|
163 }
|
|
164 private String getAuthor(){
|
|
165 if(info_reader.hasInfo())
|
|
166 return info_reader.getAsString("author");
|
|
167 else
|
|
168 return " ";
|
|
169 }
|
|
170 private String getDate(){
|
|
171 if(info_reader.hasInfo())
|
|
172 return info_reader.getAsString("date");
|
|
173 else
|
|
174 return " ";
|
|
175 }
|
|
176 private String getPages(){
|
|
177 return "Pages "+job_info.getAsString("pgs") + " (scan page numbers)";
|
|
178 }
|
|
179
|
|
180 private String getDigilibVersion(){
|
557
|
181 return "Digilib PDFMaker v."+PDFCache.version;
|
509
|
182 }
|
|
183
|
|
184 }
|