Can not Text on existing PDF file, Also can not select from ComboBoxField

Dear Aspose.Tech, I need your help:

I have a project where i need to use an existing Fillable PDF Form as input.
I need to write regular Text on this document, but it not working, text never show on final PDF…
Also i need to populate some fields in this form but when i selected an item from the combobox but it does not work, meaning it does not select anything and the final PDF output shows no selection…
Please see attached PDF. i use for input form.

My Environment: Win10, Java 8, Aspose.PDF 19.5, Eclipse 2019-03

my Code bellow:

import com.aspose.pdf.Color;
import com.aspose.pdf.ComboBoxField;
import com.aspose.pdf.Document;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.Page;
import com.aspose.pdf.Position;
import com.aspose.pdf.TextBuilder;
import com.aspose.pdf.TextFragment;

public class WriteTextOnPDF {

public static void main(String[] args) {
	com.aspose.pdf.License license = new com.aspose.pdf.License();
	// Call setLicense method to set license
	try {
		license.setLicense("Aspose.Total.Java.lic");
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	// Open a document
	String docIn = "C:\\TEMP\\PDF\\FORMMA4.pdf";
	Document pdfDocument = new Document(docIn.trim());

	Page pdfPage = pdfDocument.getPages().get_Item(1);
	// create text fragment
	TextFragment textFragment = new TextFragment("THIS IS NEW TEXT ADDED BY CODE");
	textFragment.setPosition(new Position(100, 300));

	// set text properties
	textFragment.getTextState().setFont(FontRepository.findFont("Verdana"));
	textFragment.getTextState().setFontSize(14);
	textFragment.getTextState().setForegroundColor(Color.getBlue());
	textFragment.getTextState().setBackgroundColor(Color.getGray());

	// create TextBuilder object
	TextBuilder textBuilder = new TextBuilder(pdfPage);
	// append the text fragment to the PDF page
       //THE TEXT DOES NOT WORK , DOES NOT SHOWS in FINAL PDF ???
	   textBuilder.appendText(textFragment);			

     //THIS CODE DOES NOT WORK  ???
     //I need to make a selection from ComboBox field here 
  ComboBoxField comboBoxField = (com.aspose.pdf.ComboBoxField) pdfDocument.getForm().get("form1[0].#subform[0].DropDownList1[0]");
 comboBoxField.setSelected(3);
	
	// Save the updated document
	String docOut = "C:\\TEMP\\PDF\\OUT_FORMMA4.pdf";
	pdfDocument.save(docOut);
	System.out.println("<< END OF JOB... >>");
	
}

}FormMA4.pdf (154.8 KB)

@mromero_rubinrothman_com

Thank you for contacting support.

We are afraid your source document has some restrictions set and it may not be modified with the API. We have attached a screenshot for your kind reference. Restrictions.PNG

Hi Farhan,
thank you for you answer, i see that there are restriction on my source PDF. that does not allow changes to the file.

I do have one last question for this ticket:
Can you please let me know if it may be possible to take out the restrictions of my source document and make a duplicate with all restriction removed under and save under a different name?
a sample code or a link will be great…
thank you for your help.
Marc

@mromero_rubinrothman_com

We are afraid these restrictions may not be overridden in same PDF document or its duplicate copy. One would need to create such a form from scratch with no restrictions in order to process it further.

Hi Farhan,

I can create the new PDF from scratch using aspose.java but i am using the restricted PDF as source and then i will save the new-one under another name without restrictions?

thank you,
Marc

@mromero_rubinrothman_com

Since you will be adding fields one by one and there will be no restrictions set on newly created document, you will be able to manipulate it as per your requirements.

A post was split to a new topic: Add text on specific position