iText support for HIndi and Arabic - itext

Our project needs dynamic PDF generation in 6 languages which consists of Hindi and Arabic. iText works brilliantly for other languages except these two. Can someone let me know if current version of iText(5.5.5) have ligature implementation for Hindi and Arabic?

about Arabic language:
I understand you face one of two problems:
the Arabic words don't appear.
the Arabic words appears like :
the solution is:
first: update your itext 5.5.8 to itext 7 implementation:
https://search.maven.org/artifact/com.itextpdf/itext7-core/7.2.2/pom
then edit your code:
String font = "your Arabic font";
PdfFontFactory.register(font);
FontProgram fontProgram = FontProgramFactory.createFont(font, true);
PdfFont f = PdfFontFactory.createFont(fontProgram, PdfEncodings.IDENTITY_H);
LanguageProcessor languageProcessor = new ArabicLigaturizer();
com.itextpdf.kernel.pdf.PdfDocument tempPdfDoc = new
com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(pdfFile.getPath()), TempWriter);
com.itextpdf.layout.Document TempDoc = new
com.itextpdf.layout.Document(tempPdfDoc);
com.itextpdf.layout.element.Paragraph paragraph0 = new
com.itextpdf.layout.element.Paragraph(languageProcessor.process("الاستماره الالكترونية"))
.setFont(f).setBaseDirection(BaseDirection.RIGHT_TO_LEFT)
.setFontSize(15);
//and look how i useded setBaseDirection & and don't use TextAlignment ,it will work without it

Related

Flutter Speech to Text in Arabic Language

Is there is a way to convert speech into text using flutter (specially if the the speech in Arabic and also I want the resulted text in Arabic) I've found many resources that explains how speech to text in English but not Arabic so I hope anyone can help me.
Use Flutter speech_to_text library.
to change language, localeId = the ID of the Arabic language on this device:
var locales = await speech.locales();
// Some UI or other code to select a locale from the list
// resulting in an index, selectedLocale
var selectedLocale = locales[selectedLocale];
speech.listen(
onResult: resultListener,
localeId: selectedLocale.localeId,
);

How to generate PDF in Hebrew? currently the PDF is generated empty

