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-2020 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 
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 
843  class Bookmark GetFirstBookmark();
844 
851  void AddRootBookmark(class Bookmark root_bookmark);
852 
856  SDF::Obj GetTrailer ();
857 
862  SDF::Obj GetRoot();
863 
867  SDF::Obj GetPages();
868 
872  int GetPageCount ();
873 
874 
899 
915  FieldIterator GetFieldIterator(const UString& field_name);
916 
933  Field GetField(const UString& field_name);
934 
949  Field FieldCreate(const UString& field_name,
950  Field::Type type,
951  SDF::Obj field_value = 0,
952  SDF::Obj def_field_value = 0);
953 
968  Field FieldCreate(const UString& field_name,
969  Field::Type type,
970  const UString& field_value,
971  const UString& def_field_value = "");
972 
979 
985  void RefreshAnnotAppearances(const RefreshOptions* options = 0);
986 
992  void FlattenAnnotations(bool forms_only = false);
993 
998 
999  enum ExtractFlag {
1000  e_forms_only, // default, only extract form fields to FDF
1001  e_annots_only, // only extract annots
1002  e_both, // extract both form fields and annots
1003  e_annots_only_no_links = 5 // same as e_annots_only but no url links get converted
1004  };
1005 
1012 
1019  FDF::FDFDoc FDFExtract(PageSet& pages_to_extract, enum ExtractFlag flag = e_forms_only);
1020 
1026  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annotations);
1027 
1035  FDF::FDFDoc FDFExtract(const std::vector<Annot>& annot_added, const std::vector<Annot>& annot_modified, const std::vector<Annot>& annot_deleted);
1036 
1041  void FDFMerge(FDF::FDFDoc& fdf_doc);
1042 
1048  void FDFUpdate(FDF::FDFDoc& fdf_doc);
1049 
1059 
1067  void SetOpenAction(const Action& action);
1068 
1086  void AddFileAttachment(const UString& file_key, FileSpec embedded_file);
1087 
1096  PageLabel GetPageLabel(int page_num);
1097 
1108  void SetPageLabel(int page_num, PageLabel& label);
1109 
1119  void RemovePageLabel(int page_num);
1120 
1124  bool IsTagged();
1125 
1130 
1137  bool HasOC() const;
1138 
1145  SDF::Obj GetOCGs() const;
1146 
1151  OCG::Config GetOCGConfig() const;
1152 
1164  void AddHighlights(const UString& hilite);
1165 
1173  SDF::Obj CreateIndirectName(const char* name);
1190  SDF::Obj CreateIndirectBool(bool value);
1215  SDF::Obj CreateIndirectNumber(double value);
1225  SDF::Obj CreateIndirectString(const UChar* value, UInt32 size);
1255  SDF::Obj CreateIndirectStream(const char* data, const size_t data_size, Filters::Filter filter_chain = Filters::Filter (0,false));
1256 
1260  SDF::SDFDoc& GetSDFDoc ();
1261 
1266  operator SDF::SDFDoc& () { return GetSDFDoc(); }
1267 
1268 
1274  void Lock();
1275 
1279  void Unlock();
1280 
1286  bool TryLock( int milliseconds = 0 );
1287 
1298  void LockRead();
1299 
1303  void UnlockRead();
1304 
1311  bool TryLockRead( int milliseconds = 0 );
1312 
1318  UString GetFileName() const;
1319 
1324  void GenerateThumbnails(UInt32 size);
1325 
1332  void AppendVisualDiff(Page p1, Page p2, DiffOptions* opts);
1333 
1345  void SaveViewerOptimized(const UString& path, const ViewerOptimizedOptions& opts);
1346 
1361  void SaveViewerOptimized(const char* &out_buf, size_t& out_buf_size, const ViewerOptimizedOptions& opts);
1362 
1364  {
1366  // e_failure == bad doc, digest, or MDP (i.e. does not include trust issues, because those are flaky due to being network/config-related)
1370  // unsigned sigs skipped; parts of document may be unsigned (check GetByteRanges on signed sigs to find out)
1372  };
1373 
1380 
1381  //for xamarin use only
1382  static PDFDoc* CreateInternal(ptrdiff_t impl);
1383  ptrdiff_t GetHandleInternal();
1384 
1385 // @cond PRIVATE_DOC
1386 #ifndef SWIGHIDDEN
1387 
1388  TRN_PDFDoc mp_doc;
1389  //for xamarin use only
1390  PDFDoc(TRN_PDFDoc impl) : mp_doc(impl) {}
1391 #endif
1392 // @endcond
1393 
1394 };
1395 
1396  }; // namespace PDF
1397 }; // namespace pdftron
1398 
1399 
1400 #include <Impl/PDFDoc.inl>
1401 
1402 #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(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)
class Bookmark GetFirstBookmark()
UInt64 GetDownloadedByteCount()
SDF::Obj GetAcroForm()
UInt64 GetTotalRemoteByteCount()