PDF IText-7 layout support for Persian language? - itext

I have tried lots of ways to use PDF Itext-7 with the Persian language, but none of the ways was success.
The way I have tried:
PdfFont font = PdfFontFactory.createFont("fonts/NotoSansArabic-Regular.ttf", PdfEncodings.IDENTITY_H, true/false);
Paragraph paragraph = new Paragraph();
paragraph.setFont(font);
//paragraph.setTextAlignment(TextAlignment.LEFT);
paragraph.add("فارسی");//.setFontScript(Character.UnicodeScript.ARABIC);
AND
final FontSet set = new FontSet();
set.addFont("fonts/NotoSansArabic-Regular.ttf");
set.addFont("fonts/FreeSans.ttf");
document.setFontProvider(new FontProvider(set));
...
And many more ways, but none of them solved the problem.
I am wondering such a framework even not support none English language?
OR is there anything left I did not set up?
I have used some examples from here, but also not working.
What is the solution?
Thanks!

Related

Get Font Properties From Word Document With OpenXML (.NET)

How can I get font properties from word document with OpenXML?
var para = wordDocument.MainDocumentPart.RootElement.Descendants<Paragraph>().ToList();
With the code above, I can only get the paragraphs themselves.
Only font insertion shown in forum.
Please help me..
Although i don't really know, what 'font-properties' means in this context, my answer is: it depends.
styles (templates defining paragraph or run format, etc) are set in MainDocumentPart.StyleDefinitionsPart
formatting properties are defined in RunProperties or ParagraphProperties (applied styles can also be found here)
So if you like to retrieve certain formatting properties, you will have to look inside the openxml-package.

iText arabic RTL characters not shaped

I am creating a PDF with Arabic & latin mixed data. The arabic comes out unshaped. The code i have is like the Ligatures2 example:
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100);
table.getDefaultCell().setBorder(0);
table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(0, 0, 1500, 1500);
column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
document.add(new Paragraph(line, font));
column.go();
I'm sorry to disagree with you, but your code is nothing like the Ligatures2 example:
You create a PdfPTable object, but you don't add any content to it. You don't add the table to the document.
You create a ColumnText object, but you don't add any content to it. When you perform go() nothing happens.
If we remove all the unused lines from your code snippet, this is what remains:
document.add(new Paragraph(line, font));
As documented in the book that comes with the Ligatures2 example you refer to, this code, this is insufficient to render Arabic.
One way to fix your code would be to do something like this:
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(36, 36, 559, 806);
column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
document.addElement(new Paragraph(line, font));
column.go();
Note that I am making an assumption here: I assume that your page size is A4. In your code, you defined the rectangle of the column like this:
column.setSimpleColumn(0, 0, 1500, 1500);
That's a very strange size.
Side-note:
Please avoid to copy/paste code from examples and then break those examples without reading the documentation that comes with the examples.
I see that (1.) this question isn't the first example of this behavior, and (2.) you don't provide feedback when somebody answers your question. If a question is solved correctly, you should do the right thing and accept the answer!
https://stackoverflow.com/questions/27941538/illegalpdfsyntaxexception-unbalanced-begin-end-operators: no feedback whatsoever on the counter-question. The question can't be answered due to lack of information.
IText font not subsetting or embedding: question reveals a lack of respect for the documentation. It was answered correctly, but the answer was not accepted.
JZOS and iText on z/OS: strange question and no feedback on the answer that was given. Did it solve the problem? One can only guess.

iTextSharp embedded cyrillic font in Adobe Reader

