You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by pp...@free.fr on 2017/05/05 12:32:32 UTC

A xfa Pdf file can not be saved as.. by 'Save as..' from Adobe Acrobat Reader.

Hi everyone,
Using the pdfbox-1.8.13.dll and c#, i fill some forms of a xfa pdf file.
It works, a filled xfa pdf file is saved from my c# codes.
But when I use the 'Save as ...' for the filled xfa pdf file unders Adobe Acrobat Reader.
The message "Adobe Acrobat Reader can just only save  an empty copy of this document. Print the modified document to keep a copy ..., blabla.." is displayed.
Does anyone have an idea to resolve that.
Thanks in advance.
BuuNguyen

My codes to fill and save a xfa pdf file :
using (PDDocument doc = PDDocument.load(nomComplet))
{
        try
        {
                doc.setAllSecurityToBeRemoved(true);
                PDDocumentCatalog pdCatalog = doc.getDocumentCatalog();
                PDAcroForm pdAcroForm = pdCatalog.getAcroForm();

                PDXFA xfa = pdAcroForm.getXFA();
                if (xfa != null)
                {
                        // Remplir les valeurs dans la copie
                        COSBase cos = xfa.getCOSObject();
                        org.w3c.dom.Document w3c_xmldoc = xfa.getDocument();
                        // lire les noeuds contenants les champs PDF 
                        List<Node> nodes = ArpXfaPDFieldHelper.getElementsChampsPdfs(w3c_xmldoc, _mainSubformname, true);
                        if (nodes.IsNullOrEmpty() == false)
                        {
                                foreach (var g in dicosChamps.GroupBy(o => o.Key.NomChampPdf))
                                {
                                        #region// Remplir d'un champs PDF Xfa à partir d'un noeud org.w3c.dom.Node
                                        // .....
                                        #endregion
                                }
                                
                                #region// enregistrer le document pdf rempli
                                String nomFichier = Path.GetFileName(nomComplet);
                                String extension = Path.GetExtension(nomComplet);
                                fichierRempli = nomComplet.Replace(nomFichier, "") + nomFichier.Replace(extension, "") + "_rempli" + extension;
                                {
                                        COSStream cosout = new COSStream(new RandomAccessBuffer());
                                        TransformerFactory.newInstance().newTransformer()
                                                .transform(new DOMSource(w3c_xmldoc), new StreamResult(cosout.createUnfilteredStream()));
                                        pdAcroForm.setXFA(new PDXFA(cosout));

                                        // Suppression des permissions afin de pouvoir toujours modifier le formulaire PDF une fois rempli.
                                        COSDictionary dico = pdCatalog.getCOSDictionary();
                                        if (dico.containsKey("Perms"))
                                        {
                                                COSDictionary permission = dico.getDictionaryObject("Perms") as COSDictionary;
                                                Boolean bUr3 = permission.containsKey("UR3");
                                                if (bUr3)
                                                {
                                                        permission.clear();
                                                }
                                        }
                                        doc.save(fichierRempli);
                                }
                                #endregion
                        }
                }
        }
        catch (Exception ex)
        {
                throw new MetierException(ex.Message);
        }
        finally
        {
                doc.close();
        }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: A xfa Pdf file can not be saved as.. by 'Save as..' from Adobe Acrobat Reader.

Posted by Karl Heinz Kremer <kh...@khk.net>.
This is a limitation built into Reader by Adobe. Since Reader XI, Adobe
allows the user to fill in and save an AcroForm (the type of forms created
in Adobe Acrobat), but this does not apply to XFA forms (forms created in
LiveCycle Designer). For these forms to be filled in saved in Reader, you
need to apply extended Reader rights in Adobe Acrobat (or the corresponding
LiveCycle server application). This cannot be done in Designer, so creating
such a form is a two step process: Create the form in Designer, then open
it in Acrobat and add the extended rights. From that point on, you can then
fill and save the file in Reader.

By using PDFBox, you are adding another potential problem: I don't know how
PDFBox will treat a reader enabled file, and if these extended rights will
survive the modifications performed by PDFBox.