All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDFDoc.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPPDFPDFDoc
6 #define PDFTRON_H_CPPPDFPDFDoc
7 
8 #include <Common/BasicTypes.h>
9 #include <FDF/FDFDoc.h>
10 #include <PDF/PDFDocInfo.h>
11 #include <PDF/PageLabel.h>
12 //#include <PDF/OCG/Config.h>
13 #include <C/PDF/TRN_PDFDoc.h>
14 #include <PDF/PDFDocViewPrefs.h>
15 #include <SDF/SDFDoc.h>
16 #include <PDF/Page.h>
17 #include <PDF/PageSet.h>
18 #include <PDF/DiffOptions.h>
19 #include <PDF/TextDiffOptions.h>
20 #include <PDF/Annot.h>
21 #include <Common/Iterator.h>
22 #include <SDF/SignatureHandler.h>
23 #include <SDF/UndoManager.h>
26 #include <PDF/RefreshOptions.h>
27 #include <PDF/MergeXFDFOptions.h>
28 
29 namespace pdftron {
30  namespace PDF {
31  namespace OCG{
32  class Config;
33  }
34  namespace Struct{class STree;};
35 
41 
47 
53 
70 class PDFDoc
71 {
72 public:
73 
77  PDFDoc ();
78 
88  PDFDoc (SDF::SDFDoc& sdfdoc);
89 
97  PDFDoc(const PDFDoc& other);
98  PDFDoc& operator= (const PDFDoc&);
99 
108  PDFDoc (const UString& filepath);
109  PDFDoc (const char* filepath);
110 
125  PDFDoc (Filters::Filter stream);
126 
136  PDFDoc (const UChar* buf, size_t buf_size);
137 
141  ~PDFDoc ();
142 
146  void Close();
147 
151  bool IsEncrypted();
152 
178  bool InitSecurityHandler (
179 #ifndef SWIG
180  void* custom_data = 0
181 #endif
182  );
183 
216  bool InitStdSecurityHandler(const char* password, int password_sz);
217 
244  bool InitStdSecurityHandler(const pdftron::UString& password);
245 
272  bool InitStdSecurityHandler(const std::vector<UInt8>& password_buf);
273 
289 
301  void SetSecurityHandler(const SDF::SecurityHandler & handler);
302 
306  void RemoveSecurity();
307 
308 
309  /* {{codegen: PDFDoc}} */
310  /* {{codegen: PDFDoc}} */
311 
316  bool HasSignatures();
317 
326 
336  SDF::SignatureHandlerId AddStdSignatureHandler(const UString& pkcs12_keyfile, const UString& pkcs12_keypass);
337 
347  SDF::SignatureHandlerId AddStdSignatureHandler(const std::vector<unsigned char>& pkcs12_keybuffer, const UString& pkcs12_keypass);
348 
354  void RemoveSignatureHandler(const SDF::SignatureHandlerId signature_handler_id);
355 
364 
369 
377  PDF::DigitalSignatureField CreateDigitalSignatureField(const UString& in_sig_field_name = "");
378 
385 
393 
399 
408 
410  {
411  e_action_trigger_doc_will_close = 17, //Triggered before closing a document
412  e_action_trigger_doc_will_save = 18, //Triggered before saving a document
413  e_action_trigger_doc_did_save = 19, //Triggered after saving a document
414  e_action_trigger_doc_will_print = 20, //Triggered before printing a document
415  e_action_trigger_doc_did_print = 21 //Triggered after printing a document
416  };
417 
425 
432  bool IsModified () const;
433 
445  bool HasRepairedXRef() const;
446 
466  bool IsLinearized() const;
467 
472  bool HasDownloader();
473 
484 
495 
522  void Save(const UString& path, UInt32 flags);
523 
524 #ifndef SWIG
525 
552  void Save(const UString& path, UInt32 flags, Common::ProgressMonitor* progress);
553 #endif
554 
555  std::vector<unsigned char> Save(UInt32 flags);
556 
557 #ifndef SWIG
558 
577  void Save(const char* &out_buf, size_t& out_buf_size, UInt32 flags, Common::ProgressMonitor* progress);
578 #endif
579 
594  void Save(Filters::Filter& stream, UInt32 flags);
595 
596 #ifdef SWIG
597 
605  void SaveCustomSignature(const std::vector<UChar>& in_signature, const DigitalSignatureField& in_field, const UString& in_path);
614  void SaveCustomSignature(const std::vector<UChar>& in_signature, const DigitalSignatureField& in_field, Filters::Filter& out_stream);
615 #else
616 
625  void SaveCustomSignature(const UChar* in_signature, const size_t in_signature_size, const DigitalSignatureField& in_field, const UString& in_path);
635  void SaveCustomSignature(const UChar* in_signature, const size_t in_signature_size, const DigitalSignatureField& in_field, Filters::Filter& out_stream);
636 
649  void SaveCustomSignature(const UChar* in_signature, const size_t in_signature_size, const DigitalSignatureField& in_field, const UChar* &out_buf, size_t& out_buf_size);
650 #endif
651 
652 
669  PageIterator GetPageIterator(UInt32 page_number=1);
670 
684  Page GetPage(UInt32 page_number);
685 
691  void PageRemove(const PageIterator& page_itr);
692 
693  enum InsertFlag {
694  e_none, //default, do not insert bookmarks
695  e_insert_bookmark, //insert bookmarks (use this option when inserting many pages in a single call)
696  e_insert_goto_bookmark // same as e_insert_bookmark, but ignore GoToR and URI links, while still retaining bookmark hierarchy (use this option when inserting one page at a time)
697  };
698 
709  void PageInsert(PageIterator& where, Page page);
710 
723  void InsertPages(int insert_before_page_number
724  , PDFDoc& src_doc
725  , int start_page
726  , int end_page
727  , enum InsertFlag flag
728 #ifndef SWIG
729  , Common::ProgressMonitor * monitor = 0
730 #endif
731  );
732 
744  void InsertPages(int insert_before_page_number
745  , PDFDoc& src_doc
746  , const PageSet& source_page_set
747  , enum InsertFlag flag
748 #ifndef SWIG
749  , Common::ProgressMonitor * monitor = 0
750 #endif
751  );
752 
753 
768  void MovePages(int move_before_page_number
769  , PDFDoc& src_doc
770  , int start_page
771  , int end_page
772  , enum InsertFlag flag
773 #ifndef SWIG
774  , Common::ProgressMonitor * monitor = 0
775 #endif
776  );
777 
778 
792  void MovePages(int move_before_page_number
793  , PDFDoc& src_doc
794  , const PageSet& source_page_set
795  , enum InsertFlag flag
796 #ifndef SWIG
797  , Common::ProgressMonitor * monitor = 0
798 #endif
799  );
800 
806  void PagePushFront(Page page);
807 
813  void PagePushBack(Page page);
814 
831  std::vector<Page> ImportPages(const std::vector<Page>& pages, bool import_bookmarks = false);
832 
898  Page PageCreate(const Rect& media_box = Rect(0, 0, 612, 792));
899 
910  int AppendTextDiff(Page page1, Page page2);
911 
921  int AppendTextDiff(PDFDoc& doc1, PDFDoc& doc2);
922 
933  int AppendTextDiff(PDFDoc& doc1, PDFDoc& doc2, TextDiffOptions* options);
934 
945  static int HighlightTextDiff(PDFDoc& doc1, PDFDoc& doc2, TextDiffOptions* options);
946 
952  class Bookmark GetFirstBookmark();
953 
960  void AddRootBookmark(class Bookmark root_bookmark);
961 
965  SDF::Obj GetTrailer ();
966 
971  SDF::Obj GetRoot();
972 
976  SDF::Obj GetPages();
977 
981  int GetPageCount ();
982 
983 
1008 
1024  FieldIterator GetFieldIterator(const UString& field_name);
1025 
1042  Field GetField(const UString& field_name);
1043 
1058  Field FieldCreate(const UString& field_name,
1059  Field::Type type,
1060  SDF::Obj field_value = 0,
1061  SDF::Obj def_field_value = 0);
1062 
1077  Field FieldCreate(const UString& field_name,
1078  Field::Type type,
1079  const UString& field_value,
1080  const UString& def_field_value = "");
1081 
1087  void RefreshFieldAppearances();
1088 
1094  void RefreshAnnotAppearances(const RefreshOptions* options = 0);
1095 
1101  void FlattenAnnotations(bool forms_only = false);
1102 
1107 
1109  e_forms_only, // default, only extract form fields to FDF
1110  e_annots_only, // only extract annots
1111  e_both, // extract both form fields and annots
1112  e_annots_only_no_links = 5 // same as e_annots_only but no url links get converted
1113  };
1114 
1121 
1128  FDF::FDFDoc FDFExtract(PageSet& pages_to_extract, enum ExtractFlag flag = e_forms_only);
1129 
1135  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annotations);
1136 
1144  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annot_added, const std::vector<Annot>& annot_modified, const std::vector<Annot>& annot_deleted);
1145 
1150  void FDFMerge(FDF::FDFDoc& fdf_doc);
1151 
1164  void FDFUpdate(FDF::FDFDoc& fdf_doc);
1165 
1175 
1183  void SetOpenAction(const Action& action);
1184 
1202  void AddFileAttachment(const UString& file_key, FileSpec embedded_file);
1203 
1212  PageLabel GetPageLabel(int page_num);
1213 
1224  void SetPageLabel(int page_num, PageLabel& label);
1225 
1235  void RemovePageLabel(int page_num);
1236 
1240  bool IsTagged();
1241 
1246 
1253  bool HasOC() const;
1254 
1261  SDF::Obj GetOCGs() const;
1262 
1267  OCG::Config GetOCGConfig() const;
1268 
1280  void AddHighlights(const UString& hilite);
1281 
1289  SDF::Obj CreateIndirectName(const char* name);
1306  SDF::Obj CreateIndirectBool(bool value);
1331  SDF::Obj CreateIndirectNumber(double value);
1341  SDF::Obj CreateIndirectString(const UChar* value, UInt32 size);
1371  SDF::Obj CreateIndirectStream(const char* data, const size_t data_size, Filters::Filter filter_chain = Filters::Filter (0,false));
1372 
1376  SDF::SDFDoc& GetSDFDoc ();
1377 
1382  operator SDF::SDFDoc& () { return GetSDFDoc(); }
1383 
1384 
1390  void Lock();
1391 
1395  void Unlock();
1396 
1402  bool TryLock( int milliseconds = 0 );
1403 
1414  void LockRead();
1415 
1419  void UnlockRead();
1420 
1427  bool TryLockRead( int milliseconds = 0 );
1428 
1434  UString GetFileName() const;
1435 
1440  void GenerateThumbnails(UInt32 size);
1441 
1448  void AppendVisualDiff(Page p1, Page p2, DiffOptions* opts);
1449 
1461  void SaveViewerOptimized(const UString& path, const ViewerOptimizedOptions& opts);
1462 
1477  void SaveViewerOptimized(const char* &out_buf, size_t& out_buf_size, const ViewerOptimizedOptions& opts);
1478 
1480  {
1482  // e_failure == bad doc, digest, or MDP (i.e. does not include trust issues, because those are flaky due to being network/config-related)
1486  // unsigned sigs skipped; parts of document may be unsigned (check GetByteRanges on signed sigs to find out)
1488  };
1489 
1496 
1515  void MergeXFDF(Filters::Filter stream, const MergeXFDFOptions* opts = 0);
1534  void MergeXFDF(const UString& xfdf, const MergeXFDFOptions* opts = 0);
1535 
1536  //for xamarin use only
1537  static PDFDoc* CreateInternal(ptrdiff_t impl);
1538  ptrdiff_t GetHandleInternal();
1539 
1540 // @cond PRIVATE_DOC
1541 #ifndef SWIGHIDDEN
1542 
1543  TRN_PDFDoc mp_doc;
1544  PDFDoc(TRN_PDFDoc impl) : mp_doc(impl) {}
1545 #endif
1546 // @endcond
1547 
1548 };
1549 
1550  }; // namespace PDF
1551 }; // namespace pdftron
1552 
1553 
1554 #include <Impl/PDFDoc.inl>
1555 
1556 #endif // PDFTRON_H_CPPPDFPDFDoc
void PageInsert(PageIterator &where, Page page)
void FDFMerge(FDF::FDFDoc &fdf_doc)
PDF::DigitalSignatureFieldIterator GetDigitalSignatureFieldIterator()
SDF::SignatureHandler * GetSignatureHandler(const SDF::SignatureHandlerId signature_handler_id)
Page PageCreate(const Rect &media_box=Rect(0, 0, 612, 792))
void MergeXFDF(Filters::Filter stream, const MergeXFDFOptions *opts=0)
void RemoveSignatureHandler(const SDF::SignatureHandlerId signature_handler_id)
OCG::Config GetOCGConfig() const
SignaturesVerificationStatus VerifySignedDigitalSignatures(const VerificationOptions &in_opts) const
PageLabel GetPageLabel(int page_num)
size_t SignatureHandlerId
SDF::Obj CreateIndirectBool(bool value)
ptrdiff_t GetHandleInternal()
SDF::Obj CreateIndirectNumber(double value)
void SetOpenAction(const Action &action)
void SetSecurityHandler(const SDF::SecurityHandler &handler)
TRN_UInt64 UInt64
Definition: BasicTypes.h:21
SDF::Obj GetOCGs() const
Struct::STree GetStructTree()
bool TryLock(int milliseconds=0)
void InsertPages(int insert_before_page_number, PDFDoc &src_doc, int start_page, int end_page, enum InsertFlag flag, Common::ProgressMonitor *monitor=0)
SDF::Obj CreateIndirectName(const char *name)
void PagePushFront(Page page)
void PagePushBack(Page page)
SDF::UndoManager GetUndoManager()
UString GetFileName() const
bool HasRepairedXRef() const
void SetPageLabel(int page_num, PageLabel &label)
void AddFileAttachment(const UString &file_key, FileSpec embedded_file)
PDFDocViewPrefs GetViewPrefs()
void AddRootBookmark(class Bookmark root_bookmark)
PDF::DigitalSignatureField CreateDigitalSignatureField(const UString &in_sig_field_name="")
Page GetPage(UInt32 page_number)
SDF::SignatureHandlerId AddStdSignatureHandler(const UString &pkcs12_keyfile, const UString &pkcs12_keypass)
Common::Iterator< DigitalSignatureField > DigitalSignatureFieldIterator
Definition: PDFDoc.h:52
SDF::Obj GetTriggerAction(PDFDoc::ActionTriggerEvent trigger)
bool IsLinearized() const
Common::Iterator< Field > FieldIterator
Definition: PDFDoc.h:46
void SaveCustomSignature(const UChar *in_signature, const size_t in_signature_size, const DigitalSignatureField &in_field, const UString &in_path)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
void PageRemove(const PageIterator &page_itr)
bool HasOC() const
TRN_UChar UChar
Definition: BasicTypes.h:12
static int HighlightTextDiff(PDFDoc &doc1, PDFDoc &doc2, TextDiffOptions *options)
PDF::DigitalSignatureField::DocumentPermissions GetDigitalSignaturePermissions() const
std::vector< Page > ImportPages(const std::vector< Page > &pages, bool import_bookmarks=false)
bool InitStdSecurityHandler(const char *password, int password_sz)
Field FieldCreate(const UString &field_name, Field::Type type, SDF::Obj field_value=0, SDF::Obj def_field_value=0)
void RefreshAnnotAppearances(const RefreshOptions *options=0)
FieldIterator GetFieldIterator()
bool IsModified() const
void SaveViewerOptimized(const UString &path, const ViewerOptimizedOptions &opts)
bool TryLockRead(int milliseconds=0)
SDF::Obj CreateIndirectStream(Filters::FilterReader &data, Filters::Filter filter_chain=Filters::Filter(0, false))
void FlattenAnnotations(bool forms_only=false)
void AppendVisualDiff(Page p1, Page p2, DiffOptions *opts)
Field GetField(const UString &field_name)
SDF::SignatureHandlerId AddSignatureHandler(const SDF::SignatureHandler &signature_handler)
SDF::Obj CreateIndirectNull()
bool InitSecurityHandler(void *custom_data=0)
void RefreshFieldAppearances()
void Save(const UString &path, UInt32 flags)
SDF::Obj CreateIndirectString(const UChar *value, UInt32 size)
SDF::Obj CreateIndirectArray()
int AppendTextDiff(Page page1, Page page2)
void AddHighlights(const UString &hilite)
PDFDocInfo GetDocInfo()
void MovePages(int move_before_page_number, PDFDoc &src_doc, int start_page, int end_page, enum InsertFlag flag, Common::ProgressMonitor *monitor=0)
static PDFDoc * CreateInternal(ptrdiff_t impl)
PageIterator GetPageIterator(UInt32 page_number=1)
void GenerateThumbnails(UInt32 size)
SDF::SDFDoc & GetSDFDoc()
SDF::Obj CreateIndirectDict()
SDF::SecurityHandler GetSecurityHandler()
Common::Iterator< Page > PageIterator
Definition: PDFDoc.h:34
PDFDoc & operator=(const PDFDoc &)
void FDFUpdate(FDF::FDFDoc &fdf_doc)
FDF::FDFDoc FDFExtract(enum ExtractFlag flag=e_forms_only)
void RemovePageLabel(int page_num)
class Bookmark GetFirstBookmark()
UInt64 GetDownloadedByteCount()
SDF::Obj GetAcroForm()
UInt64 GetTotalRemoteByteCount()