|
@@ -10,9 +10,7 @@ package com.ywt.mg.core.utils;
|
|
|
import com.itextpdf.text.*;
|
|
|
import com.itextpdf.text.Font;
|
|
|
import com.itextpdf.text.Image;
|
|
|
-import com.itextpdf.text.pdf.ColumnText;
|
|
|
-import com.itextpdf.text.pdf.PdfContentByte;
|
|
|
-import com.itextpdf.text.pdf.PdfWriter;
|
|
|
+import com.itextpdf.text.pdf.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -79,11 +77,7 @@ public class GeneratePdf {
|
|
|
Phrase phrase = new Phrase(content);
|
|
|
doc.add(phrase);
|
|
|
doc.close();
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (DocumentException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
@@ -101,7 +95,11 @@ public class GeneratePdf {
|
|
|
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName));
|
|
|
doc.open();
|
|
|
doc.newPage();
|
|
|
- Phrase phrase = new Phrase(content);
|
|
|
+ // 使用宋体显示中文
|
|
|
+ String songtiFontName = "./config_file/simsun.ttc";
|
|
|
+ songtiFontName += ",1";
|
|
|
+ Font songtiFont = new Font(BaseFont.createFont(songtiFontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED));//中文简体
|
|
|
+ Phrase phrase = new Phrase(content, songtiFont);
|
|
|
doc.add(phrase);
|
|
|
for (String imagePath : imagePathList) {
|
|
|
doc.newPage();
|
|
@@ -115,11 +113,7 @@ public class GeneratePdf {
|
|
|
doc.add(png1);
|
|
|
}
|
|
|
doc.close();
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (DocumentException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|