My PDF is not displayed properly with Adobe Reader. It is fine with other PDF readers so this must be a syntax issue, as I've heard that Adobe Reader is more strict with PDF syntax. The fonts seem to be twice as big as they should be but the horizontal spacing is correct, this makes the fonts overlap with each other.
This is my C# code (font creation code is at the end of this post).
Font officialUseFont = EmbeddedResources.CreateDesignFont(webform);
PdfContentByte officialUseCanvas = _stamper.GetOverContent(3);
ColumnText.ShowTextAligned(officialUseCanvas, Element.ALIGN_CENTER, new Phrase(webform.Text, officialUseFont), posX, posY, 0);
I'm using iTextSharp 5.4.2.0 with runtime v2.0.50727.
I must have embedded some fonts because the Cyrillic alphabet and Chinese alphabets were not working before but they work now. The form fields which exist in the PDF are populated with Cyrillic characters without any problems, it's only the canvas which causes the issue.
public Font CreateDesignFont(IForm webform)
{
var baseFont = GetBaseFont(fontNamespace.Length, selectedFontName);
return new Font(baseFont, webform.FontSize);
}
private static BaseFont GetBaseFont(int fontNamespaceLength, string selectedFontName)
{
byte[] fontBuffer;
using (var stream = (Assembly.GetExecutingAssembly().GetManifestResourceStream(selectedFontName)))
{
fontBuffer = new byte[stream.Length];
stream.Read(fontBuffer, 0, fontBuffer.Length);
}
var fontfile = selectedFontName.Substring(fontNamespaceLength);
var customFont = BaseFont.CreateFont(fontfile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, BaseFont.CACHED, fontBuffer, null);
return customFont;
}
The code snippet you're providing isn't sufficient. The problem originates in whatever happens when you do EmbeddedResources.CreateDesignFont(webform);
If the font isn't shown in Adobe Reader, you didn't embed the font. Maybe you think you do, but judging by the behavior of the PDF viewers, you didn't.
Can you provide a screen shot of the Document Properties, more specifically the "Fonts" tab?
UPDATE
I tried writing my own code snippet, and I wasn't able to reproduce the problem. So I took another look at your code, and I saw that you're caching the font, but you've already used ArialMT using the WINANSI encoding to fill out the fields on page 1. IMO (I don't have the time to check) that's incompatible with using the same font from cache using IDENTITY_H. If you don't cache the font (why would you? you're passing the fontBuffer! no need to store the font in a cache if you're already caching the font bytes yourself), your problem will probably be solved.
The problem stemmed from the fact I was using .otf fonts. When I changed to .ttf the problem disappeared.

HTML Tags in GWT internationalization

I'm using the internationalization of GWT to manage the different languages of my application. I have a text where some words are in bold. Therefore I did the same thing as described here.
#DefaultMessage("Welcome back, {startBold,<b>}{0}{endBold,</b>}")
String testMessage(String name);
However, when I run the application, I get "Welcome back, < b>Peter< /b>" (the HTML is written out and not interpreted. I intentionally put a space between < b so that this text editor does not interpret the html tag).
Does anyone know how to solve this issue? Many thanks in advance!
P.S.
Code fragment which gets the language string:
Label label = new Label();
label.addStyleName("intro-Text");
label.setText(new HTML(trans.testMessage(name)).getHTML());
Instead of using a Label use the HTML widget.
HTML text = new HTML();
text.addStyleName("intro-Text");
text.setHTML(trans.testMessage(name));
Hope that helps.

Does the Eclipse editor have an equivalent of Emacs's "align-regex"?

I've been using Eclipse pretty regularly for several years now, but I admit to not having explored all the esoterica it has to offer, particularly in the areas of what formatting features the editors offer.
The main thing I miss from (X)emacs is the "align-regex" command, which let me take several lines into a region and then format them so that some common pattern in all lines was aligned. The simplest example of this is a series of variable assignments:
var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();
After doing align-regex on "=", that would become:
var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();
Now, you may have your own thoughts on stylistic (ab)use of white space and alignment, etc., but that's just an example (I'm actually trying to align a different kind of mess entirely).
Can anyone tell me off-hand if there's an easy key-combo-shortcut for this in Eclipse? Or even a moderately-tricky one?
You can set the formatter to do this:
Preferences -> Java -> Code Style -> Formatter. Click 'Edit' on the profile (you may need to make a new one since you can't edit the default).
In the indentation section select 'Align fields with columns'.
Then, in your code CTRL+SHIFT+F will run that formatter.
That will of course run all the other rules, so you may want to peruse the various options here.
Version 2.8.7 of the Emacs+ plugin now supplies a fairly complete align-regexp implementation in Eclipse
If you wish to do something more complex than just aligning fields (or anything else the Eclipse code formatter offers you) you are pretty much left with having to write your own plugin.
columns4eclipse is a nice option. It is an Eclipse plugin that allow you to do the alignments you mention in your question. I use it with Eclipse 4.3 and 4.5, it works well. I had made a gif video showing its use but my answer got deleted by a mod, so I let you try and see by yourself.
This plug-in does exactly what you want: OCDFormat
It works in all text files, not only Java.