// // Copyright 2020 FoxyUtils ehf. All rights reserved. // // This is a commercial product and requires a license to operate. // A trial license can be obtained at https://unidoc.io // // DO NOT EDIT: generated by unitwist Go source code obfuscator. // // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ // Package fjson provides support for loading PDF form field data from JSON data/files. package fjson ;import (_f "encoding/json";_fgd "github.com/unidoc/unipdf/v3/core";_ad "github.com/unidoc/unipdf/v3/model";_e "io";_fg "os";); // LoadFromPDF loads form field data from a PDF. func LoadFromPDF (rs _e .ReadSeeker )(*FieldData ,error ){_ab ,_fd :=_ad .NewPdfReader (rs );if _fd !=nil {return nil ,_fd ;};if _ab .AcroForm ==nil {return nil ,nil ;};var _ga []fieldValue ;_gd :=_ab .AcroForm .AllFields ();for _ ,_aac :=range _gd {var _gc []string ; _bf :=make (map[string ]struct{});_c ,_d :=_aac .FullName ();if _d !=nil {return nil ,_d ;};if _fda ,_ge :=_aac .V .(*_fgd .PdfObjectString );_ge {_ga =append (_ga ,fieldValue {Name :_c ,Value :_fda .Decoded ()});continue ;};var _ec string ;for _ ,_fbg :=range _aac .Annotations {_bc ,_ee :=_fgd .GetName (_fbg .AS ); if _ee {_ec =_bc .String ();};_bg ,_aba :=_fgd .GetDict (_fbg .AP );if !_aba {continue ;};_ffc ,_ :=_fgd .GetDict (_bg .Get ("\u004e"));for _ ,_gdb :=range _ffc .Keys (){_ecc :=_gdb .String ();if _ ,_aaa :=_bf [_ecc ];!_aaa {_gc =append (_gc ,_ecc );_bf [_ecc ]=struct{}{}; };};_ed ,_ :=_fgd .GetDict (_bg .Get ("\u0044"));for _ ,_gb :=range _ed .Keys (){_fe :=_gb .String ();if _ ,_bgc :=_bf [_fe ];!_bgc {_gc =append (_gc ,_fe );_bf [_fe ]=struct{}{};};};};_gag :=fieldValue {Name :_c ,Value :_ec ,Options :_gc };_ga =append (_ga ,_gag ); };_gde :=FieldData {_aa :_ga };return &_gde ,nil ;}; // LoadFromJSON loads JSON form data from `r`. func LoadFromJSON (r _e .Reader )(*FieldData ,error ){var _eg FieldData ;_b :=_f .NewDecoder (r ).Decode (&_eg ._aa );if _b !=nil {return nil ,_b ;};return &_eg ,nil ;}; // JSON returns the field data as a string in JSON format. func (_fa FieldData )JSON ()(string ,error ){_gdc ,_gcf :=_f .MarshalIndent (_fa ._aa ,"","\u0020\u0020\u0020\u0020");return string (_gdc ),_gcf ;}; // LoadFromJSONFile loads form field data from a JSON file. func LoadFromJSONFile (filePath string )(*FieldData ,error ){_g ,_fb :=_fg .Open (filePath );if _fb !=nil {return nil ,_fb ;};defer _g .Close ();return LoadFromJSON (_g );}; // FieldValues implements model.FieldValueProvider interface. func (_cf *FieldData )FieldValues ()(map[string ]_fgd .PdfObject ,error ){_gbf :=make (map[string ]_fgd .PdfObject );for _ ,_gba :=range _cf ._aa {if len (_gba .Value )> 0{_gbf [_gba .Name ]=_fgd .MakeString (_gba .Value );};};return _gbf ,nil ;}; // LoadFromPDFFile loads form field data from a PDF file. func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fge ,_db :=_fg .Open (filePath );if _db !=nil {return nil ,_db ;};defer _fge .Close ();return LoadFromPDF (_fge );}; // FieldData represents form field data loaded from JSON file. type FieldData struct{_aa []fieldValue };type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`; // Options lists allowed values if present. Options []string `json:"options,omitempty"`;};