All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDFView.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPPDFPDFView
6 #define PDFTRON_H_CPPPDFPDFView
7 
8 #include <Common/BasicTypes.h>
9 #include <PDF/PDFDoc.h>
11 #include <PDF/PDFRasterizer.h>
12 #include <PDF/Highlights.h>
13 #include <PDF/LinkInfo.h>
14 #include <PDF/OCG/Context.h>
15 #include <C/PDF/TRN_PDFView.h>
16 #include <PDF/Selection.h>
17 #include <PDF/DocumentConversion.h>
18 #include <SDF/ObjSet.h>
20 #include <PDF/ActionParameter.h>
21 #ifdef SWIG
22 #include <PDF/Callback.h>
23 #endif
24 
25 namespace pdftron {
26  namespace PDF {
27 
72 class PDFView
73 {
74 public:
75 
80  PDFView();
81  ~PDFView();
82 
88  void SetDoc(PDFDoc& doc);
89 
98  void OpenUniversalDoc(DocumentConversion& conversion);
99 
103  void CloseDoc();
104 
108  PDFDoc* GetDoc();
109 
114  void DocLock(bool cancel_threads);
115 
119  void DocUnlock();
120 
126  bool DocTryLock( int milliseconds = 0 );
127 
139  void DocLockRead();
140 
144  void DocUnlockRead();
145 
151  bool DocTryLockRead( int milliseconds = 0 );
152 
157  {
158  e_single_page = 1, //<<< Display one page at a time.
159  e_single_continuous, //<<< Display the pages in one column.
160  e_facing, //<<< Display the pages two at a time, with odd-numbered pages on the left.
161  e_facing_continuous, //<<< Display the pages in two columns, with odd-numbered pages on the left.
162  e_facing_cover, //<<< Display the pages two at a time, with odd-numbered pages on the right.
163  e_facing_continuous_cover //<<< Display the pages in two columns, with odd-numbered pages on the right.
164  };
165 
173 
178 
189 
190 
204  void SetColorPostProcessMapFile(Filters::Filter image_file_contents);
205 
213  ColorPt GetPostProcessedColor(const ColorPt& color) const;
214 
227  void SetColorPostProcessColors(unsigned int white_color, unsigned int black_color);
228 
233 
237  int GetCurrentPage() const;
238 
242  int GetPageCount() const;
243 
249  bool GotoFirstPage();
250 
256  bool GotoLastPage();
257 
263  bool GotoNextPage();
264 
270  bool GotoPreviousPage();
271 
277  bool SetCurrentPage(int page_num);
278 
286  bool ShowRect( int page_num, const Rect& rect );
287 
293  std::vector<int> GetVisiblePages() const ;
294 
300  double GetZoom() const;
301 
309  bool SetZoom(double zoom);
310 
338  bool SetZoom(int x, int y, double zoom);
339 
356  bool SmartZoom(int x, int y);
360  void RotateClockwise();
361 
365  void RotateCounterClockwise();
366 
370  Page::Rotate GetRotation() const;
371 
377  int GetPageNumberFromScreenPt(double x, double y) const;
378 
382  Point ConvScreenPtToCanvasPt(const Point& pt) const;
383 
384 #ifndef SWIG
385  void ConvScreenPtToCanvasPt(double& x, double& y) const;
386 #endif
387 
391  Point ConvCanvasPtToScreenPt(const Point& pt) const;
392 
393 #ifndef SWIG
394  void ConvCanvasPtToScreenPt(double& x, double& y) const;
395 #endif
396 
404  Point ConvCanvasPtToPagePt(const Point& pt, int page_num = -1) const;
405 
406 #ifndef SWIG
407  void ConvCanvasPtToPagePt(double& x, double& y, int page_num = -1) const;
408 #endif
409 
417  Point ConvPagePtToCanvasPt(const Point& pt, int page_num = -1) const;
418 
419 #ifndef SWIG
420  void ConvPagePtToCanvasPt(double& x, double& y, int page_num = -1) const;
421 #endif
422 
430  Point ConvScreenPtToPagePt(const Point& pt, int page_num = -1) const;
431 
432 #ifndef SWIG
433  void ConvScreenPtToPagePt(double& x, double& y, int page_num = -1) const;
434 #endif
435 
445  Point ConvPagePtToScreenPt(const Point& pt, int page_num = -1) const;
446 
447 #ifndef SWIG
448  void ConvPagePtToScreenPt(double& x, double& y, int page_num = -1) const;
449 #endif
450 
455  Point SnapToNearestInDoc(const Point& screen_pt);
456 
463  void SetSnappingMode(UInt32 mode_flags);
464 
480  Common::Matrix2D GetDeviceTransform(int page_num = -1) const;
481 
489 #ifdef SWIG
490  void SetErrorReportProc(Callback* instance);
491 #else
492  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
493 #endif
494 
503  typedef void (*CurrentPageProc) (int current_page, int num_pages, void* data);
504 
513 #ifdef SWIG
514  void SetCurrentPageProc(Callback* instance);
515 #else
516  void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void* data);
517 #endif
518 
528  typedef void(*JavaScriptEventProc) (const char* event_type, const char* json, void* data);
529 
537 #ifdef SWIG
538  void SetJavaScriptEventCallBack(Callback* instance);
539 #else
540  void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void* data);
541 #endif
542 
550  typedef void (*CurrentZoomProc) (double curr_zoom_proc, void* data);
551 
560 #ifdef SWIG
561  void SetCurrentZoomProc(Callback* instance);
562 #else
563  void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void* data);
564 #endif
565 
571  void ExecuteAction(Action& action);
572 
573  void ExecuteAction(ActionParameter& action_param);
574 
578  double GetCanvasWidth() const;
579 
583  double GetCanvasHeight() const;
584 
588  double GetHScrollPos() const;
589 
593  double GetVScrollPos() const;
594 
601  void OnScroll(int pix_dx, int pix_dy);
602 
609  void SetHScrollPos(double pos);
610 
633  void SetVScrollPos(double pos);
634 
642  void OnSize(int width, int height);
643 
652  bool IsFinishedRendering(bool visible_region_only) const;
653 
658  void CancelRendering();
659 
663  void Update(bool all = false);
664 
669  void Update(const Rect& update);
670 
676  void Update(const Annot& annot, int page_num);
677 
682  void Update(const Field& field);
683 
690  void UpdatePageLayout();
691 
697 #ifdef SWIG
698  std::vector<unsigned char> GetBuffer() const;
699 #else
700  const char* GetBuffer() const;
701 #endif
702 
715  void UpdateBuffer();
716 
721  int GetBufferWidth() const;
722 
727  int GetBufferHeight() const;
728 
733  int GetBufferStride() const;
734 
741  void HideAnnotation(Annot annot);
742 
749  void ShowAnnotation(Annot annot);
750 
757  void SetDrawAnnotations(bool render_annots);
758 
771  void SetUrlExtraction(bool enabled);
772 
785  LinkInfo GetLinkAt(int x, int y);
786 
796  void SetFieldHighlightColor(const ColorPt& new_field_highlight_color);
797 
803  void SetHighlightFields(bool highlight_fields);
804 
813  void SetRequiredFieldBorderColor(const ColorPt& new_border_color);
814 
824  void SetSignatureHighlightColor(const ColorPt& new_signature_highlight_color);
825 
835  void SetAntiAliasing(bool enable_aa);
836 
845  void SetPathHinting(bool enable_hinting);
846 
857  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
858 
872  void SetImageSmoothing(bool smoothing_enabled = true);
873 
881  void SetCaching(bool enabled);
882 
892 
905  void SetGamma(double exp);
906 
917 
933  void SetOCGContext(const OCG::Context& ctx);
934 
943 
949  void UpdateOCGContext();
950 
951 
958  typedef void (*RenderBeginEventProc) (void* data);
959 
971  typedef void (*RenderFinishEventProc) (void* data, bool canceled);
972 
985 #ifdef SWIG
986  void SetRenderBeginProc(class Callback* instance);
987 #else
988  void SetRenderBeginProc(RenderBeginEventProc proc, void* data);
989 #endif
990 
1003 #ifdef SWIG
1004  void SetRenderFinishProc(class Callback* instance);
1005 #else
1006  void SetRenderFinishProc(RenderFinishEventProc proc, void* data);
1007 #endif
1008 
1009 
1021  };
1022 
1028 
1033 
1041  bool Select(double x1, double y1, double x2, double y2);
1042 
1051  bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end);
1052 
1060  bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2);
1061 
1069  bool Select(double x1, double y1, int page1, double x2, double y2, int page2);
1070 
1079  bool SelectWithSnapping(double x1, double y1, int page1, double x2, double y2, int page2,
1080  bool snap_to_start, bool snap_to_end);
1081 
1089  bool SelectWithSmartSnapping(double x1, double y1, int page1, double x2, double y2, int page2);
1090 
1097  bool Select(const Highlights& highlights);
1098 
1105  bool Select(const Selection& select);
1106 
1111  void CancelFindText();
1112 
1116  void SelectAll();
1117 
1121  bool HasSelection() const;
1122 
1126  void ClearSelection();
1127 
1131  Selection GetSelection( int pagenum = -1 ) const;
1132 
1137  int GetSelectionBeginPage() const ;
1138 
1143  int GetSelectionEndPage() const;
1144 
1149  bool HasSelectionOnPage( int ipage ) const;
1150 
1157  void PrepareWords(int page_num);
1158 
1163  bool WereWordsPrepared(int page_num) const;
1164 
1169  bool IsThereTextInRect(double x1, double y1, double x2, double y2) const;
1170 
1181  void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight);
1182 
1187  bool WereAnnotsForMousePrepared(int page_num) const;
1188 
1194  Annot::Type GetAnnotTypeUnder(double x, double y);
1195 
1200  void SetPageBorderVisibility(bool border_visible);
1201 
1207  void SetPageTransparencyGrid(bool trans_grid_visible);
1208 
1213  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
1214 
1220  void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
1221 
1231  void SetHorizontalAlign(int align);
1232 
1242  void SetVerticalAlign(int align);
1243 
1256  void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
1257 
1270  static void SetViewerCache(SDF::SDFDoc& document, size_t max_cache_size, bool on_disk);
1271 
1275  void Destroy();
1276 
1280  void SetDevicePixelDensity(double dpi, double scale_factor);
1281 
1290  Rect GetScreenRectForAnnot(Annot annot, int page_num = -1);
1291 
1302  Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight);
1303 
1314  {
1319  PVM_SIZE //must stay as the last element
1320  };
1321 
1328  void SetPageViewMode(PageViewMode mode);
1329 
1333  PageViewMode GetPageViewMode() const;
1334 
1341  void RefreshAndUpdate(const ViewChangeCollection& view_change);
1342 
1355  void SetPageRefViewMode(PageViewMode mode);
1356 
1362 
1376  void SetupThumbnails(bool use_embedded, bool generate_at_runtime, bool use_disk_cache, int thumb_max_side_length, size_t max_abs_cache_size, double max_perc_cache_size);
1377 
1381  void ClearThumbCache();
1382 
1394  typedef void (*ThumbAsyncHandler) (int page_num, bool was_thumb_found, const char* thumb_buf, int thumb_width, int thumb_height, void* custom_data);
1395 
1404 #ifdef SWIG
1405  void GetThumbAsync(int page_num, Callback* instance);
1406 #else
1407  void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void* custom_data);
1408 #endif
1409 
1417  size_t GetThumbInCacheSize(int page_num);
1418 
1429  bool GetThumbInCache(int page_num, UChar* buf, UInt32& out_width, UInt32& out_height);
1430 
1431  /*
1432  * Cancel all pending GetThumbAsync requests. Your callback function will still be called
1433  * for each canceled request, but 'was_thumb_found' will be set to 'false'.
1434  */
1435  void CancelAllThumbRequests();
1436 
1442  typedef void (*RequestRenderInWorkerThreadProc) (void* custom_data);
1443 
1452 #ifdef SWIG
1453  void SetRequestRenderInWorkerThreadProc(Callback* instance);
1454 #else
1456 #endif
1457 
1463  typedef void (*FindTextHandler)(bool success, PDF::Selection selection, void* custom_data);
1464 
1465 
1466 #ifdef SWIG
1467 
1473  void SetFindTextHandler(Callback* instance);
1474 #else // SWIG
1475 
1482  void SetFindTextHandler(PDFView::FindTextHandler proc, void* custom_data);
1483 #endif // SWIG
1484 
1496  void FindTextAsync(const UString& search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp);
1497 
1506  std::vector<Annot> GetAnnotationsOnPage(int page_num);
1507 
1520  std::vector<Annot> GetAnnotationListAt(int x1, int y1, int x2, int y2);
1521 
1522  void EnableUndoRedo();
1523  UString Undo();
1524  UString Redo();
1525  void TakeSnapshot(const UString& meta_info);
1528  bool CanUndo();
1529  bool CanRedo();
1530  void RevertAllChanges();
1531 
1533 
1534 
1535  // @cond PRIVATE_DOC
1536 private:
1537  TRN_PDFView mp_view;
1538  TRN_PDFDoc temp_doc;
1539 
1540  // PDFView should not be copied
1541  PDFView(const PDFView&);
1542  PDFView& operator= (const PDFView&);
1543 
1544  FindTextHandler mp_findtexthandler;
1545  void* mp_findtextdata;
1546 
1547  static void StaticTRNPDFViewFindTextHandler(TRN_Bool success, TRN_PDFViewSelection selection, void* custom_data);
1548 
1549  //for internal use only
1550 #if defined(__iOS__)
1551 public:
1552  #include <Impl/PDFView.internal>
1553 #endif // defined(__iOS__)
1554  // @endcond
1555 };
1556 
1557 #include <Impl/PDFView.inl>
1558 
1559  }; // namespace PDF
1560 }; // namespace pdftron
1561 
1562 #endif // PDFTRON_H_CPPPDFPDFView
bool DocTryLock(int milliseconds=0)
void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad)
void(* JavaScriptEventProc)(const char *event_type, const char *json, void *data)
Definition: PDFView.h:528
void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a=255)
Point SnapToNearestInDoc(const Point &screen_pt)
void SetVScrollPos(double pos)
void SetRasterizerType(PDFRasterizer::Type type)
void SetHScrollPos(double pos)
PagePresentationMode GetPagePresentationMode() const
bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2)
std::vector< Annot > GetAnnotationsOnPage(int page_num)
void OnScroll(int pix_dx, int pix_dy)
bool WereWordsPrepared(int page_num) const
void SetPageRefViewMode(PageViewMode mode)
bool DocTryLockRead(int milliseconds=0)
void PrepareWords(int page_num)
void HideAnnotation(Annot annot)
void SetRequestRenderInWorkerThreadProc(RequestRenderInWorkerThreadProc proc, void *custom_data)
void(* RenderFinishEventProc)(void *data, bool canceled)
Definition: PDFView.h:971
bool IsFinishedRendering(bool visible_region_only) const
void SetVerticalAlign(int align)
void(* RenderBeginEventProc)(void *data)
Definition: PDFView.h:958
void SetOCGContext(const OCG::Context &ctx)
void SetUrlExtraction(bool enabled)
size_t GetThumbInCacheSize(int page_num)
TRN_UInt8 UInt8
Definition: BasicTypes.h:15
Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight)
OCG::Context GetOCGContext()
void SetColorPostProcessMapFile(Filters::Filter image_file_contents)
void SetFindTextHandler(PDFView::FindTextHandler proc, void *custom_data)
int GetPageNumberFromScreenPt(double x, double y) const
Point ConvPagePtToScreenPt(const Point &pt, int page_num=-1) const
void SetPagePresentationMode(PagePresentationMode mode)
void(* CurrentZoomProc)(double curr_zoom_proc, void *data)
Definition: PDFView.h:550
Point ConvCanvasPtToPagePt(const Point &pt, int page_num=-1) const
Selection GetSelection(int pagenum=-1) const
Page::Rotate GetRotation() const
bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end)
void SetupThumbnails(bool use_embedded, bool generate_at_runtime, bool use_disk_cache, int thumb_max_side_length, size_t max_abs_cache_size, double max_perc_cache_size)
bool HasSelectionOnPage(int ipage) const
int GetBufferStride() const
void SetDoc(PDFDoc &doc)
void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void *data)
void FindTextAsync(const UString &search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp)
void SetAntiAliasing(bool enable_aa)
void(* RequestRenderInWorkerThreadProc)(void *custom_data)
Definition: PDFView.h:1442
void SetOverprint(PDFRasterizer::OverprintPreviewMode op)
Point ConvScreenPtToCanvasPt(const Point &pt) const
void Update(bool all=false)
void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight)
bool SetZoom(double zoom)
void SetGamma(double exp)
Point ConvCanvasPtToScreenPt(const Point &pt) const
void SetPathHinting(bool enable_hinting)
ExternalAnnotManager GetExternalAnnotManager(const UString &author, ExternalAnnotManager::Mode mode=ExternalAnnotManager::e_admin_undo_own)
double GetZoom() const
bool SetCurrentPage(int page_num)
void SetImageSmoothing(bool smoothing_enabled=true)
void(* ErrorReportProc)(const char *message, void *data)
Point ConvPagePtToCanvasPt(const Point &pt, int page_num=-1) const
void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b)
double GetHScrollPos() const
void SetColorPostProcessMode(PDFRasterizer::ColorPostProcessMode mode)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
void TakeSnapshot(const UString &meta_info)
void(* FindTextHandler)(bool success, PDF::Selection selection, void *custom_data)
Definition: PDFView.h:1463
const char * GetBuffer() const
PageViewMode GetPageRefViewMode() const
void(* ThumbAsyncHandler)(int page_num, bool was_thumb_found, const char *thumb_buf, int thumb_width, int thumb_height, void *custom_data)
Definition: PDFView.h:1394
void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void *data)
void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void *custom_data)
std::vector< Annot > GetAnnotationListAt(int x1, int y1, int x2, int y2)
ColorPt GetPostProcessedColor(const ColorPt &color) const
Point ConvScreenPtToPagePt(const Point &pt, int page_num=-1) const
TRN_UChar UChar
Definition: BasicTypes.h:12
void SetSignatureHighlightColor(const ColorPt &new_signature_highlight_color)
void SetSnappingMode(UInt32 mode_flags)
void SetDrawAnnotations(bool render_annots)
double GetVScrollPos() const
double GetCanvasHeight() const
void SetRequiredFieldBorderColor(const ColorPt &new_border_color)
void DocLock(bool cancel_threads)
void SetPageTransparencyGrid(bool trans_grid_visible)
std::vector< int > GetVisiblePages() const
bool Select(double x1, double y1, double x2, double y2)
void SetRenderFinishProc(RenderFinishEventProc proc, void *data)
void RefreshAndUpdate(const ViewChangeCollection &view_change)
void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void *data)
void SetHorizontalAlign(int align)
int GetSelectionEndPage() const
bool ShowRect(int page_num, const Rect &rect)
void ExecuteAction(Action &action)
bool WereAnnotsForMousePrepared(int page_num) const
void SetRenderBeginProc(RenderBeginEventProc proc, void *data)
Annot::Type GetAnnotTypeUnder(double x, double y)
TextSelectionMode GetTextSelectionMode() const
bool IsThereTextInRect(double x1, double y1, double x2, double y2) const
void SetPageBorderVisibility(bool border_visible)
void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void *data)
int GetSelectionBeginPage() const
bool GetThumbInCache(int page_num, UChar *buf, UInt32 &out_width, UInt32 &out_height)
bool HasSelection() const
int GetBufferWidth() const
void OnSize(int width, int height)
void SetHighlightFields(bool highlight_fields)
PDFRasterizer::ColorPostProcessMode GetColorPostProcessMode() const
void SetPageViewMode(PageViewMode mode)
LinkInfo GetLinkAt(int x, int y)
int GetPageCount() const
void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
void SetColorPostProcessColors(unsigned int white_color, unsigned int black_color)
Rect GetScreenRectForAnnot(Annot annot, int page_num=-1)
static void SetViewerCache(SDF::SDFDoc &document, size_t max_cache_size, bool on_disk)
Common::Matrix2D GetDeviceTransform(int page_num=-1) const
void ShowAnnotation(Annot annot)
void(* CurrentPageProc)(int current_page, int num_pages, void *data)
Definition: PDFView.h:503
int GetCurrentPage() const
bool SmartZoom(int x, int y)
PageViewMode GetPageViewMode() const
void OpenUniversalDoc(DocumentConversion &conversion)
void SetFieldHighlightColor(const ColorPt &new_field_highlight_color)
void SetCaching(bool enabled)
void SetTextSelectionMode(TextSelectionMode tm)
double GetCanvasWidth() const
void SetDevicePixelDensity(double dpi, double scale_factor)
int GetBufferHeight() const