Programatically fill Government PDF (XFA dynamic)

I need to fill a form from a XFA PDF generated with LiveCycle. I’m using PDFBox 3.0.0-beta1 atm and I’ve tried iText 4.2.0 and PDFBox 2.0.28 but with no success. Anything I do to the PDF, results in a unusable PDF, it breaks the usage rights if I understood correctly. Below is my java code:

PDDocument doc = Loader.loadPDF(new File(Paths.get(FileUtils.listFiles(new File("formulare"), new PrefixFileFilter("F1129"), null).toArray()[0].toString()).toUri()));
PDDocumentCatalog catalog = doc.getDocumentCatalog();
PDAcroForm acroForm = catalog.getAcroForm();
PDXFAResource xfa1 = acroForm.getXFA();

COSStream cosout = doc.getDocument().createCOSStream();
OutputStream out = cosout.createRawOutputStream();

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();

StreamResult result = new StreamResult(out);
Document src2 = acroForm.getXFA().getDocument();

NodeList dataElements = src2.getElementsByTagName("script");
if (dataElements != null) {
  for (int i = 0; i < dataElements.getLength(); i++) {
    if (i == 45) {                   
       dataElements.item(i).setTextContent(dataElements.item(i).getTextContent() + "csDataTool.GetInstance().ExecuteImport();");
    }
  }
}

transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.transform(new DOMSource(src2), result);

PDXFAResource xfaout = new PDXFAResource(cosout);
acroForm.setXFA(xfaout);
out.close();

FileOutputStream fos = new FileOutputStream("f1129Modified.pdf");
doc.saveIncremental(fos);
doc.close();
cosout.close();
fos.flush();
fos.close();

i == 45 (that is the position of the script I want to edit)

But after I modify the XFA, the PDF opens normally but I can’t to anything in it. No errors, no warnings… but if I just do this

dataElements.item(i).setTextContent(dataElements.item(i).getTextContent());

it works perfectly…

My question is: is this even possible? To modify the javascript without breaking usage rights? If not, how can I fill this PDF?
The XML that they want to be attached has different tags than the XSD I’ve tried to find inside the XFA.

The PDF in question can be downloaded from here: https://mfinante.gov.ro/documents/2552173/2552377/31.OrdinPlataElectronic_2023_05_19_A2.0.26+.pdf/5acf3ff7-7ff1-aa2c-283c-151d49af0d8b?t=1684492636871&download=true

An example of a XML to be imported:

<?xml version="1.0"?>
<f1129 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="mfp:anaf:dgti:f1129:declaratie:v1" xmlns="mfp:anaf:dgti:f1129:declaratie:v1" versiune_pdf="A2.0.21" d_rec="0" suma_control="3644129" total_opm="245.5" nr_inregistrari="1" luna_r="12" an="2022" data_document="19.12.2022" nr_document="1234567890" nume_ip="asdasdas" adresa_ip="asddas" cui_ip="3643884" tip_ent="1">
  <rand_op nr_op="32" iban_platitor="RO38TREZ24A670503200109X" den_trezorerie="TREZORERIA  STATULUI" cod_program="0000000000" cod_angajament="AAAFSF23N4X" ind_angajament="AA2" cui_beneficiar="17460640" den_beneficiar="Your Consulting SRL" iban_beneficiar="RO38TREZ24A670503200109X" den_banca_trez="TREZORERIA  STATULUI" suma_op="245.5" explicatii="asdasd" />
</f1129>

The strangest thing is that if I use Adobe Reader PRO everything works fine. xD And I can’t find a reason why …

13

Although it is not completely clear what you want*, here are some answers to part of your questions:

My question is: is this even possible? To modify the javascript
without breaking usage rights?

It is a signature so no. If you manipulate the document you’ll break the signature. In the past there was a mechanism called “reader enabled” where you could unlock features in _dobe reader for certain documents. It might be that the document was “reader enabled” and thus allows editing XFA forms in _dobe reader. Found the following infos as part of the signature:

appRightsDocument: FullSave
appRightsForm: FillIn,Add,Delete
appRightsSignature: Modify
appRightsAnnots: 
appRightsEF: Create,Delete,Modify,Import

So to change the JavaScript you have to remove the UA-signature but then you might loose the rights to do stuff in _dobe reader.

And finally one remark about XFA: XFA is a proprietary standard of adobe and has been deprecated in PDF2.0. I would not use it for any project (ever).


*

  • Why do you want to change the javascript – what is not working for you?
  • To what JavaScript do you want to change the existing value?
  • You said that _dobe acrobat pro is working – so you have a working solution?

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật