CSV to PDF file in Java
•
Java
I tried to parse a CSV file into PDF What I have attached so far is as follows
My problem is that the file where the code ends in PDF cuts off the first line of the CSV file. I can't figure out why Basically, I want a PDF version of a CFV file that is not manipulated I'm sure this is a problem. How do I add data to iText PDF, but I really can't find another way to forward the array to PDF file Any ideas about fixing code or simpler?
public static void main(String[] args) throws IOException,DocumentException { @SuppressWarnings("resource") CSVReader reader = new CSVReader(new FileReader("data1.csv"),'\''); String [] nextLine; while ((nextLine = reader.readNext()) != null) { // nextLine[] is an array of values from the line System.out.println(nextLine[0]); String test; test = nextLine[0]; // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document,new FileOutputStream("Test.pdf")); // step 3 document.open(); // step 4 PdfPTable arrayTable3 = new PdfPTable(1); arrayTable3.setHorizontalAlignment(Element.ALIGN_LEFT); Phrase phrase1 = new Phrase(nextLine[0]); PdfPCell arrayDetailsCell3 = new PdfPCell(); arrayDetailsCell3.addElement(phrase1); // Add the cell to the table arrayTable3.addCell(arrayDetailsCell3); // Add table to the document document.add(arrayTable3); // step 5 document.close(); } }
CSV file: http://dl.dropbox.com/u/11365830/data1.csv Pdf file: http://dl.dropbox.com/u/11365830/Test.pdf
Solution
In csvreader Default in Java_ SKIP_ Lines is set to 0
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码