/** * Creates a PDF document. * * @param filename the path to the new PDF document * @throws DocumentException * @throws IOException * @throws BadLocationException */ public void createPdf(String filename) throws IOException, DocumentException, BadLocationException { Document document = new Document(new Rectangle(300, 150)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte canvas = writer.getDirectContent(); DefaultFontMapper mapper = new DefaultFontMapper(); BaseFontParameters parameters = new BaseFontParameters("c:/windows/fonts/msgothic.ttc,1"); parameters.encoding = BaseFont.IDENTITY_H; mapper.putName("MS PGothic", parameters); Graphics2D g2 = canvas.createGraphics(300, 150, mapper); JTextPane text = TextExample4.createTextPane(); text.setSize(new Dimension(300, 150)); text.print(g2); g2.dispose(); document.close(); }