Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
Jobreceive.com for sale
Blogerwiki
Updated:
Yesterday at 8:55 PM
Post Your Vehicle for Sale — FREE! - https://libro.lk
Kalu_Puth
Updated:
Yesterday at 7:38 PM
ඔයාගෙ Assignment හෝ Thesis එක හරියට හදාගමු
ErMurazor
Updated:
Saturday at 10:52 PM
Ad icon
BlackWall V2ray servers
hu KANNA
Updated:
Sep 23, 2026
Peppa Pig Family Plush Toy Set – 5 Characters
anil1961
Updated:
Sep 19, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Problems and Troubleshooting
Java සිංහල අකුරු
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="KandyMalli" data-source="post: 30331580" data-attributes="member: 566261"><p>To support Sinhala fonts in PDFs, you need a library that allows embedding custom fonts. Both **iText** and **Apache PDFBox** support this functionality, but you must explicitly load and embed the required Sinhala font (e.g., `FM-Abhaya`, `Iskoola Pota`, or any other Unicode-compliant font). Below are examples for both libraries.</p><p></p><p>---</p><p></p><p>### **1. Using iText with Sinhala Fonts**</p><p></p><p>iText allows embedding custom fonts, including Sinhala. </p><p></p><p>#### Maven Dependency:</p><p>```xml</p><p><dependency></p><p> <groupId>com.itextpdf</groupId></p><p> <artifactId>itext7-core</artifactId></p><p> <version>7.2.5</version> <!-- Check for the latest version --></p><p></dependency></p><p>```</p><p></p><p>#### Example Code:</p><p>```java</p><p>import com.itextpdf.kernel.pdf.PdfWriter;</p><p>import com.itextpdf.kernel.pdf.PdfDocument;</p><p>import com.itextpdf.layout.Document;</p><p>import com.itextpdf.layout.element.Paragraph;</p><p>import com.itextpdf.io.font.PdfFontFactory;</p><p>import com.itextpdf.kernel.font.PdfFont;</p><p></p><p>public class SinhalaPdfGenerator {</p><p> public static void main(String[] args) {</p><p> String dest = "sinhala_output.pdf";</p><p> String fontPath = "path/to/IskoolaPota.ttf"; // Path to Sinhala font file</p><p> try {</p><p> PdfWriter writer = new PdfWriter(dest);</p><p> PdfDocument pdf = new PdfDocument(writer);</p><p> Document document = new Document(pdf);</p><p> </p><p> // Load Sinhala font</p><p> PdfFont sinhalaFont = PdfFontFactory.createFont(fontPath, "Identity-H");</p><p> </p><p> // Add Sinhala text</p><p> String sinhalaText = "සිංහල අකුරු PDF එකේ";</p><p> document.add(new Paragraph(sinhalaText).setFont(sinhalaFont).setFontSize(14));</p><p> </p><p> document.close();</p><p> System.out.println("PDF with Sinhala text created: " + dest);</p><p> } catch (Exception e) {</p><p> e.printStackTrace();</p><p> }</p><p> }</p><p>}</p><p>```</p><p></p><p>---</p><p></p><p>### **2. Using Apache PDFBox with Sinhala Fonts**</p><p></p><p>Apache PDFBox also supports embedding Sinhala fonts for rendering custom text.</p><p></p><p>#### Maven Dependency:</p><p>```xml</p><p><dependency></p><p> <groupId>org.apache.pdfbox</groupId></p><p> <artifactId>pdfbox</artifactId></p><p> <version>2.0.29</version> <!-- Check for the latest version --></p><p></dependency></p><p>```</p><p></p><p>#### Example Code:</p><p>```java</p><p>import org.apache.pdfbox.pdmodel.PDDocument;</p><p>import org.apache.pdfbox.pdmodel.PDPage;</p><p>import org.apache.pdfbox.pdmodel.PDPageContentStream;</p><p>import org.apache.pdfbox.pdmodel.font.PDType0Font;</p><p></p><p>import java.io.File;</p><p></p><p>public class SinhalaPdfBoxGenerator {</p><p> public static void main(String[] args) {</p><p> String outputFile = "sinhala_output.pdf";</p><p> String fontPath = "path/to/IskoolaPota.ttf"; // Path to Sinhala font file</p><p></p><p> try (PDDocument document = new PDDocument()) {</p><p> PDPage page = new PDPage();</p><p> document.addPage(page);</p><p></p><p> // Load Sinhala font</p><p> PDType0Font sinhalaFont = PDType0Font.load(document, new File(fontPath));</p><p></p><p> try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {</p><p> contentStream.setFont(sinhalaFont, 14);</p><p> contentStream.beginText();</p><p> contentStream.newLineAtOffset(100, 700);</p><p> contentStream.showText("සිංහල අකුරු PDF එකේ");</p><p> contentStream.endText();</p><p> }</p><p></p><p> document.save(outputFile);</p><p> System.out.println("PDF with Sinhala text created: " + outputFile);</p><p> } catch (Exception e) {</p><p> e.printStackTrace();</p><p> }</p><p> }</p><p>}</p><p>```</p><p></p><p>---</p><p></p><p>### **3. Notes on Sinhala Fonts**</p><p>1. **Use Unicode-Compliant Fonts**: Ensure the font supports Sinhala characters (e.g., `Iskoola Pota`, `FM-Abhaya`).</p><p>2. **Embed the Font**: Always embed the font using the provided methods to ensure compatibility across devices.</p><p>3. **Path to Font File**: Replace `"path/to/IskoolaPota.ttf"` with the actual path to your Sinhala font file.</p><p></p><p>### Comparison:</p><p>- **iText**: Offers better support for advanced PDF features, making it ideal for complex projects.</p><p>- **PDFBox**: Lightweight and simple, suitable for straightforward PDFs.</p><p></p><p>Let me know if you need further assistance!</p></blockquote><p></p>
[QUOTE="KandyMalli, post: 30331580, member: 566261"] To support Sinhala fonts in PDFs, you need a library that allows embedding custom fonts. Both **iText** and **Apache PDFBox** support this functionality, but you must explicitly load and embed the required Sinhala font (e.g., `FM-Abhaya`, `Iskoola Pota`, or any other Unicode-compliant font). Below are examples for both libraries. --- ### **1. Using iText with Sinhala Fonts** iText allows embedding custom fonts, including Sinhala. #### Maven Dependency: ```xml <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext7-core</artifactId> <version>7.2.5</version> <!-- Check for the latest version --> </dependency> ``` #### Example Code: ```java import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.layout.Document; import com.itextpdf.layout.element.Paragraph; import com.itextpdf.io.font.PdfFontFactory; import com.itextpdf.kernel.font.PdfFont; public class SinhalaPdfGenerator { public static void main(String[] args) { String dest = "sinhala_output.pdf"; String fontPath = "path/to/IskoolaPota.ttf"; // Path to Sinhala font file try { PdfWriter writer = new PdfWriter(dest); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf); // Load Sinhala font PdfFont sinhalaFont = PdfFontFactory.createFont(fontPath, "Identity-H"); // Add Sinhala text String sinhalaText = "සිංහල අකුරු PDF එකේ"; document.add(new Paragraph(sinhalaText).setFont(sinhalaFont).setFontSize(14)); document.close(); System.out.println("PDF with Sinhala text created: " + dest); } catch (Exception e) { e.printStackTrace(); } } } ``` --- ### **2. Using Apache PDFBox with Sinhala Fonts** Apache PDFBox also supports embedding Sinhala fonts for rendering custom text. #### Maven Dependency: ```xml <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.29</version> <!-- Check for the latest version --> </dependency> ``` #### Example Code: ```java import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDType0Font; import java.io.File; public class SinhalaPdfBoxGenerator { public static void main(String[] args) { String outputFile = "sinhala_output.pdf"; String fontPath = "path/to/IskoolaPota.ttf"; // Path to Sinhala font file try (PDDocument document = new PDDocument()) { PDPage page = new PDPage(); document.addPage(page); // Load Sinhala font PDType0Font sinhalaFont = PDType0Font.load(document, new File(fontPath)); try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) { contentStream.setFont(sinhalaFont, 14); contentStream.beginText(); contentStream.newLineAtOffset(100, 700); contentStream.showText("සිංහල අකුරු PDF එකේ"); contentStream.endText(); } document.save(outputFile); System.out.println("PDF with Sinhala text created: " + outputFile); } catch (Exception e) { e.printStackTrace(); } } } ``` --- ### **3. Notes on Sinhala Fonts** 1. **Use Unicode-Compliant Fonts**: Ensure the font supports Sinhala characters (e.g., `Iskoola Pota`, `FM-Abhaya`). 2. **Embed the Font**: Always embed the font using the provided methods to ensure compatibility across devices. 3. **Path to Font File**: Replace `"path/to/IskoolaPota.ttf"` with the actual path to your Sinhala font file. ### Comparison: - **iText**: Offers better support for advanced PDF features, making it ideal for complex projects. - **PDFBox**: Lightweight and simple, suitable for straightforward PDFs. Let me know if you need further assistance! [/QUOTE]
Insert quotes…
Verification
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom