I’m working on converting HTML to PDF.
Do you know how to specify a default font when converting html to pdf using the Spire.doc for Java library? (Korean is broken)
// html to pdf
public static void pdfConvertorDefault(String inputHtml) throws IOException {
// pdf 파일 생성
Document document = new Document();
document.setCustomFontsFolders("D:\font");
Section section = document.addSection();
section.getPageSetup().setPageSize(PageSize.A3);
// Page 방향 (Landscape: 가로, Portrait : 세로)
section.getPageSetup().setOrientation(PageOrientation.Landscape);
String htmlText = readTextFromFile(inputHtml); // inputHtml : "D:/test.html";
document.setCustomFontsFolders("D:\font"); // Font Folder 지정
//add a paragraph and append html string.
Paragraph p = section.addParagraph();
p.appendHTML(htmlText); // PDF Convertor
//Save to PDF
document.saveToFile("D://SpireDoc_ouput.pdf", FileFormat.PDF);
}
// htmlFile To String
public static String readTextFromFile(String fileName) throws IOException{
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader(fileName));
String content = null;
while ((content = br.readLine()) != null) {
sb.append(content);
}
return sb.toString();
}