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-2021 by PDFTron Systems 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 
792  void SetHighlightFields(bool highlight_fields);
793 
802  void SetRequiredFieldBorderColor(const ColorPt& new_border_color);
803 
813  void SetAntiAliasing(bool enable_aa);
814 
823  void SetPathHinting(bool enable_hinting);
824 
835  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
836 
850  void SetImageSmoothing(bool smoothing_enabled = true);
851 
859  void SetCaching(bool enabled);
860 
870 
883  void SetGamma(double exp);
884 
895 
911  void SetOCGContext(const OCG::Context& ctx);
912 
921 
927  void UpdateOCGContext();
928 
929 
936  typedef void (*RenderBeginEventProc) (void* data);
937 
949  typedef void (*RenderFinishEventProc) (void* data, bool canceled);
950 
963 #ifdef SWIG
964  void SetRenderBeginProc(class Callback* instance);
965 #else
966  void SetRenderBeginProc(RenderBeginEventProc proc, void* data);
967 #endif
968 
981 #ifdef SWIG
982  void SetRenderFinishProc(class Callback* instance);
983 #else
984  void SetRenderFinishProc(RenderFinishEventProc proc, void* data);
985 #endif
986 
987 
999  };
1000 
1006 
1014  bool Select(double x1, double y1, double x2, double y2);
1015 
1024  bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end);
1025 
1033  bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2);
1034 
1042  bool Select(double x1, double y1, int page1, double x2, double y2, int page2);
1043 
1052  bool SelectWithSnapping(double x1, double y1, int page1, double x2, double y2, int page2,
1053  bool snap_to_start, bool snap_to_end);
1054 
1062  bool SelectWithSmartSnapping(double x1, double y1, int page1, double x2, double y2, int page2);
1063 
1070  bool Select(const Highlights& highlights);
1071 
1078  bool Select(const Selection& select);
1079 
1084  void CancelFindText();
1085 
1089  void SelectAll();
1090 
1094  bool HasSelection() const;
1095 
1099  void ClearSelection();
1100 
1104  Selection GetSelection( int pagenum = -1 ) const;
1105 
1110  int GetSelectionBeginPage() const ;
1111 
1116  int GetSelectionEndPage() const;
1117 
1122  bool HasSelectionOnPage( int ipage ) const;
1123 
1130  void PrepareWords(int page_num);
1131 
1136  bool WereWordsPrepared(int page_num) const;
1137 
1142  bool IsThereTextInRect(double x1, double y1, double x2, double y2) const;
1143 
1154  void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight);
1155 
1160  bool WereAnnotsForMousePrepared(int page_num) const;
1161 
1167  Annot::Type GetAnnotTypeUnder(double x, double y);
1168 
1173  void SetPageBorderVisibility(bool border_visible);
1174 
1180  void SetPageTransparencyGrid(bool trans_grid_visible);
1181 
1186  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
1187 
1193  void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
1194 
1204  void SetHorizontalAlign(int align);
1205 
1215  void SetVerticalAlign(int align);
1216 
1226  void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
1227 
1240  static void SetViewerCache(SDF::SDFDoc& document, size_t max_cache_size, bool on_disk);
1241 
1245  void Destroy();
1246 
1250  void SetDevicePixelDensity(double dpi, double scale_factor);
1251 
1260  Rect GetScreenRectForAnnot(Annot annot, int page_num = -1);
1261 
1272  Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight);
1273 
1284  {
1289  PVM_SIZE //must stay as the last element
1290  };
1291 
1298  void SetPageViewMode(PageViewMode mode);
1299 
1303  PageViewMode GetPageViewMode() const;
1304 
1311  void RefreshAndUpdate(const ViewChangeCollection& view_change);
1312 
1325  void SetPageRefViewMode(PageViewMode mode);
1326 
1332 
1346  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);
1347 
1351  void ClearThumbCache();
1352 
1364  typedef void (*ThumbAsyncHandler) (int page_num, bool was_thumb_found, const char* thumb_buf, int thumb_width, int thumb_height, void* custom_data);
1365 
1374 #ifdef SWIG
1375  void GetThumbAsync(int page_num, Callback* instance);
1376 #else
1377  void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void* custom_data);
1378 #endif
1379 
1387  size_t GetThumbInCacheSize(int page_num);
1388 
1399  bool GetThumbInCache(int page_num, UChar* buf, UInt32& out_width, UInt32& out_height);
1400 
1401  /*
1402  * Cancel all pending GetThumbAsync requests. Your callback function will still be called
1403  * for each canceled request, but 'was_thumb_found' will be set to 'false'.
1404  */
1405  void CancelAllThumbRequests();
1406 
1412  typedef void (*RequestRenderInWorkerThreadProc) (void* custom_data);
1413 
1422 #ifdef SWIG
1423  void SetRequestRenderInWorkerThreadProc(Callback* instance);
1424 #else
1426 #endif
1427 
1433  typedef void (*FindTextHandler)(bool success, PDF::Selection selection, void* custom_data);
1434 
1435 
1436 #ifdef SWIG
1437 
1443  void SetFindTextHandler(Callback* instance);
1444 #else // SWIG
1445 
1452  void SetFindTextHandler(PDFView::FindTextHandler proc, void* custom_data);
1453 #endif // SWIG
1454 
1466  void FindTextAsync(const UString& search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp);
1467 
1476  std::vector<Annot> GetAnnotationsOnPage(int page_num);
1477 
1490  std::vector<Annot> GetAnnotationListAt(int x1, int y1, int x2, int y2);
1491 
1492  void EnableUndoRedo();
1493  UString Undo();
1494  UString Redo();
1495  void TakeSnapshot(const UString& meta_info);
1498  bool CanUndo();
1499  bool CanRedo();
1500  void RevertAllChanges();
1501 
1503 
1504 
1505  // @cond PRIVATE_DOC
1506 private:
1507  TRN_PDFView mp_view;
1508  TRN_PDFDoc temp_doc;
1509 
1510  // PDFView should not be copied
1511  PDFView(const PDFView&);
1512  PDFView& operator= (const PDFView&);
1513 
1514  FindTextHandler mp_findtexthandler;
1515  void* mp_findtextdata;
1516 
1517  static void StaticTRNPDFViewFindTextHandler(TRN_Bool success, TRN_PDFViewSelection selection, void* custom_data);
1518 
1519  //for internal use only
1520 #if defined(__iOS__)
1521 public:
1522  #include <Impl/PDFView.internal>
1523 #endif // defined(__iOS__)
1524  // @endcond
1525 };
1526 
1527 #include <Impl/PDFView.inl>
1528 
1529  }; // namespace PDF
1530 }; // namespace pdftron
1531 
1532 #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:949
bool IsFinishedRendering(bool visible_region_only) const
void SetVerticalAlign(int align)
void(* RenderBeginEventProc)(void *data)
Definition: PDFView.h:936
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:1412
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:1433
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:1364
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 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)
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 SetCaching(bool enabled)
void SetTextSelectionMode(TextSelectionMode tm)
double GetCanvasWidth() const
void SetDevicePixelDensity(double dpi, double scale_factor)
int GetBufferHeight() const