Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Java in General
pdfexport
edi ramani
Greenhorn
Posts: 1
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello,
I have written one Class PDFExporter
package export; import java.awt.Color; import java.io.IOException; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; import entities.Kunde; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.Font; import com.lowagie.text.FontFactory; import com.lowagie.text.HeaderFooter; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfWriter; public class PDFExporter { private static Logger log = Logger.getLogger(PDFExporter.class); private static Document document = new Document(); //TABELA private static void addToTable(PdfPTable table, Font font, String... str) { for (String s : str) { PdfPCell cell = new PdfPCell(new Paragraph(s, font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } } //TABELA PER KUNDE public static void listPdfExportKunde(OutputStream out, List<Kunde> list) { PdfPTable table = new PdfPTable(7); table.getDefaultCell().setBorderColor(new Color(0, 0, 0)); table.setWidthPercentage(100); Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD); Font font1 = FontFactory.getFont(FontFactory.HELVETICA, 10); addToTable(table, font, "KundeNummer", "Name", "Adresse", "Postleitzahl", "Ort"); for (Kunde k : list) { table.addCell(new Paragraph(k.getKundeNummer().toString(),font1)); table.addCell(new Paragraph(k.getName(), font1)); table.addCell(new Paragraph(k.getAdresse(), font1)); table.addCell(new Paragraph(k.getPostleitzahl().toString(),font1)); table.addCell(new Paragraph(k.getOrt(), font1)); Kunde(out, "Ausdruck Kunden", PageSize.A4.rotate()); try { document.add(new Paragraph(" ", FontFactory.getFont( FontFactory.HELVETICA, 10, Font.BOLDITALIC, new Color(0, 0, 0)))); document.add(table); document.add(new Paragraph(" ")); Impressum(); } catch (DocumentException e) { e.printStackTrace(); } log.info("Kunden-Liste erfolgreich exportiert!"); document.close(); } } private static void Kunde(OutputStream out, String titel, Rectangle format) { try { document = new Document(format); // PDF-Datei befüllen PdfWriter.getInstance(document, out); if (out != null) { // Metainformationen document.addTitle("Firma JONT - " + titel); document.addAuthor("Gazmendi"); // Kopf- / Fusszeile HeaderFooter header = new HeaderFooter(new Phrase("JONT - " + titel), false); HeaderFooter footer = new HeaderFooter(new Phrase("Faqa "), true); footer.setAlignment(Element.ALIGN_RIGHT); document.setHeader(header); document.setFooter(footer); document.open(); // Dokumentenkopf PdfPTable table = new PdfPTable(2); PdfPTable table1 = new PdfPTable(1); table1.getDefaultCell() .setBorderColor(new Color(255, 255, 255)); table.addCell(Image.getInstance(ClassLoader .getSystemClassLoader().getResource("logo.jpg"))); table1.addCell(new Paragraph("Dokument erstellt am: " + new SimpleDateFormat("dd.MM.yyyy, HH:mm") .format(new Date()) + " Uhr.", FontFactory .getFont(FontFactory.HELVETICA, 10))); table1.addCell(new Paragraph( "---------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10))); table.addCell(table1); table.getDefaultCell().setBorderColor(new Color(0, 0, 0)); table.setWidthPercentage(100); document.add(table); document.add(new Paragraph(" ")); Paragraph title1 = new Paragraph(titel, FontFactory.getFont( FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color( 0, 0, 0))); document.add(title1); } } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private static void Impressum() { Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD); PdfPTable table = new PdfPTable(1); PdfPCell cell = new PdfPCell(); table.setWidthPercentage(50); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setBorderColor(new Color(255, 255, 255)); table.addCell(new Paragraph(" ", FontFactory.getFont( FontFactory.HELVETICA, 20))); cell = new PdfPCell( new Paragraph( "--------------------------------" + "----------------------", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(new Color(255, 255, 255)); table.addCell(cell); try { document.add(table); } catch (DocumentException e) { e.printStackTrace(); } } }
I have made another Class HauptFenster
package gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.List; import javax.swing.BorderFactory; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.LayoutStyle; import javax.swing.border.BevelBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Vector; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; import org.apache.log4j.Logger; import db.HSQLDb; import db.dao.KundeDao; import db.dao.WeinflascheDao; import entities.Kunde; import export.*; import start.Start; public class HauptFenster extends JFrame { // Labels&ComboBoxs private JLabel tabela = new JLabel(" Tabelle:"); private JComboBox chooseTable = null; private JLabel sortiertNach = new JLabel("Sortiren nach:"); private JComboBox chooseSortAtribut = null; // Buttons private JButton hinzufuegen = new JButton(" Hinzufügen "); private JButton bearbeiten = new JButton("Bearbeiten"); private JButton loeschen = new JButton(" Loeschen "); private JButton suchen = new JButton(" Suchen "); private JButton pdf = new JButton(" PDF "); private JButton aktualisieren = new JButton("Aktualisieren"); private JButton anzalKunde = new JButton("Anzahl Kunde"); private JButton beenden = new JButton(" Beenden "); private JLabel leereZeile = new JLabel(" "); private String[] spaltenName = { "KundeNummer", "Name", "Adresse", "Postleitzahl", "Ort", "Alkoholiker" }; private Object[][] data = { { "", "", "", "", "", "" } }; private JTable tabelle = new JTable(data, spaltenName); private JScrollPane scrl_tabelle = new JScrollPane(tabelle); private static Logger logger = Logger.getLogger(Start.class); private void exit() { HSQLDb.closeConnection(); logger.info("Finisch"); System.exit(0); } public HauptFenster() { setTitle("Weinhändler"); setLayout(new GridBagLayout()); setLocation(250, 100); setResizable(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { exit(); } }); GridBagConstraints c = new GridBagConstraints();// wichtig! c.gridx = 0; c.gridy = 0; getContentPane().add(tabela, c); chooseTable = new JComboBox(); chooseTable.addItem("Kunde"); chooseTable.addItem("Weinflasche");c.gridx = 4; c.gridy = 2; c.anchor = GridBagConstraints.CENTER; getContentPane().add(pdf,c); pdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pdfActionPerformed(evt); } }); tabelle.addMouseListener(new MouseAdapter() {// kjo eshte kur // buttonave do tu // ndrohet statusi public void mouseClicked(MouseEvent e) { updateButtonStatus(); } }); pack(); setVisible(true); } public void pdfActionPerformed(ActionEvent evt){ }
and my problem is,how can i write public void pdfActionPerformed(ActionEvent evt),when I click the button PDF,my dates to be exported as PDF!
please help me!
Campbell Ritchie
Marshal
Posts: 79707
381
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Welcome to the Ranch
That question is too difficult for “beginning”, so I shall move it.
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
iText with Java: PDF nested table issues
web dynpro application
header overlapping with data in generated pdf document
FieldPositioningEvents in iText fails on multiple pages
PdfPTable
More...