KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have to create a PDF file from a HTML source. Currently, I'm coping with problem concerning special (polish) characters in the output file, precisely with their lack. HTML source: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table width="100%" border="0.5" align="center" cellpadding="0" style="border-collapse:collapse; border:1px solid black; font-family:Arial, Helvetica, sans-serif; font-size:16px"> <tr> <td align="center" ><b>Test: ąęłóćńśŁÓŃĆŻŹąśżźłęó</b></td> </tr> </table> Java source: Document document = new Document(PageSize.A4, 38, 38, 50, 38); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("iTextExample.pdf")); document.open(); HTMLWorker htmlWorker = new HTMLWorker(document); htmlWorker.parse(new StringReader(readFileAsString("index.html"))); document.close(); public static String readFileAsString(String filePath) throws IOException { DataInputStream dis = new DataInputStream(new FileInputStream(filePath)); try { long len = new File(filePath).length(); if (len > Integer.MAX_VALUE) { throw new IOException("File " + filePath + " too large, was " + len + " bytes."); } byte[] bytes = new byte[(int) len]; dis.readFully(bytes); return new String(bytes, "UTF-8"); } finally { dis.close(); } } My question is: how to change default font (Helvetica) to eg. Arial Bold in whole PDF document? I've tested many examples connected with StyleSheet and none of them worked. I have to change a default font, because there's no polish characters - that's the solution I hope is going to work. Edit: class defaultFontProvider extends Fon
Tags (comma-separated)
Save Edits
Cancel