Skip to content

Instantly share code, notes, and snippets.

@ogavrisevs
Created June 6, 2012 11:25
Show Gist options
  • Save ogavrisevs/2881356 to your computer and use it in GitHub Desktop.
Save ogavrisevs/2881356 to your computer and use it in GitHub Desktop.
Create pdf using iText 2.1.7 (manual add styles + unicode font )
InputStreamReader reader = new InputStreamReader(inputStream);
ByteArrayOutputStream outputStream = null;
try {
Document document = new Document();
outputStream = new ByteArrayOutputStream();
PdfWriter.getInstance(document, outputStream);
Map<String, String> pc2 = new HashMap<String, String>();
pc2.put("line-height", "115%");
pc2.put("margin-bottom", "6.0pt");
pc2.put("text-align", "center");
Map<String, String> spanc1 = new HashMap<String, String>();
spanc1.put("line-height", "115%");
spanc1.put("font-family", "\"Arial\",serif");
spanc1.put("color", "black");
spanc1.put("letter-spacing", "10pt");
StyleSheet styles = new StyleSheet();
styles.loadTagStyle("p", pc2);
styles.loadTagStyle("span", spanc1);
BaseFont bf = BaseFont.createFont( "arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 12);
document.open();
document.add(new Paragraph(" Atsižvelgiant į pirmiau nurodytą Bendrovės teisėtą interesą bei si" , font));
document.add(new LineSeparator(0.5f, 100, null, 0, -5));
document.close();
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
document.close();
htmlWorker.setStyleSheet(styles);
htmlWorker.parse(reader);
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
@hantaekyung
Copy link

gg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment