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-2026 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 
465  Point SnapToNearestInDocFromPageSpace(double page_x, double page_y, int page_num);
466 
473  void SetSnappingMode(UInt32 mode_flags);
474 
490  Common::Matrix2D GetDeviceTransform(int page_num = -1) const;
491 
499 #ifdef SWIG
500  void SetErrorReportProc(Callback* instance);
501 #else
502  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
503 #endif
504 
513  typedef void (*CurrentPageProc) (int current_page, int num_pages, void* data);
514 
523 #ifdef SWIG
524  void SetCurrentPageProc(Callback* instance);
525 #else
526  void SetCurrentPageProc(CurrentPageProc curr_pagenum_proc, void* data);
527 #endif
528 
538  typedef void(*JavaScriptEventProc) (const char* event_type, const char* json, void* data);
539 
547 #ifdef SWIG
548  void SetJavaScriptEventCallBack(Callback* instance);
549 #else
550  void SetJavaScriptEventCallBack(JavaScriptEventProc js_proc, void* data);
551 #endif
552 
560  typedef void (*CurrentZoomProc) (double curr_zoom_proc, void* data);
561 
570 #ifdef SWIG
571  void SetCurrentZoomProc(Callback* instance);
572 #else
573  void SetCurrentZoomProc(CurrentZoomProc curr_zoom_proc, void* data);
574 #endif
575 
581  void ExecuteAction(Action& action);
582 
583  void ExecuteAction(ActionParameter& action_param);
584 
588  double GetCanvasWidth() const;
589 
593  double GetCanvasHeight() const;
594 
598  double GetHScrollPos() const;
599 
603  double GetVScrollPos() const;
604 
611  void OnScroll(int pix_dx, int pix_dy);
612 
619  void SetHScrollPos(double pos);
620 
643  void SetVScrollPos(double pos);
644 
652  void OnSize(int width, int height);
653 
662  bool IsFinishedRendering(bool visible_region_only) const;
663 
668  void CancelRendering();
669 
673  void Update(bool all = false);
674 
679  void Update(const Rect& update);
680 
686  void Update(const Annot& annot, int page_num);
687 
692  void Update(const Field& field);
693 
700  void UpdatePageLayout();
701 
707 #ifdef SWIG
708  std::vector<unsigned char> GetBuffer() const;
709 #else
710  const char* GetBuffer() const;
711 #endif
712 
725  void UpdateBuffer();
726 
731  int GetBufferWidth() const;
732 
737  int GetBufferHeight() const;
738 
743  int GetBufferStride() const;
744 
751  void HideAnnotation(Annot annot);
752 
759  void ShowAnnotation(Annot annot);
760 
767  void SetDrawAnnotations(bool render_annots);
768 
781  void SetUrlExtraction(bool enabled);
782 
795  LinkInfo GetLinkAt(int x, int y);
796 
806  void SetFieldHighlightColor(const ColorPt& new_field_highlight_color);
807 
813  void SetHighlightFields(bool highlight_fields);
814 
823  void SetRequiredFieldBorderColor(const ColorPt& new_border_color);
824 
834  void SetSignatureHighlightColor(const ColorPt& new_signature_highlight_color);
835 
845  void SetAntiAliasing(bool enable_aa);
846 
855  void SetPathHinting(bool enable_hinting);
856 
867  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
868 
882  void SetImageSmoothing(bool smoothing_enabled = true);
883 
891  void SetCaching(bool enabled);
892 
902 
915  void SetGamma(double exp);
916 
927 
943  void SetOCGContext(const OCG::Context& ctx);
944 
953 
959  void UpdateOCGContext();
960 
961 
968  typedef void (*RenderBeginEventProc) (void* data);
969 
981  typedef void (*RenderFinishEventProc) (void* data, bool canceled);
982 
995 #ifdef SWIG
996  void SetRenderBeginProc(class Callback* instance);
997 #else
998  void SetRenderBeginProc(RenderBeginEventProc proc, void* data);
999 #endif
1000 
1013 #ifdef SWIG
1014  void SetRenderFinishProc(class Callback* instance);
1015 #else
1016  void SetRenderFinishProc(RenderFinishEventProc proc, void* data);
1017 #endif
1018 
1019 
1031  };
1032 
1038 
1043 
1049  void SetRightToLeftLanguage(bool flag);
1050 
1056  bool GetRightToLeftLanguage() const;
1057 
1065  bool Select(double x1, double y1, double x2, double y2);
1066 
1075  bool SelectWithSnapping(double x1, double y1, double x2, double y2, bool snap_to_start, bool snap_to_end);
1076 
1084  bool SelectWithSmartSnapping(double x1, double y1, double x2, double y2);
1085 
1093  bool Select(double x1, double y1, int page1, double x2, double y2, int page2);
1094 
1103  bool SelectWithSnapping(double x1, double y1, int page1, double x2, double y2, int page2,
1104  bool snap_to_start, bool snap_to_end);
1105 
1113  bool SelectWithSmartSnapping(double x1, double y1, int page1, double x2, double y2, int page2);
1114 
1121  bool Select(const Highlights& highlights);
1122 
1129  bool Select(const Selection& select);
1130 
1135  void CancelFindText();
1136 
1140  void SelectAll();
1141 
1145  bool HasSelection() const;
1146 
1150  void ClearSelection();
1151 
1155  Selection GetSelection( int pagenum = -1 ) const;
1156 
1161  int GetSelectionBeginPage() const ;
1162 
1167  int GetSelectionEndPage() const;
1168 
1173  bool HasSelectionOnPage( int ipage ) const;
1174 
1181  void PrepareWords(int page_num);
1182 
1187  bool WereWordsPrepared(int page_num) const;
1188 
1193  bool IsThereTextInRect(double x1, double y1, double x2, double y2) const;
1194 
1205  void PrepareAnnotsForMouse(int page_num, double distance_threshold, double minimum_line_weight);
1206 
1211  bool WereAnnotsForMousePrepared(int page_num) const;
1212 
1218  Annot::Type GetAnnotTypeUnder(double x, double y);
1219 
1224  void SetPageBorderVisibility(bool border_visible);
1225 
1231  void SetPageTransparencyGrid(bool trans_grid_visible);
1232 
1237  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
1238 
1244  void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a = 255);
1245 
1255  void SetHorizontalAlign(int align);
1256 
1266  void SetVerticalAlign(int align);
1267 
1280  void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
1281 
1294  static void SetViewerCache(SDF::SDFDoc& document, size_t max_cache_size, bool on_disk);
1295 
1299  void Destroy();
1300 
1304  void SetDevicePixelDensity(double dpi, double scale_factor);
1305 
1314  Rect GetScreenRectForAnnot(Annot annot, int page_num = -1);
1315 
1326  Annot GetAnnotationAt(int x, int y, double distanceThreshold, double minimumLineWeight);
1327 
1338  {
1343  PVM_SIZE //must stay as the last element
1344  };
1345 
1352  void SetPageViewMode(PageViewMode mode);
1353 
1357  PageViewMode GetPageViewMode() const;
1358 
1365  void RefreshAndUpdate(const ViewChangeCollection& view_change);
1366 
1379  void SetPageRefViewMode(PageViewMode mode);
1380 
1386 
1400  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);
1401 
1405  void ClearThumbCache();
1406 
1418  typedef void (*ThumbAsyncHandler) (int page_num, bool was_thumb_found, const char* thumb_buf, int thumb_width, int thumb_height, void* custom_data);
1419 
1428 #ifdef SWIG
1429  void GetThumbAsync(int page_num, Callback* instance);
1430 #else
1431  void GetThumbAsync(int page_num, ThumbAsyncHandler proc, void* custom_data);
1432 #endif
1433 
1441  size_t GetThumbInCacheSize(int page_num);
1442 
1453  bool GetThumbInCache(int page_num, UChar* buf, UInt32& out_width, UInt32& out_height);
1454 
1455  /*
1456  * Cancel all pending GetThumbAsync requests. Your callback function will still be called
1457  * for each canceled request, but 'was_thumb_found' will be set to 'false'.
1458  */
1459  void CancelAllThumbRequests();
1460 
1466  typedef void (*RequestRenderInWorkerThreadProc) (void* custom_data);
1467 
1476 #ifdef SWIG
1477  void SetRequestRenderInWorkerThreadProc(Callback* instance);
1478 #else
1480 #endif
1481 
1487  typedef void (*FindTextHandler)(bool success, PDF::Selection selection, void* custom_data);
1488 
1489 
1490 #ifdef SWIG
1491 
1497  void SetFindTextHandler(Callback* instance);
1498 #else // SWIG
1499 
1506  void SetFindTextHandler(PDFView::FindTextHandler proc, void* custom_data);
1507 #endif // SWIG
1508 
1520  void FindTextAsync(const UString& search_str, bool match_case, bool match_whole_word, bool search_up, bool reg_exp);
1521 
1530  std::vector<Annot> GetAnnotationsOnPage(int page_num);
1531 
1544  std::vector<Annot> GetAnnotationListAt(int x1, int y1, int x2, int y2);
1545 
1549  void EnableUndoRedo();
1550 
1557  UString Undo();
1558 
1564  UString Redo();
1565 
1571  bool HasChangesSinceSnapshot();
1572 
1578  void TakeSnapshot(const UString& meta_info);
1579 
1588 
1597 
1603  bool CanUndo();
1604 
1610  bool CanRedo();
1611 
1619 
1623  void RevertAllChanges();
1624 
1626 
1627 
1628  // @cond PRIVATE_DOC
1629 private:
1630  TRN_PDFView mp_view;
1631  TRN_PDFDoc temp_doc;
1632 
1633  // PDFView should not be copied
1634  PDFView(const PDFView&);
1635  PDFView& operator= (const PDFView&);
1636 
1637  FindTextHandler mp_findtexthandler;
1638  void* mp_findtextdata;
1639 
1640  static void StaticTRNPDFViewFindTextHandler(TRN_Bool success, TRN_PDFViewSelection selection, void* custom_data);
1641 
1642  //for internal use only
1643 #if defined(__iOS__)
1644 public:
1645  #include <Impl/PDFView.internal>
1646 #endif // defined(__iOS__)
1647  // @endcond
1648 };
1649 
1650 #include <Impl/PDFView.inl>
1651 
1652  }; // namespace PDF
1653 }; // namespace pdftron
1654 
1655 #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:538
void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b, UInt8 a=255)
Point SnapToNearestInDoc(const Point &screen_pt)
void SetVScrollPos(double pos)
Point SnapToNearestInDocFromPageSpace(double page_x, double page_y, int page_num)
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:981
bool IsFinishedRendering(bool visible_region_only) const
void SetVerticalAlign(int align)
void(* RenderBeginEventProc)(void *data)
Definition: PDFView.h:968
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:560
void SetRightToLeftLanguage(bool flag)
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:1466
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:1487
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:1418
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 RevertChangesSinceSnapshot()
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:513
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
bool GetRightToLeftLanguage() const
void SetDevicePixelDensity(double dpi, double scale_factor)
int GetBufferHeight() const