I'm using iTextSharp 5.5.13 and when i try to generate the PDF with Hebrew it comes out empty.
this is my code: I'm i doing something wrong?
public byte[] GenerateIvhunPdf(FinalIvhunSolution ivhun)
{
byte[] pdfBytes;
using (var mem = new MemoryStream())
{
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, mem);
writer.PageEvent = new MyHeaderNFooter();
document.Open();
var font = new
Font(BaseFont.CreateFont("C:\\Downloads\\fonts\\Rubik-Light.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 14);
Paragraph p = new Paragraph("פסקת פתיחה")
{
Alignment = Element.ALIGN_RIGHT
};
PdfPTable table = new PdfPTable(2)
{
RunDirection = PdfWriter.RUN_DIRECTION_RTL
};
PdfPCell cell = new PdfPCell(new Phrase("מזהה", font));
cell.BackgroundColor = BaseColor.BLACK;
table.AddCell(cell);
document.Add(p);
document.Add(table);
document.Close();
pdfBytes = mem.ToArray();
}
return pdfBytes;
}
The PDF comes out blank
I changed a few details of your code, and now I get this:
My changes:
Embedding the font
As I don't have Rubik installed on my system, I have to embed the font into the PDF to have a chance to see anything. Thus, I replaced BaseFont.NOT_EMBEDDED by BaseFont.EMBEDDED when creating the var font:
var font = new Font(BaseFont.CreateFont("Rubik-Light.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 14);
Making the Paragraph kind of work
You create the Paragraph p without specifying a font. Thus, a default font with default encoding is used. The default encoding is WinAnsiEncoding which is Latin1-like, so no Hebrew characters can be represented. I added your Rubik font instance to the Paragraph p creation:
Paragraph p = new Paragraph("פסקת פתיחה", font)
{
Alignment = Element.ALIGN_RIGHT
};
Et voilà, the writing appears.
iText developers often have communicated that in iText 5.x and earlier right-to-left scripts are only supported properly in certain contexts, e.g. in tables, but not in others like paragraphs immediately added to the document. As your Paragraph p is added immediately to the Document document, its letters appear in the wrong order in the output.
Making the PdfPTable work
You defined the PdfPTable table to have two columns (new PdfPTable(2)) but then you added only one cell. Thus, table contains not even a single complete row. iText, therefore, draws nothing when it is added to the document.
I changed the definition of table to have a single column only:
PdfPTable table = new PdfPTable(1)
{
RunDirection = PdfWriter.RUN_DIRECTION_RTL
};
Furthermore, I commented out the line setting the cell background to black because usually it is difficult to read black on black:
PdfPCell cell = new PdfPCell(new Phrase("מזהה", font));
//cell.BackgroundColor = BaseColor.BLACK;
table.AddCell(cell);
And again the writing appears.
Properly downloading the font
Another possible obstacle is that when downloading the font from the URL you gave — https://fonts.google.com/selection?selection.family=Rubik — one can see in the customization tab of the selection drawer that by default only Latin characters are included in the download, in particular not Hebrew ones:
I tested with a font file I downloaded with all language options enabled:

C# How can I Coppy All Things in RichTextBox?

I have a richTextBox and I add text and image. Text are not the same color and font. I want to convert to all things for doc file. I am using this codes for this.
wordeaktar.Application wordapp = new wordeaktar.Application();
wordapp.Visible = true;
wordeaktar.Document worddoc;
object wordobj = System.Reflection.Missing.Value;
worddoc = wordapp.Documents.Add(ref wordobj);
wordapp.Selection.TypeText(richTextBox1.Text);
wordapp = null;
enter image description here
This is the image of my richTextBox. How can I do that?
#Gserg's Answer is right!
"richTextBox1.SelectAll(); richTextBox1.Copy(); worddoc.Range().Paste();. However if you simply richTextBox1.SaveFile("...", RichTextBoxStreamType.RichText), Word will be perfectly happy with that. – GSerg"

How did NPM create the border for their update message?

I'm assuming they used unicode characters to render the yellow box around the update message.
What characters were used and does it look the same on all platforms?
How did NPM create the border for their update message?
NPM uses npmlog to print to the console, and npmlog utilizes console-control-strings & gauge.
console-control-strings mostly offers convenience functions for moving the cursor around the line and coloring the text.
gauge provides the progress bar and spinner and a way to style them.
What characters were used and does it look the same on all platforms?
Unicode box-drawing characters are used for the border characters. I didn't research the exact unicode characters that NPM uses. Assuming that the terminal/platform is implemented to support unicode and, doesn't override the standard charset with its own characters (ie. emojis), I don't see why it wouldn't look the same across platform.
The below snippet unicode characters don't match exactly. Instead, it demonstrates how to use control-control-strings to print something close to what NPM outputs. I'm sure with enough tinkering you could get it to be exact.
const control = require('console-control-strings')
let title = `${control.color('cyan')}Update available 5.0.3 \u2192 5.0.4${control.color('reset')}`
let subtitle = `Run ${control.color('cyan')} npm i -g npm ${control.color('reset')}`
let borderWidth = (title.length > subtitle.length ? title.length : subtitle.length)
let topLeftCorner = '\u256D'
let topRightCorner = '\u256E'
let btmRightCorner = '\u256F'
let btmLeftCorner = '\u2570'
let border = [...Array(borderWidth)].map(() => { return '\u2500' }).join('')
let topBorder = `${control.nextLine()}${control.color('yellow')}${topLeftCorner}${border}${topRightCorner}${control.color('reset')}`
let btmBorder = `${control.nextLine()}${control.color('yellow')}${btmLeftCorner}${border}${btmRightCorner}${control.color('reset')}`
let lineWrapper = `${control.color('yellow')}\u2502${control.color('reset')}`
console.log(topBorder)
console.log(`${lineWrapper}${control.forward(borderWidth)}${lineWrapper}`)
console.log(`${control.nextLine()}${lineWrapper}${control.forward(4)}${title}${control.forward(5)}${lineWrapper}`)
console.log(`${lineWrapper}${control.forward(11)}${subtitle}${control.forward(10)}${lineWrapper}`)
console.log(`${lineWrapper}${control.forward(borderWidth)}${lineWrapper}`)
console.log(`${btmBorder}${control.color('reset')}`)

special characters in droidText - Android

I need to use special characters like "ç", "á"... but nothing works.
Part of the code:
Paragraph title = new Paragraph();
com.lowagie.text.Font fontTitle= FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 15, Font.BOLD);
title.add(new Paragraph("ç", fontTtile));
document.add(title);
Using IDENTITY_H and EMBEDDED the pdf doesn't work, but if I just use ("Arial", 15, Font.BOLD) it works (special characters don't).
How can I fix it?
Thanks.