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/Annot.h>
20 #include <Common/Iterator.h>
21 #include <SDF/SignatureHandler.h>
22 #include <SDF/UndoManager.h>
25 #include <PDF/RefreshOptions.h>
26 
27 namespace pdftron {
28  namespace PDF {
29  namespace OCG{
30  class Config;
31  }
32  namespace Struct{class STree;};
33 
39 
45 
51 
68 class PDFDoc
69 {
70 public:
71 
75  PDFDoc ();
76 
86  PDFDoc (SDF::SDFDoc& sdfdoc);
87 
95  PDFDoc(const PDFDoc& other);
96  PDFDoc& operator= (const PDFDoc&);
97 
106  PDFDoc (const UString& filepath);
107  PDFDoc (const char* filepath);
108 
123  PDFDoc (Filters::Filter stream);
124 
134  PDFDoc (const UChar* buf, size_t buf_size);
135 
139  ~PDFDoc ();
140 
144  void Close();
145 
149  bool IsEncrypted();
150 
176  bool InitSecurityHandler (
177 #ifndef SWIG
178  void* custom_data = 0
179 #endif
180  );
181 
214  bool InitStdSecurityHandler(const char* password, int password_sz);
215 
242  bool InitStdSecurityHandler(const pdftron::UString& password);
243 
270  bool InitStdSecurityHandler(const std::vector<UInt8>& password_buf);
271 
287 
299  void SetSecurityHandler(const SDF::SecurityHandler & handler);
300 
304  void RemoveSecurity();
305 
310  bool HasSignatures();
311 
320 
330  SDF::SignatureHandlerId AddStdSignatureHandler(const UString& pkcs12_keyfile, const UString& pkcs12_keypass);
331 
341  SDF::SignatureHandlerId AddStdSignatureHandler(const std::vector<unsigned char>& pkcs12_keybuffer, const UString& pkcs12_keypass);
342 
348  void RemoveSignatureHandler(const SDF::SignatureHandlerId signature_handler_id);
349 
358 
363 
371  PDF::DigitalSignatureField CreateDigitalSignatureField(const UString& in_sig_field_name = "");
372 
379 
387 
393 
402 
404  {
405  e_action_trigger_doc_will_close = 17, //Triggered before closing a document
406  e_action_trigger_doc_will_save = 18, //Triggered before saving a document
407  e_action_trigger_doc_did_save = 19, //Triggered after saving a document
408  e_action_trigger_doc_will_print = 20, //Triggered before printing a document
409  e_action_trigger_doc_did_print = 21 //Triggered after printing a document
410  };
411 
419 
426  bool IsModified () const;
427 
439  bool HasRepairedXRef() const;
440 
460  bool IsLinearized() const;
461 
466  bool HasDownloader();
467 
478 
489 
516  void Save(const UString& path, UInt32 flags);
517 
518 #ifndef SWIG
519 
546  void Save(const UString& path, UInt32 flags, Common::ProgressMonitor* progress);
547 #endif
548 
549  std::vector<unsigned char> Save(UInt32 flags);
550 
551 #ifndef SWIG
552 
572  void Save(const char* &out_buf, size_t& out_buf_size, UInt32 flags, Common::ProgressMonitor* progress);
573 #endif
574 
589  void Save(Filters::Filter& stream, UInt32 flags);
590 
607  PageIterator GetPageIterator(UInt32 page_number=1);
608 
622  Page GetPage(UInt32 page_number);
623 
629  void PageRemove(const PageIterator& page_itr);
630 
631  enum InsertFlag {
632  e_none, //default, do not insert bookmarks
633  e_insert_bookmark, //insert bookmarks (use this option when inserting many pages in a single call)
634  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)
635  };
636 
647  void PageInsert(PageIterator& where, Page page);
648 
661  void InsertPages(int insert_before_page_number
662  , PDFDoc& src_doc
663  , int start_page
664  , int end_page
665  , enum InsertFlag flag
666 #ifndef SWIG
667  , Common::ProgressMonitor * monitor = 0
668 #endif
669  );
670 
682  void InsertPages(int insert_before_page_number
683  , PDFDoc& src_doc
684  , const PageSet& source_page_set
685  , enum InsertFlag flag
686 #ifndef SWIG
687  , Common::ProgressMonitor * monitor = 0
688 #endif
689  );
690 
691 
706  void MovePages(int move_before_page_number
707  , PDFDoc& src_doc
708  , int start_page
709  , int end_page
710  , enum InsertFlag flag
711 #ifndef SWIG
712  , Common::ProgressMonitor * monitor = 0
713 #endif
714  );
715 
716 
730  void MovePages(int move_before_page_number
731  , PDFDoc& src_doc
732  , const PageSet& source_page_set
733  , enum InsertFlag flag
734 #ifndef SWIG
735  , Common::ProgressMonitor * monitor = 0
736 #endif
737  );
738 
744  void PagePushFront(Page page);
745 
751  void PagePushBack(Page page);
752 
769  std::vector<Page> ImportPages(const std::vector<Page>& pages, bool import_bookmarks = false);
770 
836  Page PageCreate(const Rect& media_box = Rect(0, 0, 612, 792));
837 
846  void AppendTextDiff(Page page1, Page page2);
847 
854  void AppendTextDiff(PDFDoc& doc1, PDFDoc& doc2);
855 
861  class Bookmark GetFirstBookmark();
862 
869  void AddRootBookmark(class Bookmark root_bookmark);
870 
874  SDF::Obj GetTrailer ();
875 
880  SDF::Obj GetRoot();
881 
885  SDF::Obj GetPages();
886 
890  int GetPageCount ();
891 
892 
917 
933  FieldIterator GetFieldIterator(const UString& field_name);
934 
951  Field GetField(const UString& field_name);
952 
967  Field FieldCreate(const UString& field_name,
968  Field::Type type,
969  SDF::Obj field_value = 0,
970  SDF::Obj def_field_value = 0);
971 
986  Field FieldCreate(const UString& field_name,
987  Field::Type type,
988  const UString& field_value,
989  const UString& def_field_value = "");
990 
997 
1003  void RefreshAnnotAppearances(const RefreshOptions* options = 0);
1004 
1010  void FlattenAnnotations(bool forms_only = false);
1011 
1016 
1018  e_forms_only, // default, only extract form fields to FDF
1019  e_annots_only, // only extract annots
1020  e_both, // extract both form fields and annots
1021  e_annots_only_no_links = 5 // same as e_annots_only but no url links get converted
1022  };
1023 
1030 
1037  FDF::FDFDoc FDFExtract(PageSet& pages_to_extract, enum ExtractFlag flag = e_forms_only);
1038 
1044  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annotations);
1045 
1053  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annot_added, const std::vector<Annot>& annot_modified, const std::vector<Annot>& annot_deleted);
1054 
1059  void FDFMerge(FDF::FDFDoc& fdf_doc);
1060 
1066  void FDFUpdate(FDF::FDFDoc& fdf_doc);
1067 
1077 
1085  void SetOpenAction(const Action& action);
1086 
1104  void AddFileAttachment(const UString& file_key, FileSpec embedded_file);
1105 
1114  PageLabel GetPageLabel(int page_num);
1115 
1126  void SetPageLabel(int page_num, PageLabel& label);
1127 
1137  void RemovePageLabel(int page_num);
1138 
1142  bool IsTagged();
1143 
1148 
1155  bool HasOC() const;
1156 
1163  SDF::Obj GetOCGs() const;
1164 
1169  OCG::Config GetOCGConfig() const;
1170 
1182  void AddHighlights(const UString& hilite);
1183 
1191  SDF::Obj CreateIndirectName(const char* name);
1208  SDF::Obj CreateIndirectBool(bool value);
1233  SDF::Obj CreateIndirectNumber(double value);
1243  SDF::Obj CreateIndirectString(const UChar* value, UInt32 size);
1273  SDF::Obj CreateIndirectStream(const char* data, const size_t data_size, Filters::Filter filter_chain = Filters::Filter (0,false));
1274 
1278  SDF::SDFDoc& GetSDFDoc ();
1279 
1284  operator SDF::SDFDoc& () { return GetSDFDoc(); }
1285 
1286 
1292  void Lock();
1293 
1297  void Unlock();
1298 
1304  bool TryLock( int milliseconds = 0 );
1305 
1316  void LockRead();
1317 
1321  void UnlockRead();
1322 
1329  bool TryLockRead( int milliseconds = 0 );
1330 
1336  UString GetFileName() const;
1337 
1342  void GenerateThumbnails(UInt32 size);
1343 
1350  void AppendVisualDiff(Page p1, Page p2, DiffOptions* opts);
1351 
1363  void SaveViewerOptimized(const UString& path, const ViewerOptimizedOptions& opts);
1364 
1379  void SaveViewerOptimized(const char* &out_buf, size_t& out_buf_size, const ViewerOptimizedOptions& opts);
1380 
1382  {
1384  // e_failure == bad doc, digest, or MDP (i.e. does not include trust issues, because those are flaky due to being network/config-related)
1388  // unsigned sigs skipped; parts of document may be unsigned (check GetByteRanges on signed sigs to find out)
1390  };
1391 
1398 
1399  //for xamarin use only
1400  static PDFDoc* CreateInternal(ptrdiff_t impl);
1401  ptrdiff_t GetHandleInternal();
1402 
1403 // @cond PRIVATE_DOC
1404 #ifndef SWIGHIDDEN
1405 
1406  TRN_PDFDoc mp_doc;
1407  //for xamarin use only
1408  PDFDoc(TRN_PDFDoc impl) : mp_doc(impl) {}
1409 #endif
1410 // @endcond
1411 
1412 };
1413 
1414  }; // namespace PDF
1415 }; // namespace pdftron
1416 
1417 
1418 #include <Impl/PDFDoc.inl>
1419 
1420 #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:50
SDF::Obj GetTriggerAction(PDFDoc::ActionTriggerEvent trigger)
bool IsLinearized() const
Common::Iterator< Field > FieldIterator
Definition: PDFDoc.h:44
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:32
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()