Add TextBoxField Read Only without Cursor or Movable Label on Adobe Edit using Aspose.PDF for Java

Hi,

The requirement is having the labels and corresponding value against it, with all the labels movable on PDF with Edit option on Adobe.

So my question is, how would I make TextBoxField without cursor and read only. I am able to do read only but I want to get rid of cursor in it, to avoid the confusion for the user because it is just a label.

If that is not possible with TextBoxField, is there any other option available in Aspose PDF lib that shows the label but when user use Edit feature of Adobe, that allow them to drag and place as per user location within PDF.

I am looking for this in Java language.

If you have any question, please let me know.

Thanks

@darshpatel

You may use FreeTextAnnotation and set its flags as AnnotationFlags.LockedContents to make it read-only:

Pdf.Document doc = new Pdf.Document();
doc.Pages.Add();
Aspose.Pdf.Rectangle rect = new Rectangle(0, 0, 100, 100);
DefaultAppearance appearance = new DefaultAppearance("Arial", 14, System.Drawing.Color.Black);
FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(doc.Pages[1], rect, appearance);
freeTextAnnotation.Contents = "text in the box";
freeTextAnnotation.Color = Aspose.Pdf.Color.Red;
freeTextAnnotation.Border.Width = 2;
freeTextAnnotation.Flags = AnnotationFlags.LockedContents;
doc.Pages[1].Annotations.Add(freeTextAnnotation);
doc.Save(dataDir + "sampleoutput.pdf");

@asad.ali

I guess, snippet doesn’t look like a Java code and I requested for Java language snippet.

I tried to play and change it to Java but not working, so can you please provide snippet for Java.

Thanks

@darshpatel

Please check following Java Code snippet to add free text annotation:

Document doc = new Document();
doc.getPages().add();
Rectangle rect = new Rectangle(0, 0, 100, 100);
DefaultAppearance appearance = new DefaultAppearance("Arial", 14, java.awt.Color.black);
FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(doc.getPages().get_Item(1), rect, appearance);
freeTextAnnotation.setContents("text in the box");
freeTextAnnotation.setColor(Color.getRed());
freeTextAnnotation.getBorder().setWidth(2);
freeTextAnnotation.setFlags(AnnotationFlags.LockedContents);
doc.getPages().get_Item(1).getAnnotations().add(freeTextAnnotation);
doc.save(dataDir + "sampleoutput.pdf");

@asad.ali

Thanks for response.

I tried the code and it does allow to move label even user is not in edit mode of Adobe, that is not the requirement.

Requirement is to allow user to move label only when user is in Edit mode of Adobe, and not general PDF view screen.

I hope that is clear enough for you, if you need more information, please let me know.

Thanks

@darshpatel

Thanks for sharing more details.

We have create an investigation ticket as PDFJAVA-39191 in our issue tracking system for further investigation on your requirements. We will check the feasibility in details and keep you informed with the status of ticket resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.