LibrePDF / OpenPDF

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.
Other
3.55k stars 584 forks source link

Add motivations to add FOP #584

Closed Marco-Sulla closed 3 years ago

Marco-Sulla commented 3 years ago

Currently, in the README there's no explanation why someone should consider to add FOP too. PS: and I'm curious :D

codecracker2014 commented 3 years ago

Fop is required to process gsub table for TTF fonts. Without this glyph substitution doesn't work properly. Ex: #297

Without FOP output[Incorrect]: image

With FOP output[Correct]: image

This is due to glyph substitutions not done as per TTF file. Below is link to typography specs: https://docs.microsoft.com/en-us/typography/opentype/spec/gsub

Below is code for creating simple PDF using TTF font :

` import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter;

import java.io.FileOutputStream; import java.io.IOException;

/**

* Created by gajendra.jatav on 11/20/2019.
  */
  public class HelloWorld {
  public static void main(String[] args) {
  ```
   System.out.println("नमस्ते");

   FontFactory.register("C:\\Windows\\Fonts\\NIRMALA.TTF");
   // step 1: creation of a document-object
   Document document = new Document();
   try {
       // step 2:
       // we create a writer that listens to the document
       // and directs a PDF-stream to a file
       PdfWriter.getInstance(document,
               new FileOutputStream("D:\\workspace\\TMP\\out\\HelloWorld.pdf"));

       // step 3: we open the document
       document.open();
       // step 4: we add a paragraph to the document
       document.add(new Chunk(
               "नमस्ते",
               FontFactory.getFont("nirmala ui", "Identity-H",false,10,0,null)));
   } catch (DocumentException de) {
       System.err.println(de.getMessage());
   } catch (IOException ioe) {
       System.err.println(ioe.getMessage());
   }

   // step 5: we close the document
   document.close();
  ```

  }
  }

`

gsub processing using FOP was added in #329.

codecracker2014 commented 3 years ago

Adding above to wiki as well.

codecracker2014 commented 3 years ago

Wiki link: https://github.com/LibrePDF/OpenPDF/wiki/Multi-byte-character-language-support-with-TTF-fonts

codecracker2014 commented 3 years ago

updating main page with #585

Marco-Sulla commented 3 years ago

Is it only for this? I read also for ligatures.

codecracker2014 commented 3 years ago

Yes

vk-github18 commented 3 years ago

It is also possible to render texts needing glyph positioning, substitution and reordering using LayoutProcessor. See https://github.com/LibrePDF/OpenPDF/wiki/Accents,-DIN-91379,-non-Latin-scripts The result for the example is: image

Maybe we should also add a reference to LayoutProcessor to the README-file.

asturio commented 3 years ago

The PR is merged, can we close this? @vk-github18

vk-github18 commented 3 years ago

@asturio thanks, we can close this.