-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Yuki YOSHIDA <yoshida@sports-it.jp>
- Loading branch information
1 parent
cb2ed37
commit cd7c591
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
38 changes: 38 additions & 0 deletions
38
pdf-toolbox/src/main/java/org/librepdf/openpdf/examples/fonts/languages/Japanese.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.librepdf.openpdf.examples.fonts.languages; | ||
|
||
import com.lowagie.text.Chunk; | ||
import com.lowagie.text.Document; | ||
import com.lowagie.text.Font; | ||
import com.lowagie.text.pdf.BaseFont; | ||
import com.lowagie.text.pdf.PdfWriter; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class Japanese { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// step 0: prepare font with chinese symbols | ||
BaseFont baseFont = BaseFont.createFont( | ||
Japanese.class.getClassLoader().getResource("fonts/GenShinGothic-Normal.ttf").getFile(), | ||
BaseFont.IDENTITY_H, BaseFont.EMBEDDED); | ||
Font font = new Font(baseFont, 12, Font.NORMAL); | ||
|
||
// step 1: Prepare document for japanese text | ||
Document document = new Document(); | ||
ByteArrayOutputStream pdfOutput = new ByteArrayOutputStream(); | ||
PdfWriter.getInstance(document, pdfOutput); | ||
document.open(); | ||
|
||
// step 2: we add content to the document | ||
// http://en.glyphwiki.org/wiki/u20bb7 | ||
document.add(new Chunk("\uD842\uDFB7", font)); | ||
|
||
// step 3: we close the document | ||
document.close(); | ||
|
||
Files.write(Paths.get(Japanese.class.getSimpleName() + ".pdf"), pdfOutput.toByteArray()); | ||
} | ||
} |
Binary file not shown.