csv
ファイルを解析して。に変換しようとしていますpdf
。私がこれまでに持っているものを以下に添付します。
私の問題は、このコードで、pdfで終わるファイルがcsvファイルの最初の行で途切れてしまうことです。理由がわかりません。[添付の例]基本的に、何も操作されていないcsvファイルのpdfバージョンが欲しいです。itext pdfにデータを追加する方法に問題があると確信していますが、配列をpdfファイルに転送する別の方法を実際に見つけることはできません。コードやもっと簡単なものを修正するためのアイデアはありますか?
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ファイル:http
://dl.dropbox.com/u/11365830/data1.csv
PDFファイル:http ://dl.dropbox.com/u/11365830/Test.pdf