source: trunk/src/org/expeditee/io/PDFWriter.java@ 289

Last change on this file since 289 was 282, checked in by ra33, 16 years ago
File size: 2.2 KB
Line 
1package org.expeditee.io;
2
3import java.awt.Image;
4import java.io.FileOutputStream;
5import java.io.IOException;
6import java.util.List;
7
8import org.expeditee.gui.Frame;
9import org.expeditee.gui.UserSettings;
10import org.expeditee.items.Item;
11import org.expeditee.items.Picture;
12import org.expeditee.items.Text;
13
14import com.lowagie.text.Document;
15import com.lowagie.text.DocumentException;
16import com.lowagie.text.FontFactory;
17import com.lowagie.text.Paragraph;
18import com.lowagie.text.pdf.PdfWriter;
19
20/**
21 * Writes out a tree in a linear format.
22 * @author root
23 *
24 */
25public class PDFWriter extends DefaultTreeWriter {
26
27 private Document _pdfDocument;
28
29 public PDFWriter() {
30 _pdfDocument = new Document();
31 }
32
33 @Override
34 protected void initialise(Frame start) throws IOException {
35 _format = ".pdf";
36 super.initialise(start);
37 try {
38 PdfWriter
39 .getInstance(_pdfDocument, new FileOutputStream(_filename));
40 _pdfDocument.open();
41 _pdfDocument.addCreationDate();
42 _pdfDocument.addAuthor(UserSettings.Username);
43 _pdfDocument.addCreator("Expeditee");
44 } catch (DocumentException e) {
45 e.printStackTrace();
46 throw new IOException(e.getMessage());
47 }
48 }
49
50 @Override
51 protected void writeTitle(Text toWrite, List<Item> items)
52 throws IOException {
53 _pdfDocument.addTitle(toWrite.getText());
54 writeText(toWrite);
55 }
56
57 @Override
58 protected String finaliseTree() throws IOException {
59 _pdfDocument.close();
60 return super.finaliseTree();
61 }
62
63 @Override
64 protected void writeStartLink(Item linker) throws IOException {
65 }
66
67 @Override
68 protected void writeEndLink(Item linker) throws IOException {
69 }
70
71 @Override
72 protected void writeText(Text text) throws IOException {
73 try {
74
75 _pdfDocument.add(new Paragraph(text.getText(), FontFactory.getFont(
76 Conversion.getPdfFont(text.getFamily()), text.getSize(),
77 text.getPaintFont().getStyle(), text.getColor())));
78 } catch (DocumentException e) {
79 // TODO Auto-generated catch block
80 e.printStackTrace();
81 }
82 }
83
84 @Override
85 protected void writePicture(Picture pic) throws IOException {
86 Image image = pic.getCroppedImage();
87 try {
88 _pdfDocument.add(com.lowagie.text.Image.getInstance(image, null));
89 } catch (DocumentException e) {
90 // TODO Auto-generated catch block
91 e.printStackTrace();
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.