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-2020 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 
218  void SetColorPostProcessColors(unsigned int white_color, unsigned int black_color);
219 
224 
228  int GetCurrentPage() const;
229 
233  int GetPageCount() const;
234 
240  bool GotoFirstPage();
241 
247  bool GotoLastPage();
248 
254  bool GotoNextPage();
255 
261  bool GotoPreviousPage();
262 
268  bool SetCurrentPage(int page_num);
269 
277  bool ShowRect( int page_num, const Rect& rect );
278 
284  std::vector<int> GetVisiblePages() const ;
285 
291  double GetZoom() const;
292 
300  bool SetZoom(double zoom);
301 
329  bool SetZoom(int x, int y, double zoom);
330 
347  bool SmartZoom(int x, int y);
351  void RotateClockwise();
352 
356  void RotateCounterClockwise();
357 
361  Page::Rotate GetRotation() const;
362 
368  int GetPageNumberFromScreenPt(double x, double y) const;
369 
373  Point ConvScreenPtToCanvasPt(const Point& pt) const;
374 
375 #ifndef SWIG
376  void ConvScreenPtToCanvasPt(double& x, double& y) const;
377 #endif
378 
382  Point ConvCanvasPtToScreenPt(const Point& pt) const;
383 
384 #ifndef SWIG
385  void ConvCanvasPtToScreenPt(double& x, double& y) const;
386 #endif
387 
395  Point ConvCanvasPtToPagePt(const Point& pt, int page_num = -1) const;
396 
397 #ifndef SWIG
398  void ConvCanvasPtToPagePt(double& x, double& y, int page_num = -1) const;
399 #endif
400 
408  Point ConvPagePtToCanvasPt(const Point& pt, int page_num = -1) const;
409 
410 #ifndef SWIG
411  void ConvPagePtToCanvasPt(double& x, double& y, int page_num = -1) const;
412 #endif
413 
421  Point ConvScreenPtToPagePt(const Point& pt, int page_num = -1) const;
422 
423 #ifndef SWIG
424  void ConvScreenPtToPagePt(double& x, double& y, int page_num = -1) const;
425 #endif
426 
436  Point ConvPagePtToScreenPt(const Point& pt, int page_num = -1) const;
437 
438 #ifndef SWIG
439  void ConvPagePtToScreenPt(double& x, double& y, int page_num = -1) const;
440 #endif
441 
446  Point SnapToNearestInDoc(const Point& screen_pt);
447 
454  void SetSnappingMode(UInt32 mode_flags);
455 
471  Common::Matrix2D GetDeviceTransform(int page_num = -1) const;
472 
480 #ifdef SWIG
481  void SetErrorReportProc(Callback* instance);
482 #else
483  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
484 #endif
485 
494  typedef void (*CurrentPageProc) (int current_page, int num_pages, void* data);
495 
504 #ifdef SWIG
505  void SetCurrentPageProc(Callback* instance);
506 #else
507  void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void* data);
508 #endif
509 
519  typedef void(*JavaScriptEventProc) (const char* event_type, const char* json, void* data);
520 
528 #ifdef SWIG
529  void SetJavaScriptEventCallBack(Callback* instance);
530 #else
531  void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void* data);
532 #endif
533 
541  typedef void (*CurrentZoomProc) (double curr_zoom_proc, void* data);
542 
551 #ifdef SWIG
552  void SetCurrentZoomProc(Callback* instance);
553 #else
554  void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void* data);
555 #endif
556 
562  void ExecuteAction(Action& action);
563 
564  void ExecuteAction(ActionParameter& action_param);
565 
569  double GetCanvasWidth() const;
570 
574  double GetCanvasHeight() const;
575 
579  double GetHScrollPos() const;
580 
584  double GetVScrollPos() const;
585 
592  void OnScroll(int pix_dx, int pix_dy);
593 
600  void SetHScrollPos(double pos);
601 
624  void SetVScrollPos(double pos);
625 
633  void OnSize(int width, int height);
634 
643  bool IsFinishedRendering(bool visible_region_only) const;
644 
649  void CancelRendering();
650 
654  void Update(bool all = false);
655 
660  void Update(const Rect& update);
661 
667  void Update(const Annot& annot, int page_num);
668 
673  void Update(const Field& field);
674 
681  void UpdatePageLayout();
682 
688 #ifdef SWIG
689  std::vector<unsigned char> GetBuffer() const;
690 #else
691  const char* GetBuffer() const;
692 #endif
693 
706  void UpdateBuffer();
707 
712  int GetBufferWidth() const;
713 
718  int GetBufferHeight() const;
719 
724  int GetBufferStride() const;
725 
732  void HideAnnotation(Annot annot);
733 
740  void ShowAnnotation(Annot annot);
741 
748  void SetDrawAnnotations(bool render_annots);
749 
762  void SetUrlExtraction(bool enabled);
763 
776  LinkInfo GetLinkAt(int x, int y);
777 
783  void SetHighlightFields(bool highlight_fields);
784 
793  void SetRequiredFieldBorderColor(const ColorPt& new_border_color);
794 
804  void SetAntiAliasing(bool enable_aa);
805 
814  void SetPathHinting(bool enable_hinting);
815 
826  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
827 
841  void SetImageSmoothing(bool smoothing_enabled = true);
842 
850  void SetCaching(bool enabled);
851 
861 
874  void SetGamma(double exp);
875 
886 
902  void SetOCGContext(const OCG::Context& ctx);
903 
912 
918  void UpdateOCGContext();
919 
920 
927  typedef void (*RenderBeginEventProc) (void* data);
928 
940  typedef void (*RenderFinishEventProc) (void* data, bool canceled);
941 
954 #ifdef SWIG
955  void SetRenderBeginProc(class Callback* instance);
956 #else
957  void SetRenderBeginProc(RenderBeginEventProc proc, void* data);
958 #endif
959 
972 #ifdef SWIG
973  void SetRenderFinishProc(class Callback* instance);
974 #else
975  void SetRenderFinishProc(RenderFinishEventProc proc, void* data);
976 #endif
977 
978 
990  };
991 
997 
1005  bool Select(double x1, double y1, double x2, double y2);
1006 
1015  bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end);
1016 
1024  bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2);
1025 
1033  bool Select(double x1, double y1, int page1, double x2, double y2, int page2);
1034 
1043  bool SelectWithSnapping(double x1, double y1, int page1, double x2, double y2, int page2,
1044  bool snap_to_start, bool snap_to_end);
1045 
1053  bool SelectWithSmartSnapping(double x1, double y1, int page1, double x2, double y2, int page2);
1054 
1061  bool Select(const Highlights& highlights);
1062 
1069  bool Select(const Selection& select);
1070 
1075  void CancelFindText();
1076 
1080  void SelectAll();
1081 
1085  bool HasSelection() const;
1086 
1090  void ClearSelection();
1091 
1095  Selection GetSelection( int pagenum = -1 ) const;
1096 
1101  int GetSelectionBeginPage() const ;
1102 
1107  int GetSelectionEndPage() const;
1108 
1113  bool HasSelectionOnPage( int ipage ) const;
1114 
1121  void PrepareWords(int page_num);
1122 
1127  bool WereWordsPrepared(int page_num) const;
1128 
1133  bool IsThereTextInRect(double x1, double y1, double x2, double y2) const;
1134 
1145  void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight);
1146 
1151  bool WereAnnotsForMousePrepared(int page_num) const;
1152 
1158  Annot::Type GetAnnotTypeUnder(double x, double y);
1159 
1164  void SetPageBorderVisibility(bool border_visible);
1165 
1171  void SetPageTransparencyGrid(bool trans_grid_visible);
1172 
1177  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
1178 
1184  void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
1185 
1195  void SetHorizontalAlign(int align);
1196 
1206  void SetVerticalAlign(int align);
1207 
1217  void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
1218 
1231  static void SetViewerCache(SDF::SDFDoc& document, size_t max_cache_size, bool on_disk);
1232 
1236  void Destroy();
1237 
1241  void SetDevicePixelDensity(double dpi, double scale_factor);
1242 
1251  Rect GetScreenRectForAnnot(Annot annot, int page_num = -1);
1252 
1263  Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight);
1264 
1275  {
1280  PVM_SIZE //must stay as the last element
1281  };
1282 
1289  void SetPageViewMode(PageViewMode mode);
1290 
1294  PageViewMode GetPageViewMode() const;
1295 
1302  void RefreshAndUpdate(const ViewChangeCollection& view_change);
1303 
1316  void SetPageRefViewMode(PageViewMode mode);
1317 
1323 
1337  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);
1338 
1342  void ClearThumbCache();
1343 
1355  typedef void (*ThumbAsyncHandler) (int page_num, bool was_thumb_found, const char* thumb_buf, int thumb_width, int thumb_height, void* custom_data);
1356 
1365 #ifdef SWIG
1366  void GetThumbAsync(int page_num, Callback* instance);
1367 #else
1368  void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void* custom_data);
1369 #endif
1370 
1378  size_t GetThumbInCacheSize(int page_num);
1379 
1390  bool GetThumbInCache(int page_num, UChar* buf, UInt32& out_width, UInt32& out_height);
1391 
1392  /*
1393  * Cancel all pending GetThumbAsync requests. Your callback function will still be called
1394  * for each canceled request, but 'was_thumb_found' will be set to 'false'.
1395  */
1396  void CancelAllThumbRequests();
1397 
1403  typedef void (*RequestRenderInWorkerThreadProc) (void* custom_data);
1404 
1413 #ifdef SWIG
1414  void SetRequestRenderInWorkerThreadProc(Callback* instance);
1415 #else
1417 #endif
1418 
1424  typedef void (*FindTextHandler)(bool success, PDF::Selection selection, void* custom_data);
1425 
1426 
1427 #ifdef SWIG
1428 
1434  void SetFindTextHandler(Callback* instance);
1435 #else // SWIG
1436 
1443  void SetFindTextHandler(PDFView::FindTextHandler proc, void* custom_data);
1444 #endif // SWIG
1445 
1457  void FindTextAsync(const UString& search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp);
1458 
1467  std::vector<Annot> GetAnnotationsOnPage(int page_num);
1468 
1481  std::vector<Annot> GetAnnotationListAt(int x1, int y1, int x2, int y2);
1482 
1483  void EnableUndoRedo();
1484  UString Undo();
1485  UString Redo();
1486  void TakeSnapshot(const UString& meta_info);
1489  void RevertAllChanges();
1490 
1492 
1493 
1494  // @cond PRIVATE_DOC
1495 private:
1496  TRN_PDFView mp_view;
1497  TRN_PDFDoc temp_doc;
1498 
1499  // PDFView should not be copied
1500  PDFView(const PDFView&);
1501  PDFView& operator= (const PDFView&);
1502 
1503  FindTextHandler mp_findtexthandler;
1504  void* mp_findtextdata;
1505 
1506  static void StaticTRNPDFViewFindTextHandler(TRN_Bool success, TRN_PDFViewSelection selection, void* custom_data);
1507 
1508  //for internal use only
1509 #if defined(__iOS__)
1510 public:
1511  #include <Impl/PDFView.internal>
1512 #endif // defined(__iOS__)
1513  // @endcond
1514 };
1515 
1516 #include <Impl/PDFView.inl>
1517 
1518  }; // namespace PDF
1519 }; // namespace pdftron
1520 
1521 #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:519
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:940
bool IsFinishedRendering(bool visible_region_only) const
void SetVerticalAlign(int align)
void(* RenderBeginEventProc)(void *data)
Definition: PDFView.h:927
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:541
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)
ExternalAnnotManager GetExternalAnnotManager(const UString &author)
void(* RequestRenderInWorkerThreadProc)(void *custom_data)
Definition: PDFView.h:1403
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)
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:1424
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:1355
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)
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:494
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