All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDFDraw.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_CPPPDFPDFDraw
6 #define PDFTRON_H_CPPPDFPDFDraw
7 
8 #include <PDF/PDFRasterizer.h>
9 #include <C/PDF/TRN_PDFDraw.h>
10 
11 #ifdef SWIG
12 #include <PDF/Callback.h>
13 #endif
14 
15 // @cond PRIVATE_DOC
16 #ifndef SWIGHIDDEN
17 #if defined(_WIN32)
18  // A forward declaration for GDI+ Bitmap-s which can be directly created using PDFDraw::GetBitmap() method.
19  namespace Gdiplus { class Bitmap; };
20 #endif
21 #endif
22 // @endcond
23 
24 
25 
26 
27 namespace pdftron {
28  namespace PDF {
29 
30 
31 //return type for PDFDraw::GetBitmap
33 {
34  std::vector<unsigned char> buf;
35 
36 public:
37  BitmapInfo(int w, int h, int s, double d, char* b) {
38  width = w;
39  height = h;
40  stride = s;
41  dpi = d;
42  if (h * s > 0) {
43  buf.resize((std::vector<unsigned char>::size_type)(h * s));
44  if (b)
45  {
46  memcpy(&buf[0], b, (size_t)(h * s));
47  }
48  }
49  }
50  int width;
51  int height;
52  int stride;
53  double dpi;
54 
55  //copy constructor
56  BitmapInfo(const BitmapInfo& b) {
57  width = b.width;
58  height = b.height;
59  stride = b.stride;
60  dpi = b.dpi;
61  std::vector<unsigned char> temp(b.GetBuffer());
62  buf.swap(temp);
63  }
64 
65  std::vector<unsigned char> GetBuffer() const {
66  return buf;
67  }
68 };
69 
70 class Separation;
71 
79 class PDFDraw
80 {
81 public:
82 
90  PDFDraw(double dpi = 92);
91  ~PDFDraw();
92 
105 
126  void SetDPI(double dpi);
127 
140  void SetImageSize(int width, int height, bool preserve_aspect_ratio = true);
141 
148  void SetPageBox(Page::Box region);
149 
156  void SetClipRect(Rect clip_rect);
157 
164  void SetFlipYAxis(bool flip_y);
165 
175  void SetRotate(Page::Rotate r);
176 
183  void SetDrawAnnotations(bool render_annots);
184 
190  void SetHighlightFields(bool highlight_fields);
191 
197  void SetDrawUIElements(bool draw_ui_elements);
198 
208  void SetAntiAliasing(bool enable_aa);
209 
218  void SetPathHinting(bool enable_hinting);
219 
230  void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust);
231 
241  void SetThinLineScaling(double scaling);
242 
257  void SetImageSmoothing(bool smoothing_enabled = true, bool hq_image_resampling = false);
258 
265  void SetCaching(bool enabled = true);
266 
279  void SetGamma(double exp);
280 
290  void SetOCGContext(OCG::Context* ctx);
291 
301  void SetPrintMode(bool is_printing);
302 
315  void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
316 
331  void SetPageTransparent(bool is_transparent);
332 
343 
427  void Export(Page page, const UString& filename, const char* format = "PNG", SDF::Obj encoder_params = 0);
428 
437  void Export(Page page, Filters::Filter& stream, const char* format = "PNG", SDF::Obj encoder_params = 0);
438 
447  #ifdef __DOTNET
448  System::Drawing::Bitmap* GetBitmap(Page page);
449  #endif
450 
467 #if defined(_WIN32) && !defined(__WINRT__)
468  void DrawInRect(Page& page, void* hdc, const Rect& rect);
469 #endif
470 
474  enum PixelFormat {
482  };
483 
499  const BitmapInfo GetBitmap(Page page, PixelFormat pix_fmt = e_bgra, bool demult = false);
500 
513  std::vector<Separation> GetSeparationBitmaps(Page page);
514 
515 #ifndef SWIG
516 
539  const UChar* GetBitmap(Page page, int& out_width, int& out_height, int& out_stride, double& out_dpi,
540  PixelFormat pix_fmt = e_bgra, bool demult = false);
541 #endif
542 
550 #ifdef SWIG
551  void SetErrorReportProc(Callback* instance);
552 #else
553  void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void* data);
554 #endif
555 
566 
570  void Destroy();
571 
572 // @cond PRIVATE_DOC
573 #ifndef SWIGHIDDEN
574  TRN_PDFDraw mp_draw;
575 #endif
576 private:
577  // PDFDraw should not be copied
578  PDFDraw(const PDFDraw& other);
579  PDFDraw& operator= (const PDFDraw&);
580 // @endcond
581 };
582 
583 
584 #include <Impl/PDFDraw.inl>
585 
586 
587  }; // namespace PDF
588 }; // namespace pdftron
589 
590 #endif // PDFTRON_H_CPPPDFPDFDraw
void SetGamma(double exp)
void SetPathHinting(bool enable_hinting)
void SetClipRect(Rect clip_rect)
void SetPrintMode(bool is_printing)
void SetImageSmoothing(bool smoothing_enabled=true, bool hq_image_resampling=false)
void SetPageBox(Page::Box region)
PDFDraw(double dpi=92)
void SetThinLineScaling(double scaling)
TRN_UInt8 UInt8
Definition: BasicTypes.h:15
BitmapInfo(const BitmapInfo &b)
Definition: PDFDraw.h:56
void(* ErrorReportProc)(const char *message, void *data)
void SetPageTransparent(bool is_transparent)
void SetImageSize(int width, int height, bool preserve_aspect_ratio=true)
BitmapInfo(int w, int h, int s, double d, char *b)
Definition: PDFDraw.h:37
std::vector< Separation > GetSeparationBitmaps(Page page)
void SetRotate(Page::Rotate r)
void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b)
TRN_UChar UChar
Definition: BasicTypes.h:12
void SetFlipYAxis(bool flip_y)
void SetErrorReportProc(PDFRasterizer::ErrorReportProc error_proc, void *data)
std::vector< unsigned char > GetBuffer() const
Definition: PDFDraw.h:65
void SetDPI(double dpi)
void Export(Page page, const UString &filename, const char *format="PNG", SDF::Obj encoder_params=0)
void SetRasterizerType(PDFRasterizer::Type type)
void SetCaching(bool enabled=true)
const BitmapInfo GetBitmap(Page page, PixelFormat pix_fmt=e_bgra, bool demult=false)
void SetDrawUIElements(bool draw_ui_elements)
void SetDrawAnnotations(bool render_annots)
void SetOCGContext(OCG::Context *ctx)
void SetColorPostProcessMode(PDFRasterizer::ColorPostProcessMode mode)
void SetHighlightFields(bool highlight_fields)
void SetAntiAliasing(bool enable_aa)
void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
void SetOverprint(PDFRasterizer::OverprintPreviewMode op)
void DrawInRect(Page &page, void *hdc, const Rect &rect)