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-2021 by PDFTron Systems 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 
28 namespace pdftron {
29  namespace PDF {
30  namespace OCG{
31  class Config;
32  }
33  namespace Struct{class STree;};
34 
40 
46 
52 
69 class PDFDoc
70 {
71 public:
72 
76  PDFDoc ();
77 
87  PDFDoc (SDF::SDFDoc& sdfdoc);
88 
96  PDFDoc(const PDFDoc& other);
97  PDFDoc& operator= (const PDFDoc&);
98 
107  PDFDoc (const UString& filepath);
108  PDFDoc (const char* filepath);
109 
124  PDFDoc (Filters::Filter stream);
125 
135  PDFDoc (const UChar* buf, size_t buf_size);
136 
140  ~PDFDoc ();
141 
145  void Close();
146 
150  bool IsEncrypted();
151 
177  bool InitSecurityHandler (
178 #ifndef SWIG
179  void* custom_data = 0
180 #endif
181  );
182 
215  bool InitStdSecurityHandler(const char* password, int password_sz);
216 
243  bool InitStdSecurityHandler(const pdftron::UString& password);
244 
271  bool InitStdSecurityHandler(const std::vector<UInt8>& password_buf);
272 
288 
300  void SetSecurityHandler(const SDF::SecurityHandler & handler);
301 
305  void RemoveSecurity();
306 
311  bool HasSignatures();
312 
321 
331  SDF::SignatureHandlerId AddStdSignatureHandler(const UString& pkcs12_keyfile, const UString& pkcs12_keypass);
332 
342  SDF::SignatureHandlerId AddStdSignatureHandler(const std::vector<unsigned char>& pkcs12_keybuffer, const UString& pkcs12_keypass);
343 
349  void RemoveSignatureHandler(const SDF::SignatureHandlerId signature_handler_id);
350 
359 
364 
372  PDF::DigitalSignatureField CreateDigitalSignatureField(const UString& in_sig_field_name = "");
373 
380 
388 
394 
403 
405  {
406  e_action_trigger_doc_will_close = 17, //Triggered before closing a document
407  e_action_trigger_doc_will_save = 18, //Triggered before saving a document
408  e_action_trigger_doc_did_save = 19, //Triggered after saving a document
409  e_action_trigger_doc_will_print = 20, //Triggered before printing a document
410  e_action_trigger_doc_did_print = 21 //Triggered after printing a document
411  };
412 
420 
427  bool IsModified () const;
428 
440  bool HasRepairedXRef() const;
441 
461  bool IsLinearized() const;
462 
467  bool HasDownloader();
468 
479 
490 
517  void Save(const UString& path, UInt32 flags);
518 
519 #ifndef SWIG
520 
547  void Save(const UString& path, UInt32 flags, Common::ProgressMonitor* progress);
548 #endif
549 
550  std::vector<unsigned char> Save(UInt32 flags);
551 
552 #ifndef SWIG
553 
573  void Save(const char* &out_buf, size_t& out_buf_size, UInt32 flags, Common::ProgressMonitor* progress);
574 #endif
575 
590  void Save(Filters::Filter& stream, UInt32 flags);
591 
592 #ifdef SWIG
593 
601  void SaveCustomSignature(const std::vector<UChar>& in_signature, const DigitalSignatureField& in_field, const UString& in_path);
610  void SaveCustomSignature(const std::vector<UChar>& in_signature, const DigitalSignatureField& in_field, Filters::Filter& out_stream);
611 #else
612 
621  void SaveCustomSignature(const UChar* in_signature, const size_t in_signature_size, const DigitalSignatureField& in_field, const UString& in_path);
631  void SaveCustomSignature(const UChar* in_signature, const size_t in_signature_size, const DigitalSignatureField& in_field, Filters::Filter& out_stream);
632 
645  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);
646 #endif
647 
648 
665  PageIterator GetPageIterator(UInt32 page_number=1);
666 
680  Page GetPage(UInt32 page_number);
681 
687  void PageRemove(const PageIterator& page_itr);
688 
689  enum InsertFlag {
690  e_none, //default, do not insert bookmarks
691  e_insert_bookmark, //insert bookmarks (use this option when inserting many pages in a single call)
692  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)
693  };
694 
705  void PageInsert(PageIterator& where, Page page);
706 
719  void InsertPages(int insert_before_page_number
720  , PDFDoc& src_doc
721  , int start_page
722  , int end_page
723  , enum InsertFlag flag
724 #ifndef SWIG
725  , Common::ProgressMonitor * monitor = 0
726 #endif
727  );
728 
740  void InsertPages(int insert_before_page_number
741  , PDFDoc& src_doc
742  , const PageSet& source_page_set
743  , enum InsertFlag flag
744 #ifndef SWIG
745  , Common::ProgressMonitor * monitor = 0
746 #endif
747  );
748 
749 
764  void MovePages(int move_before_page_number
765  , PDFDoc& src_doc
766  , int start_page
767  , int end_page
768  , enum InsertFlag flag
769 #ifndef SWIG
770  , Common::ProgressMonitor * monitor = 0
771 #endif
772  );
773 
774 
788  void MovePages(int move_before_page_number
789  , PDFDoc& src_doc
790  , const PageSet& source_page_set
791  , enum InsertFlag flag
792 #ifndef SWIG
793  , Common::ProgressMonitor * monitor = 0
794 #endif
795  );
796 
802  void PagePushFront(Page page);
803 
809  void PagePushBack(Page page);
810 
827  std::vector<Page> ImportPages(const std::vector<Page>& pages, bool import_bookmarks = false);
828 
894  Page PageCreate(const Rect& media_box = Rect(0, 0, 612, 792));
895 
904  void AppendTextDiff(Page page1, Page page2);
905 
912  void AppendTextDiff(PDFDoc& doc1, PDFDoc& doc2);
913 
921  void AppendTextDiff(PDFDoc& doc1, PDFDoc& doc2, TextDiffOptions* options);
922 
928  class Bookmark GetFirstBookmark();
929 
936  void AddRootBookmark(class Bookmark root_bookmark);
937 
941  SDF::Obj GetTrailer ();
942 
947  SDF::Obj GetRoot();
948 
952  SDF::Obj GetPages();
953 
957  int GetPageCount ();
958 
959 
984 
1000  FieldIterator GetFieldIterator(const UString& field_name);
1001 
1018  Field GetField(const UString& field_name);
1019 
1034  Field FieldCreate(const UString& field_name,
1035  Field::Type type,
1036  SDF::Obj field_value = 0,
1037  SDF::Obj def_field_value = 0);
1038 
1053  Field FieldCreate(const UString& field_name,
1054  Field::Type type,
1055  const UString& field_value,
1056  const UString& def_field_value = "");
1057 
1063  void RefreshFieldAppearances();
1064 
1070  void RefreshAnnotAppearances(const RefreshOptions* options = 0);
1071 
1077  void FlattenAnnotations(bool forms_only = false);
1078 
1083 
1085  e_forms_only, // default, only extract form fields to FDF
1086  e_annots_only, // only extract annots
1087  e_both, // extract both form fields and annots
1088  e_annots_only_no_links = 5 // same as e_annots_only but no url links get converted
1089  };
1090 
1097 
1104  FDF::FDFDoc FDFExtract(PageSet& pages_to_extract, enum ExtractFlag flag = e_forms_only);
1105 
1111  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annotations);
1112 
1120  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annot_added, const std::vector<Annot>& annot_modified, const std::vector<Annot>& annot_deleted);
1121 
1126  void FDFMerge(FDF::FDFDoc& fdf_doc);
1127 
1140  void FDFUpdate(FDF::FDFDoc& fdf_doc);
1141 
1151 
1159  void SetOpenAction(const Action& action);
1160 
1178  void AddFileAttachment(const UString& file_key, FileSpec embedded_file);
1179 
1188  PageLabel GetPageLabel(int page_num);
1189 
1200  void SetPageLabel(int page_num, PageLabel& label);
1201 
1211  void RemovePageLabel(int page_num);
1212 
1216  bool IsTagged();
1217 
1222 
1229  bool HasOC() const;
1230 
1237  SDF::Obj GetOCGs() const;
1238 
1243  OCG::Config GetOCGConfig() const;
1244 
1256  void AddHighlights(const UString& hilite);
1257 
1265  SDF::Obj CreateIndirectName(const char* name);
1282  SDF::Obj CreateIndirectBool(bool value);
1307  SDF::Obj CreateIndirectNumber(double value);
1317  SDF::Obj CreateIndirectString(const UChar* value, UInt32 size);
1347  SDF::Obj CreateIndirectStream(const char* data, const size_t data_size, Filters::Filter filter_chain = Filters::Filter (0,false));
1348 
1352  SDF::SDFDoc& GetSDFDoc ();
1353 
1358  operator SDF::SDFDoc& () { return GetSDFDoc(); }
1359 
1360 
1366  void Lock();
1367 
1371  void Unlock();
1372 
1378  bool TryLock( int milliseconds = 0 );
1379 
1390  void LockRead();
1391 
1395  void UnlockRead();
1396 
1403  bool TryLockRead( int milliseconds = 0 );
1404 
1410  UString GetFileName() const;
1411 
1416  void GenerateThumbnails(UInt32 size);
1417 
1424  void AppendVisualDiff(Page p1, Page p2, DiffOptions* opts);
1425 
1437  void SaveViewerOptimized(const UString& path, const ViewerOptimizedOptions& opts);
1438 
1453  void SaveViewerOptimized(const char* &out_buf, size_t& out_buf_size, const ViewerOptimizedOptions& opts);
1454 
1456  {
1458  // e_failure == bad doc, digest, or MDP (i.e. does not include trust issues, because those are flaky due to being network/config-related)
1462  // unsigned sigs skipped; parts of document may be unsigned (check GetByteRanges on signed sigs to find out)
1464  };
1465 
1472 
1473  //for xamarin use only
1474  static PDFDoc* CreateInternal(ptrdiff_t impl);
1475  ptrdiff_t GetHandleInternal();
1476 
1477 // @cond PRIVATE_DOC
1478 #ifndef SWIGHIDDEN
1479 
1480  TRN_PDFDoc mp_doc;
1481  //for xamarin use only
1482  PDFDoc(TRN_PDFDoc impl) : mp_doc(impl) {}
1483 #endif
1484 // @endcond
1485 
1486 };
1487 
1488  }; // namespace PDF
1489 }; // namespace pdftron
1490 
1491 
1492 #include <Impl/PDFDoc.inl>
1493 
1494 #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 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:51
SDF::Obj GetTriggerAction(PDFDoc::ActionTriggerEvent trigger)
bool IsLinearized() const
Common::Iterator< Field > FieldIterator
Definition: PDFDoc.h:45
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
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()
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:33
PDFDoc & operator=(const PDFDoc &)
void FDFUpdate(FDF::FDFDoc &fdf_doc)
FDF::FDFDoc FDFExtract(enum ExtractFlag flag=e_forms_only)
void RemovePageLabel(int page_num)
void AppendTextDiff(Page page1, Page page2)
class Bookmark GetFirstBookmark()
UInt64 GetDownloadedByteCount()
SDF::Obj GetAcroForm()
UInt64 GetTotalRemoteByteCount()