Fill PDF form field with Hebrew text (RTL) - pdf

I tried to use iText 7 community to check if it supports filling PDF form fields in Hebrew. For some reason, I can't make it work.
Here is the code I'm using:
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false);
form.setGenerateAppearance(true);
form.getField("test").setValue("\u05de\u05d9\u05db\u05d0\u05dc");
form.flattenFields();
pdfDoc.close();
The PDF is a blank PDF page including only one text field with the following properties:
Font Adobe Hebrew
Text direction RTL
I tried with and without flattening fields.
When fields are not flattened, after opening the resulting PDF using Acrobat Reader, I see my field but it is empty. Only after I click on the field, the content of the field appears correctly. When I view the PDF on Chrome, the field doesn't appear (or it may be there but no text inside).
When fields are flattened, after opening the resulting PDF using Acrobat Reader, the field doesn't appear at all.
I precise that I created the PDF using Acrobat DC.
Any idea what is going on here?
EDIT: The test PDF can be downloaded from here

Try creating a font (not all fonts support IDENTITY_H, but Arial does). On windows this will look like this:
PdfFont f = PdfFontFactory.createFont("C:\\windows\\fonts\\arial.ttf", PdfEncodings.IDENTITY_H, true);
And then set the font to field:
form.getField("test").setValue("\u05de\u05d9\u05db\u05d0\u05dc").setFont(f);
This worked for me

Related

Text changed to graphics, still selectable in PDF?

I have this PDF ebook with selectable text - the handwriting - but there is no such font embedded and the letters are all different, so it's not actually a font. How is this possible?
I've worked with CorelDraw and Adobe Acrobat, but I can't understand how this works.
The left side of the picture shows the document properties, the right side shows a page of the PDF file and I selected the last 3 rows. I can copy and paste that to a text file, no problem. How was this achieved?
There are a few possibilities but the most likely is the text is being converted to outlines/paths or vectors. Some software such as Adobe InDesign and other print design apps allow you to 'flatten' a font based text into vector or paths, meaning the original font isn't required to be embedded or installed on the system. The original text data is however still present and able to be copied into a text field or word processor.

Adobe Reader doesn't show some texts generated by PDFKit

I have written a pdf generator with PDFKit. If I open the saved PDF-file with Adobe Reader some texts won't be shown. In some other PDF-viewer programs and the viewers of modern browsers all texts will be shown correctly.
Do you know somethng about that? Is it known?
Note: All texts have the standard font 'Helvetica'. So the font formatting isn't the problem (I think). The texts which won't be shown are texts set as footer and header. Maybe the coordinates of the set texts are for Adobe Reader a problem?
My simple code to add these texts:
doc.text('My text', posX, posY);
Example PDF

how do I extract the Arabic text of this PDF file correctly?

Today i tried to search a Arabic word in a PDF file that contained Arabic content.
All PDF reader soft wares cannot search any Arabic word in this PDF file.
So I dragged PDF file into Firefox browser and selected a area that contained some words by inspect elements and saw this:
hw ½oiC instead of آخرین سخن
What is type of the encoding used in this PDF file?
how can i encode this to normal text?
It's difficult to comment on the file you are looking at without seeing it but a good starting point is to try Acrobat and by either copying the text and pasting it into a text editor or doing a search for the text content will reveal if it can be extracted correctly or not.
If it can't be extracted properly then there's a good chance the font is lacking a ToUnicode entry (see Section 9.10.1 of the ISO PDF 32000-1:2008 specification for more information).

Adobe PDF Forms - Text Field displays value only when clicked on it

I have a PDF with forms defined in it.
One field in the form is a multi line text field.
The value in the text field is populated by a java program using Apache PDFBox.
The issue is when the value is of around 5 to 6 lines, the text box displays the text automatically. But if it is more than 6 lines, the text box does not display the value. I had to specifically click on the text field to display the text. If I click outside the text box again, the text disappears.
The text field is read only with Multi Line and Scrolling options enabled.
Any ideas what is causing this weird issue?
I have Adobe Acrobat Pro 11, Adobe Acrobat XI and Adobe Reader to view the files. All have the same issue.
It sounds like a typical "appearance" problem. There's no form field appearance in the field widget dictionary so when you click in the field, the raw string data is shown but when you click out there is no appearance to display so you get a blank. You can test this out by toggling the multi-line setting in the field properties in Acrobat so it generates an appearance. If that fixes it, then you the problem is the one I describe.
You can use PDFBox to set the "needs appearances" flag in the file that will tell Adobe viewers to regenerate field appearances when the file is opened but that doesn't work for all PDF viewers. To make the field value visible in all PDF viewers, it's best to generate appearances when you populate the field values.
The Datalogics PDF Java Toolkit can automatically generate appearances based on field values. Full disclosure, I represent Datalogics.

PDF with fillable form fields + "Save As" = PDF with fixed text - how?

I'm creating a PDF using iTextSharp and it contains some fillable form fields. What I need, is to somehow set it up so that when those form fields are filled in and the resulting PDF is saved (in one of the commercially-available PDF readers like Adobe's Reader), I need those form fields to be fixed text (no longer editable).
Is there any way to do this?
As a comment suggests, this sounds like "flattening the document".
The issue with that process is that it is not available in (Adobe) Reader; it would require Acrobat, or server-side help.
On the other hand, some mobile PDF viewers do actually offer flattening when saving.
The workaround for Reader is to set the fields to read-only when saving the document. You would do this in the willSave Document Action by looping through the fields and setting them to readonly.
Simply Print your document as PDF. This will flatten the file.
For this
1. Install Adobe PDF Printer or CutePDF or some similar tool.
2. From your document. Select File -> Print.
3. Select Printer as the tool you installed in Step 1.
4. Your document will be a flattened, non-editable PDF now.