Java සිංහල අකුරු

dnet

Active member
  • Dec 14, 2010
    178
    80
    28
    මං හදපු Pos System එකක් තියනවා. Java වලින් හදලා තියෙන්නේ Advance System එකක්. දැනට අපේ Shop එකේ කිසි අවුලක් නැතුව වැඩ. මට මේක දැන් අනිත් අයටත් විකුනන්න අදහසක් තියනවා. ගැටළුව තියෙන්නේ සමහර කඩ වල සිංහලෙන්නේ Bill එක දෙන්නේ. මං Java වලින් හදපු එකේ සිංහල අකුරු හරියට එන්නේ නෑ. ශ්‍රී වගේ අකුරු වදින්නේ ශ්ර විදිහට. මේකට විසදුමක් තියනවාද ?. IReport වලත් සිංහල අවුල්.

    නැත්තම් VB.net වගේ එකකින් අයෙත් හදන එකද හොද. Java to Vb.net Converter එකක් Use කරන එක හොදයිද.
     

    dnet

    Active member
  • Dec 14, 2010
    178
    80
    28
    PDF ekak generate karala print kaloth moko? 🤔
    ------ Post added on Nov 15, 2024 at 10:15 PM
    iReports වලත් සිංහල අකුරු හරියට වැඩ කරන්නේ නැති එක තමා ගැටළුව

    Bump
    ------ Post added on Nov 16, 2024 at 7:58 AM
     

    KandyMalli

    Well-known member
  • Feb 15, 2018
    4,376
    4,004
    113
    Try this

    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.
     
    • Like
    Reactions: dnet

    dnet

    Active member
  • Dec 14, 2010
    178
    80
    28
    Try this

    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.
    මේක FM Fonts වලින් කරොත් ගැටළුවක් නැහැ නේද ? එතකොට Unicode ගැටළු එන්නේ නැහැ නේද
     
    • Like
    Reactions: MihiCherub

    KandyMalli

    Well-known member
  • Feb 15, 2018
    4,376
    4,004
    113
    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!
     
    • Like
    Reactions: dnet and Asmodeus

    dnet

    Active member
  • Dec 14, 2010
    178
    80
    28
    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!
    Thanks
     

    dnet

    Active member
  • Dec 14, 2010
    178
    80
    28
    oka unicode danne nathuwa karapan. fm hari dl hari fonts walin. mekema ekek hadapu Zsrilanka kiyala software ekak thiyenawa. eken type karapan unicode wagemai. customer tath eka install karala dipan

    https://elakiri.com/threads/මගේ-fm-dl-fonts-sinhala-typing-software-එක-සිංහල-ඉගෙන-ගන්න-ගමන්-singlish-වලින්-ලේසියෙන්-sinhala-type-කරමුද.1994719/
    එහෙම තමයි කරන්න හිතන් ඉන්නේ දැන් FM fonts දාලා.