Sample C# code for using Apryse SDK's PDF viewer control in a basic project. This sample uses a number of built-in features from PDFViewCtrl to open PDF files, implement document navigation, text highlighting, markup, and editing. If you are looking for a sample showing how to further customize the viewer (e.g. by implementing custom tools or custom GUI elements), please take a look at the PDFView sample code. Learn more about our Server SDK and PDF Viewer SDK.
1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6
7using pdftron;
8using pdftron.PDF;
9using pdftron.SDF;
10using pdftron.Filters;
11using pdftron.Common;
12
13
14namespace PDFViewSimpleCS
15{
16 /// <summary>
17 /// Summary description for Form1.
18 /// </summary>
19 public class PDFViewSimple : System.Windows.Forms.Form
20 {
21 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
22 static PDFViewSimple() {}
23
24 private PDFViewCtrl _pdfview;
25 private PDFDoc _pdfdoc;
26 private String filePath;
27
28 private IContainer components;
29 private MainMenu mainMenu1;
30 private MenuItem menuItem1;
31 private MenuItem MenuFileOpen;
32 private MenuItem MenuFileSave;
33 private MenuItem MenuFileSaveAs;
34 private MenuItem MenuFilePrint;
35 private MenuItem MenuFileExit;
36 private MenuItem menuItem2;
37 private MenuItem MenuEditFind;
38 private MenuItem MenuEditCopy;
39 private MenuItem MenuEditSelect;
40 private MenuItem menuItem3;
41 private MenuItem MenuViewPageLayout;
42 private MenuItem MenuViewPageView;
43 private MenuItem MenuViewZoomIn;
44 private MenuItem MenuViewZoomOut;
45 private MenuItem MenuViewPageLayoutSingle;
46 private MenuItem MenuViewPageLayoutSingleContinuous;
47 private MenuItem MenuViewPageLayoutFacing;
48 private MenuItem MenuViewPageLayoutFacingContinuous;
49 private MenuItem MenuViewPageViewFitPage;
50 private MenuItem MenuViewPageViewFitWidth;
51 private MenuItem menuItem4;
52 private MenuItem MenuToolPan;
53 private MenuItem MenuToolStructSel;
54 private MenuItem MenuToolRectSel;
55 private MenuItem MenuToolRectZoomIn;
56 private MenuItem MenuToolRectZoomOut;
57 private MenuItem MenuToolAnnotEdit;
58 private MenuItem MenuToolLineCreate;
59 private MenuItem MenuToolRectCreate;
60 private MenuItem MenuToolOvalCreate;
61 private MenuItem MenuToolArrowCreate;
62 private MenuItem MenuToolFreeHand;
63 private MenuItem menuItem5;
64 private MenuItem MenuPageNavNext;
65 private MenuItem MenuPageNavPrev;
66 private MenuItem MenuPageNavFirst;
67 private MenuItem MenuPageNavLast;
68 private MenuItem menuItem6;
69 private System.Windows.Forms.MenuItem menuItemNavPanel;
70 private System.Windows.Forms.MenuItem menuItem7;
71 private MenuItem menuHelpAbout;
72
73
74 public PDFViewSimple()
75 {
76 //
77 // Required for Windows Form Designer support
78 //
79 InitializeComponent();
80 _pdfview = new PDFViewCtrl();
81 _pdfview.Location = new System.Drawing.Point(0, 0);
82 _pdfview.Dock = System.Windows.Forms.DockStyle.Fill;
83 _pdfview.SetPageBorderVisibility(false);
84 Controls.Add(_pdfview);
85 }
86
87 /// <summary>
88 /// Clean up any resources being used.
89 /// </summary>
90 protected override void Dispose( bool disposing )
91 {
92 if( disposing )
93 {
94 if (components != null)
95 {
96 components.Dispose();
97 }
98 }
99 base.Dispose( disposing );
100 }
101
102 #region Windows Form Designer generated code
103 /// <summary>
104 /// Required method for Designer support - do not modify
105 /// the contents of this method with the code editor.
106 /// </summary>
107 private void InitializeComponent()
108 {
109 this.components = new System.ComponentModel.Container();
110 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PDFViewSimple));
111 this.mainMenu1 = new System.Windows.Forms.MainMenu();
112 this.menuItem1 = new System.Windows.Forms.MenuItem();
113 this.MenuFileOpen = new System.Windows.Forms.MenuItem();
114 this.MenuFileSave = new System.Windows.Forms.MenuItem();
115 this.MenuFileSaveAs = new System.Windows.Forms.MenuItem();
116 this.MenuFilePrint = new System.Windows.Forms.MenuItem();
117 this.MenuFileExit = new System.Windows.Forms.MenuItem();
118 this.menuItem2 = new System.Windows.Forms.MenuItem();
119 this.MenuEditFind = new System.Windows.Forms.MenuItem();
120 this.MenuEditCopy = new System.Windows.Forms.MenuItem();
121 this.MenuEditSelect = new System.Windows.Forms.MenuItem();
122 this.menuItem3 = new System.Windows.Forms.MenuItem();
123 this.MenuViewPageLayout = new System.Windows.Forms.MenuItem();
124 this.MenuViewPageLayoutSingle = new System.Windows.Forms.MenuItem();
125 this.MenuViewPageLayoutSingleContinuous = new System.Windows.Forms.MenuItem();
126 this.MenuViewPageLayoutFacing = new System.Windows.Forms.MenuItem();
127 this.MenuViewPageLayoutFacingContinuous = new System.Windows.Forms.MenuItem();
128 this.MenuViewPageView = new System.Windows.Forms.MenuItem();
129 this.MenuViewPageViewFitPage = new System.Windows.Forms.MenuItem();
130 this.MenuViewPageViewFitWidth = new System.Windows.Forms.MenuItem();
131 this.MenuViewZoomIn = new System.Windows.Forms.MenuItem();
132 this.MenuViewZoomOut = new System.Windows.Forms.MenuItem();
133 this.menuItem7 = new System.Windows.Forms.MenuItem();
134 this.menuItemNavPanel = new System.Windows.Forms.MenuItem();
135 this.menuItem4 = new System.Windows.Forms.MenuItem();
136 this.MenuToolPan = new System.Windows.Forms.MenuItem();
137 this.MenuToolStructSel = new System.Windows.Forms.MenuItem();
138 this.MenuToolRectSel = new System.Windows.Forms.MenuItem();
139 this.MenuToolRectZoomIn = new System.Windows.Forms.MenuItem();
140 this.MenuToolRectZoomOut = new System.Windows.Forms.MenuItem();
141 this.MenuToolAnnotEdit = new System.Windows.Forms.MenuItem();
142 this.MenuToolLineCreate = new System.Windows.Forms.MenuItem();
143 this.MenuToolRectCreate = new System.Windows.Forms.MenuItem();
144 this.MenuToolOvalCreate = new System.Windows.Forms.MenuItem();
145 this.MenuToolArrowCreate = new System.Windows.Forms.MenuItem();
146 this.MenuToolFreeHand = new System.Windows.Forms.MenuItem();
147 this.menuItem5 = new System.Windows.Forms.MenuItem();
148 this.MenuPageNavNext = new System.Windows.Forms.MenuItem();
149 this.MenuPageNavPrev = new System.Windows.Forms.MenuItem();
150 this.MenuPageNavFirst = new System.Windows.Forms.MenuItem();
151 this.MenuPageNavLast = new System.Windows.Forms.MenuItem();
152 this.menuItem6 = new System.Windows.Forms.MenuItem();
153 this.menuHelpAbout = new System.Windows.Forms.MenuItem();
154 this.SuspendLayout();
155 //
156 // mainMenu1
157 //
158 this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
159 this.menuItem1,
160 this.menuItem2,
161 this.menuItem3,
162 this.menuItem4,
163 this.menuItem5,
164 this.menuItem6});
165 //
166 // menuItem1
167 //
168 this.menuItem1.Index = 0;
169 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
170 this.MenuFileOpen,
171 this.MenuFileSave,
172 this.MenuFileSaveAs,
173 this.MenuFilePrint,
174 this.MenuFileExit});
175 this.menuItem1.Text = "File";
176 //
177 // MenuFileOpen
178 //
179 this.MenuFileOpen.Index = 0;
180 this.MenuFileOpen.Text = "Open..";
181 this.MenuFileOpen.Click += new System.EventHandler(this.menuFileOpen_Click);
182 //
183 // MenuFileSave
184 //
185 this.MenuFileSave.Index = 1;
186 this.MenuFileSave.Text = "Save";
187 this.MenuFileSave.Click += new System.EventHandler(this.MenuFileSave_Click);
188 //
189 // MenuFileSaveAs
190 //
191 this.MenuFileSaveAs.Index = 2;
192 this.MenuFileSaveAs.Text = "Save As";
193 this.MenuFileSaveAs.Click += new System.EventHandler(this.MenuFileSaveAs_Click);
194 //
195 // MenuFilePrint
196 //
197 this.MenuFilePrint.Index = 3;
198 this.MenuFilePrint.Text = "Print";
199 this.MenuFilePrint.Click += new System.EventHandler(this.MenuFilePrint_Click);
200 //
201 // MenuFileExit
202 //
203 this.MenuFileExit.Index = 4;
204 this.MenuFileExit.Text = "Exit";
205 this.MenuFileExit.Click += new System.EventHandler(this.MenuFileExit_Click);
206 //
207 // menuItem2
208 //
209 this.menuItem2.Index = 1;
210 this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
211 this.MenuEditFind,
212 this.MenuEditCopy,
213 this.MenuEditSelect});
214 this.menuItem2.Text = "Edit";
215 //
216 // MenuEditFind
217 //
218 this.MenuEditFind.Index = 0;
219 this.MenuEditFind.Text = "Find ...";
220 this.MenuEditFind.Click += new System.EventHandler(this.MenuEditFind_Click);
221 //
222 // MenuEditCopy
223 //
224 this.MenuEditCopy.Index = 1;
225 this.MenuEditCopy.Text = "Copy";
226 this.MenuEditCopy.Click += new System.EventHandler(this.MenuEditCopy_Click);
227 //
228 // MenuEditSelect
229 //
230 this.MenuEditSelect.Index = 2;
231 this.MenuEditSelect.Text = "Select All";
232 this.MenuEditSelect.Click += new System.EventHandler(this.MenuEditSelect_Click);
233 //
234 // menuItem3
235 //
236 this.menuItem3.Index = 2;
237 this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
238 this.MenuViewPageLayout,
239 this.MenuViewPageView,
240 this.MenuViewZoomIn,
241 this.MenuViewZoomOut,
242 this.menuItem7,
243 this.menuItemNavPanel});
244 this.menuItem3.Text = "View";
245 //
246 // MenuViewPageLayout
247 //
248 this.MenuViewPageLayout.Index = 0;
249 this.MenuViewPageLayout.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
250 this.MenuViewPageLayoutSingle,
251 this.MenuViewPageLayoutSingleContinuous,
252 this.MenuViewPageLayoutFacing,
253 this.MenuViewPageLayoutFacingContinuous});
254 this.MenuViewPageLayout.Text = "Page Layout";
255 //
256 // MenuViewPageLayoutSingle
257 //
258 this.MenuViewPageLayoutSingle.Index = 0;
259 this.MenuViewPageLayoutSingle.Text = "Single Page";
260 this.MenuViewPageLayoutSingle.Click += new System.EventHandler(this.MenuViewPageLayoutSingle_Click);
261 //
262 // MenuViewPageLayoutSingleContinuous
263 //
264 this.MenuViewPageLayoutSingleContinuous.Index = 1;
265 this.MenuViewPageLayoutSingleContinuous.Text = "Single Continuous";
266 this.MenuViewPageLayoutSingleContinuous.Click += new System.EventHandler(this.MenuViewPageLayoutSingleContinuous_Click);
267 //
268 // MenuViewPageLayoutFacing
269 //
270 this.MenuViewPageLayoutFacing.Index = 2;
271 this.MenuViewPageLayoutFacing.Text = "Facing";
272 this.MenuViewPageLayoutFacing.Click += new System.EventHandler(this.MenuViewPageLayoutFacing_Click);
273 //
274 // MenuViewPageLayoutFacingContinuous
275 //
276 this.MenuViewPageLayoutFacingContinuous.Index = 3;
277 this.MenuViewPageLayoutFacingContinuous.Text = "Facing Continuous";
278 this.MenuViewPageLayoutFacingContinuous.Click += new System.EventHandler(this.MenuViewPageLayoutFacingContinuous_Click);
279 //
280 // MenuViewPageView
281 //
282 this.MenuViewPageView.Index = 1;
283 this.MenuViewPageView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
284 this.MenuViewPageViewFitPage,
285 this.MenuViewPageViewFitWidth});
286 this.MenuViewPageView.Text = "Page View Mode";
287 //
288 // MenuViewPageViewFitPage
289 //
290 this.MenuViewPageViewFitPage.Index = 0;
291 this.MenuViewPageViewFitPage.Text = "Fit Page";
292 this.MenuViewPageViewFitPage.Click += new System.EventHandler(this.MenuViewPageViewFitPage_Click);
293 //
294 // MenuViewPageViewFitWidth
295 //
296 this.MenuViewPageViewFitWidth.Index = 1;
297 this.MenuViewPageViewFitWidth.Text = "Fit Width";
298 this.MenuViewPageViewFitWidth.Click += new System.EventHandler(this.MenuViewPageViewFitWidth_Click);
299 //
300 // MenuViewZoomIn
301 //
302 this.MenuViewZoomIn.Index = 2;
303 this.MenuViewZoomIn.Text = "Zoom In";
304 this.MenuViewZoomIn.Click += new System.EventHandler(this.MenuViewZoomIn_Click);
305 //
306 // MenuViewZoomOut
307 //
308 this.MenuViewZoomOut.Index = 3;
309 this.MenuViewZoomOut.Text = "Zoom Out";
310 this.MenuViewZoomOut.Click += new System.EventHandler(this.MenuViewZoomOut_Click);
311 //
312 // menuItem7
313 //
314 this.menuItem7.Index = 4;
315 this.menuItem7.Text = "-";
316 //
317 // menuItemNavPanel
318 //
319 this.menuItemNavPanel.Index = 5;
320 this.menuItemNavPanel.Text = "Navigation Panel";
321 this.menuItemNavPanel.Click += new System.EventHandler(this.menuItem7_Click);
322 //
323 // menuItem4
324 //
325 this.menuItem4.Index = 3;
326 this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
327 this.MenuToolPan,
328 this.MenuToolStructSel,
329 this.MenuToolRectSel,
330 this.MenuToolRectZoomIn,
331 this.MenuToolRectZoomOut,
332 this.MenuToolAnnotEdit,
333 this.MenuToolLineCreate,
334 this.MenuToolRectCreate,
335 this.MenuToolOvalCreate,
336 this.MenuToolArrowCreate,
337 this.MenuToolFreeHand});
338 this.menuItem4.Text = "Tool";
339 //
340 // MenuToolPan
341 //
342 this.MenuToolPan.Index = 0;
343 this.MenuToolPan.Text = "Pan";
344 this.MenuToolPan.Click += new System.EventHandler(this.MenuToolPan_Click);
345 //
346 // MenuToolStructSel
347 //
348 this.MenuToolStructSel.Index = 1;
349 this.MenuToolStructSel.Text = "Structural Selection";
350 this.MenuToolStructSel.Click += new System.EventHandler(this.MenuToolStructSel_Click);
351 //
352 // MenuToolRectSel
353 //
354 this.MenuToolRectSel.Index = 2;
355 this.MenuToolRectSel.Text = "Rectangular Selection";
356 this.MenuToolRectSel.Click += new System.EventHandler(this.MenuToolRectSel_Click);
357 //
358 // MenuToolRectZoomIn
359 //
360 this.MenuToolRectZoomIn.Index = 3;
361 this.MenuToolRectZoomIn.Text = "Rectangular Zoom In";
362 this.MenuToolRectZoomIn.Click += new System.EventHandler(this.MenuToolRectZoomIn_Click);
363 //
364 // MenuToolRectZoomOut
365 //
366 this.MenuToolRectZoomOut.Index = 4;
367 this.MenuToolRectZoomOut.Text = "Rectangular Zoom Out";
368 this.MenuToolRectZoomOut.Click += new System.EventHandler(this.MenuToolRectZoomOut_Click);
369 //
370 // MenuToolAnnotEdit
371 //
372 this.MenuToolAnnotEdit.Index = 5;
373 this.MenuToolAnnotEdit.Text = "Annotation Editing";
374 this.MenuToolAnnotEdit.Click += new System.EventHandler(this.MenuToolAnnotEdit_Click);
375 //
376 // MenuToolLineCreate
377 //
378 this.MenuToolLineCreate.Index = 6;
379 this.MenuToolLineCreate.Text = "Line Creation";
380 this.MenuToolLineCreate.Click += new System.EventHandler(this.MenuToolLineCreate_Click);
381 //
382 // MenuToolRectCreate
383 //
384 this.MenuToolRectCreate.Index = 7;
385 this.MenuToolRectCreate.Text = "Rectangle Creation";
386 this.MenuToolRectCreate.Click += new System.EventHandler(this.MenuToolRectCreate_Click);
387 //
388 // MenuToolOvalCreate
389 //
390 this.MenuToolOvalCreate.Index = 8;
391 this.MenuToolOvalCreate.Text = "Oval Creation";
392 this.MenuToolOvalCreate.Click += new System.EventHandler(this.MenuToolOvalCreate_Click);
393 //
394 // MenuToolArrowCreate
395 //
396 this.MenuToolArrowCreate.Index = 9;
397 this.MenuToolArrowCreate.Text = "Arrow Creation";
398 this.MenuToolArrowCreate.Click += new System.EventHandler(this.MenuToolArrowCreate_Click);
399 //
400 // MenuToolFreeHand
401 //
402 this.MenuToolFreeHand.Index = 10;
403 this.MenuToolFreeHand.Text = "FreeHand Tool";
404 this.MenuToolFreeHand.Click += new System.EventHandler(this.MenuToolFreeHand_Click);
405 //
406 // menuItem5
407 //
408 this.menuItem5.Index = 4;
409 this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
410 this.MenuPageNavNext,
411 this.MenuPageNavPrev,
412 this.MenuPageNavFirst,
413 this.MenuPageNavLast});
414 this.menuItem5.Text = "Page Navigation";
415 //
416 // MenuPageNavNext
417 //
418 this.MenuPageNavNext.Index = 0;
419 this.MenuPageNavNext.Text = "Go To Next Page";
420 this.MenuPageNavNext.Click += new System.EventHandler(this.MenuPageNavNext_Click);
421 //
422 // MenuPageNavPrev
423 //
424 this.MenuPageNavPrev.Index = 1;
425 this.MenuPageNavPrev.Text = "Go To Previous Page";
426 this.MenuPageNavPrev.Click += new System.EventHandler(this.MenuPageNavPrev_Click);
427 //
428 // MenuPageNavFirst
429 //
430 this.MenuPageNavFirst.Index = 2;
431 this.MenuPageNavFirst.Text = "Go To First Page";
432 this.MenuPageNavFirst.Click += new System.EventHandler(this.MenuPageNavFirst_Click);
433 //
434 // MenuPageNavLast
435 //
436 this.MenuPageNavLast.Index = 3;
437 this.MenuPageNavLast.Text = "Go To Last Page";
438 this.MenuPageNavLast.Click += new System.EventHandler(this.MenuPageNavLast_Click);
439 //
440 // menuItem6
441 //
442 this.menuItem6.Index = 5;
443 this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
444 this.menuHelpAbout});
445 this.menuItem6.Text = "Help";
446 //
447 // menuHelpAbout
448 //
449 this.menuHelpAbout.Index = 0;
450 this.menuHelpAbout.Text = "About ...";
451 this.menuHelpAbout.Click += new System.EventHandler(this.menuHelpAbout_Click);
452 //
453 // PDFViewSimple
454 //
455 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
456 this.ClientSize = new System.Drawing.Size(619, 443);
457 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
458 this.Menu = this.mainMenu1;
459 this.Name = "PDFViewSimple";
460 this.Text = "PDFViewSimple";
461 this.ResumeLayout(false);
462
463 }
464 #endregion
465
466 /// <summary>
467 /// The main entry point for the application.
468 /// </summary>
469 [STAThread]
470 static void Main()
471 {
472 PDFNet.Initialize(PDFTronLicense.Key);
473 Application.Run(new PDFViewSimple());
474 }
475
476
477 private void menuFileOpen_Click(object sender, System.EventArgs e)
478 {
479 OpenFileDialog dlg = new OpenFileDialog();
480 dlg.CheckFileExists = true;
481 dlg.CheckPathExists = true;
482 dlg.Filter="PDF (*.pdf)|*.pdf|All files (*.*)|*.*";
483 dlg.DefaultExt = ".pdf";
484
485 if(dlg.ShowDialog() == DialogResult.OK)
486 {
487 OpenPDF(dlg.FileName);
488 }
489 }
490
491 public bool OpenPDF(String filename)
492 {
493 try
494 {
495 PDFDoc oldDoc = _pdfview.GetDoc();
496 _pdfdoc = new PDFDoc(filename);
497 if (!_pdfdoc.InitSecurityHandler())
498 {
499 AuthorizeDlg dlg = new AuthorizeDlg();
500 if (dlg.ShowDialog() == DialogResult.OK)
501 {
502 if(!_pdfdoc.InitStdSecurityHandler(dlg.pass.Text))
503 {
504 MessageBox.Show("Incorrect password");
505 return false;
506 }
507 }
508 else
509 {
510 return false;
511 }
512 }
513 _pdfview.SetDoc(_pdfdoc);
514
515 // Example calls to SetupThumbnails:
516
517 // To turn on thumbnail rendering (each 600x600), and retrieving
518 // thumbnails from the pdfs, but no persistent thumbnail caching on disk:
519 //_pdfview.SetupThumbnails(true, true, false, 600, "", 0);
520
521 // To cache 100 thumbnails, each 600x600, at "D:\\thumb_cache":
522 //_pdfview.SetupThumbnails(true, true, true, 600, "D:\\thumb_cache", 600 * 600 * 4 * 100);
523 // To programmatically delete the cache at "D:\\thumb_cache":
524 //_pdfview.SetupThumbnails(true, true, true, 600, "D:\\thumb_cache", 0);
525
526 // Example call to GetThumbAsync:
527 //PDFViewThumbAsyncDelegate my_del = delegate(int page_num, bool was_thumb_found, System.Drawing.Bitmap thumb_buf, int thumb_width, int thumb_height, object custom_data)
528 //{
529 // Console.WriteLine("Inside the callback for GetThumbAsync.");
530 //};
531 //_pdfview.GetThumbAsync(2, my_del, this);
532
533 // Use built-in navigation (thumbnails, bookmarks, layers, etc)?
534 // _pdfview.ShowNavToolbar(true);
535 // _pdfview.ShowNavPanel(true);
536
537 filePath = filename;
538 if (oldDoc != null)
539 {
540 oldDoc.Dispose();
541 }
542 }
543 catch(PDFNetException ex)
544 {
545 MessageBox.Show(ex.Message);
546 return false;
547 }
548 catch(Exception ex)
549 {
550 MessageBox.Show(ex.ToString());
551 return false;
552 }
553
554 this.Text = filename; // Set the title
555 return true;
556 }
557
558 private void MenuFileSave_Click(object sender, EventArgs e)
559 {
560 if (_pdfview.GetDoc() != null)
561 _pdfview.GetDoc().Save(filePath, SDFDoc.SaveOptions.e_remove_unused);
562 }
563
564 private void MenuFileSaveAs_Click(object sender, EventArgs e)
565 {
566 SaveAs();
567 }
568
569 private void SaveAs()
570 {
571 if (_pdfview.GetDoc() != null)
572 {
573 SaveFileDialog dlg = new SaveFileDialog();
574 dlg.Title = "Save Pdf File";
575 dlg.Filter = "PDF (*.pdf)|*.pdf|All files (*.*)|*.*";
576 dlg.DefaultExt = ".pdf";
577
578 if (dlg.ShowDialog() == DialogResult.OK)
579 if (dlg.FileName != null)
580 _pdfview.GetDoc().Save(dlg.FileName, SDFDoc.SaveOptions.e_remove_unused);
581 }
582 }
583
584 private void MenuFilePrint_Click(object sender, EventArgs e)
585 {
586 if (_pdfview.GetDoc() != null)
587 _pdfview.Print();
588 }
589
590 private void MenuFileExit_Click(object sender, System.EventArgs e)
591 {
592 PDFNet.Terminate();
593 //when the user clicks exit, exit the application
594 Application.Exit();
595 }
596
597 private void MenuEditFind_Click(object sender, EventArgs e)
598 {
599 if (_pdfview.GetDoc() != null)
600 _pdfview.Find();
601 }
602
603 private void MenuEditCopy_Click(object sender, EventArgs e)
604 {
605 if (_pdfview.GetDoc() != null)
606 _pdfview.Copy();
607 }
608
609 private void MenuEditSelect_Click(object sender, EventArgs e)
610 {
611 if (_pdfview.GetDoc() != null)
612 _pdfview.SelectAll();
613 }
614
615 private void MenuViewPageLayoutSingle_Click(object sender, EventArgs e)
616 {
617 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_page);
618 }
619
620 private void MenuViewPageLayoutSingleContinuous_Click(object sender, EventArgs e)
621 {
622 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_continuous);
623 }
624
625 private void MenuViewPageLayoutFacing_Click(object sender, EventArgs e)
626 {
627 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing);
628 }
629
630 private void MenuViewPageLayoutFacingContinuous_Click(object sender, EventArgs e)
631 {
632 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing_continuous);
633 }
634
635 private void MenuViewPageViewFitPage_Click(object sender, EventArgs e)
636 {
637 _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_page);
638 }
639
640 private void MenuViewPageViewFitWidth_Click(object sender, EventArgs e)
641 {
642 _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_width);
643 }
644
645 private void MenuViewZoomIn_Click(object sender, EventArgs e)
646 {
647 if (_pdfview.GetDoc() != null)
648 _pdfview.SetZoom(_pdfview.GetZoom() * 2);
649 }
650
651 private void MenuViewZoomOut_Click(object sender, EventArgs e)
652 {
653 if (_pdfview.GetDoc() != null)
654 _pdfview.SetZoom(_pdfview.GetZoom() / 2);
655 }
656
657 private void MenuToolPan_Click(object sender, EventArgs e)
658 {
659 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_pan);
660 }
661
662 private void MenuToolStructSel_Click(object sender, EventArgs e)
663 {
664 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_struct_select);
665 }
666
667 private void MenuToolRectSel_Click(object sender, EventArgs e)
668 {
669 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_rect_select);
670 }
671
672 private void MenuToolRectZoomIn_Click(object sender, EventArgs e)
673 {
674 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_in);
675 }
676
677 private void MenuToolRectZoomOut_Click(object sender, EventArgs e)
678 {
679 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_out);
680 }
681
682 private void MenuToolAnnotEdit_Click(object sender, EventArgs e)
683 {
684 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_annot_edit);
685 }
686
687 private void MenuToolLineCreate_Click(object sender, EventArgs e)
688 {
689 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_line_create);
690 }
691
692 private void MenuToolRectCreate_Click(object sender, EventArgs e)
693 {
694 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_rect_create);
695 }
696
697 private void MenuToolOvalCreate_Click(object sender, EventArgs e)
698 {
699 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_oval_create);
700 }
701
702 private void MenuToolArrowCreate_Click(object sender, EventArgs e)
703 {
704 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_arrow_create);
705 }
706
707 private void MenuToolFreeHand_Click(object sender, EventArgs e)
708 {
709 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_ink_create);
710 }
711
712 private void MenuPageNavNext_Click(object sender, EventArgs e)
713 {
714 if (_pdfview.GetDoc() != null)
715 _pdfview.GotoNextPage();
716 }
717
718 private void MenuPageNavPrev_Click(object sender, EventArgs e)
719 {
720 if (_pdfview.GetDoc() != null)
721 _pdfview.GotoPreviousPage();
722 }
723
724 private void MenuPageNavFirst_Click(object sender, EventArgs e)
725 {
726 if (_pdfview.GetDoc() != null)
727 _pdfview.GotoFirstPage();
728 }
729
730 private void MenuPageNavLast_Click(object sender, EventArgs e)
731 {
732 if (_pdfview.GetDoc() != null)
733 _pdfview.GotoLastPage();
734 }
735
736 private void menuHelpAbout_Click(object sender, EventArgs e)
737 {
738 MessageBox.Show(
739 "\n\t PDFViewSimple, Version 1.0\t\n" +
740 "\n\t Copyright (c) 2009\t\n" +
741 "\n\tSimple Sample of using PDFViewCtrl in Win32\t\n\n",
742 "About PDFviewSimple");
743 }
744
745 private void menuItem7_Click(object sender, System.EventArgs e)
746 {
747 this.menuItemNavPanel.Checked = !_pdfview.IsNavPanelVisible();
748 _pdfview.ShowNavPanel(this.menuItemNavPanel.Checked);
749 }
750
751 }
752}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5// This sample shows how to add PDF viewer control in a basic Win32 project.
6// The sample uses a number of built-in features from PDFViewCtrl to implement
7// document navigation, text highlighting, markup, and editing.
8//
9// PDFViewCtrl offers built-in support for a number of PDF tools (including markup,
10// link creation, forms, text selection, etc) and user interface elements (such as
11// navigation panel, find text, etc). PDFViewCtrl is highly configurable allowing
12// users to implement custom tools or to modify behavior of built-in tools.
13// Default user interface elements such as the navigation panel can be replaced
14// with a custom implementation and users can override window events and various
15// document actions. For example, by default, PDFViewCtrl will launch URL links
16// in a web browser and will jump to a destination for 'GoTo' actions. The default
17// behavior can be overridden using a custom callback function (as shown in the
18// following sample).
19//
20// Besides PDFViewCtrl, the C++ version of PDFNet SDK also includes a low-level class
21// called PDFView. Because PDFView does not process any window messages and does not
22// implement built-in tools it is only suitable for very low-level control development
23// (e.g. if you would like to implement a control similar to PDFViewCtrl from scratch).
24// The basic use of PDFView is illustrated in PDFView sample project.
25//---------------------------------------------------------------------------------------
26
27#include "stdafx.h"
28#include "resource.h"
29#include <Common/Exception.h>
30#include <commdlg.h>
31#include <cassert>
32#include <PDF/PDFViewCtrl.h>
33#include <PDF/PDFDraw.h>
34#include <PDF/PDFNet.h>
35#include <stdlib.h>
36#include <iostream>
37#include <utility>
38#include <algorithm>
39#include <memory>
40#include "../../LicenseKey/CPP/LicenseKey.h"
41
42using namespace pdftron;
43using namespace PDF;
44
45#define MAX_LOADSTRING 100
46
47// Global Variables:
48HINSTANCE hInst; // current instance
49TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
50TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
51UString m_doc_name;
52std::auto_ptr<PDF::PDFDoc> mp_doc;
53std::auto_ptr<PDF::PDFViewCtrl> m_view;
54
55
56// Forward declarations of functions included in this code module:
57ATOM MyRegisterClass(HINSTANCE hInstance);
58BOOL InitInstance(HINSTANCE, int);
59LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
60INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
61
62int APIENTRY _tWinMain(HINSTANCE hInstance,
63 HINSTANCE hPrevInstance,
64 LPTSTR lpCmdLine,
65 int nCmdShow)
66{
67 UNREFERENCED_PARAMETER(hPrevInstance);
68 UNREFERENCED_PARAMETER(lpCmdLine);
69
70 // TODO: Place code here.
71 MSG msg;
72 HACCEL hAccelTable;
73
74 // Initialize global strings
75 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
76 LoadString(hInstance, IDC_PDFVIEWSIMPLE, szWindowClass, MAX_LOADSTRING);
77 MyRegisterClass(hInstance);
78
79 // Perform application initialization:
80 if (!InitInstance (hInstance, nCmdShow))
81 {
82 return FALSE;
83 }
84
85 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));
86
87 // Main message loop:
88 while (GetMessage(&msg, NULL, 0, 0))
89 {
90 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
91 {
92 TranslateMessage(&msg);
93 DispatchMessage(&msg);
94 }
95 }
96
97 return (int) msg.wParam;
98}
99
100
101
102//
103// FUNCTION: MyRegisterClass()
104//
105// PURPOSE: Registers the window class.
106//
107// COMMENTS:
108//
109// This function and its usage are only necessary if you want this code
110// to be compatible with Win32 systems prior to the 'RegisterClassEx'
111// function that was added to Windows 95. It is important to call this function
112// so that the application will get 'well formed' small icons associated
113// with it.
114//
115ATOM MyRegisterClass(HINSTANCE hInstance)
116{
117 WNDCLASSEX wcex;
118
119 wcex.cbSize = sizeof(WNDCLASSEX);
120
121 wcex.style = CS_HREDRAW | CS_VREDRAW;
122 wcex.lpfnWndProc = WndProc;
123 wcex.cbClsExtra = 0;
124 wcex.cbWndExtra = 0;
125 wcex.hInstance = hInstance;
126 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PDFVIEWSIMPLE));
127 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
128 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
129 wcex.lpszMenuName = MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE);
130 wcex.lpszClassName = szWindowClass;
131 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
132
133 return RegisterClassEx(&wcex);
134}
135
136
137typedef std::pair< int, PDF::PDFViewCtrl::ToolMode > ToolModeMapType;
138const ToolModeMapType toolModeMap[] = {
139 ToolModeMapType( IDM_TOOL_PAN , PDF::PDFViewCtrl::e_pan ),
140 ToolModeMapType( IDM_TOOL_STRUCTURALSELECTION , PDF::PDFViewCtrl::e_text_struct_select ),
141 ToolModeMapType( IDM_TOOL_RECTANGLESELECTION , PDF::PDFViewCtrl::e_text_rect_select ),
142 ToolModeMapType( IDM_TOOL_RECTANGLEZOOMIN , PDF::PDFViewCtrl::e_zoom_in ),
143 ToolModeMapType( IDM_TOOL_RECTANGLEZOOMOUT , PDF::PDFViewCtrl::e_zoom_out ),
144 ToolModeMapType( IDM_TOOL_ANNOTATIONEDITING , PDF::PDFViewCtrl::e_annot_edit ),
145 ToolModeMapType( IDM_TOOL_TEXTANNOTCREATION , PDF::PDFViewCtrl::e_text_annot_create ),
146 ToolModeMapType( IDM_TOOL_LINECREATION , PDF::PDFViewCtrl::e_line_create ),
147 ToolModeMapType( IDM_TOOL_ARROWCREATION , PDF::PDFViewCtrl::e_arrow_create ),
148 ToolModeMapType( IDM_TOOL_RECTANGLECREATION , PDF::PDFViewCtrl::e_rect_create ),
149 ToolModeMapType( IDM_TOOL_OVALCREATION , PDF::PDFViewCtrl::e_oval_create ),
150 ToolModeMapType( IDM_TOOL_FREEHANDTOOL , PDF::PDFViewCtrl::e_ink_create ),
151 ToolModeMapType( IDM_TOOL_STAMPCREATIONTOOL , PDF::PDFViewCtrl::e_stamp_create ),
152 ToolModeMapType( ID_TOOL_HIGHLIGHTTOOL , PDF::PDFViewCtrl::e_highlight_create ),
153 ToolModeMapType( ID_TOOL_UNDERLINETOOL , PDF::PDFViewCtrl::e_underline_create ),
154 ToolModeMapType( ID_TOOL_STRIKEOUTTOOL , PDF::PDFViewCtrl::e_strikeout_create ),
155 ToolModeMapType( ID_TOOL_SQUIGGLYUNDERLINETOOL , PDF::PDFViewCtrl::e_squiggly_create ),
156 ToolModeMapType( ID_TOOL_CALLOUTTEXTBOXTOOL , PDF::PDFViewCtrl::e_calloutbox_create ),
157 ToolModeMapType( ID_TOOL_SIMPLETEXTBOXTOOL , PDF::PDFViewCtrl::e_text_box_create ),
158 ToolModeMapType( ID_TOOL_POLYGONTOOL , PDF::PDFViewCtrl::e_polygon_create ),
159 ToolModeMapType( ID_TOOL_POLYLINETOOL , PDF::PDFViewCtrl::e_polyline_create ),
160 ToolModeMapType( ID_TOOL_FILEATTACHMENTTOOL , PDF::PDFViewCtrl::e_file_attachment ),
161 ToolModeMapType( ID_TOOL_SOUNDATTACHMENTTOOL , PDF::PDFViewCtrl::e_sound_attachment ),
162 ToolModeMapType( ID_TOOL_MOVIEINSERTIONTOOL , PDF::PDFViewCtrl::e_movie_attachment ),
163 ToolModeMapType( ID_TOOL_CARETPLACEMENTTOOL , PDF::PDFViewCtrl::e_caret_create ),
164 ToolModeMapType( ID_TOOL_REDACTIONTOOL , PDF::PDFViewCtrl::e_redaction_create ),
165 ToolModeMapType( ID_TOOL_TEXTFIELDCREATION , PDF::PDFViewCtrl::e_text_field_create ),
166 ToolModeMapType( ID_TOOL_CHECKBOXCREATIONTOOL , PDF::PDFViewCtrl::e_check_box_create ),
167 ToolModeMapType( ID_TOOL_RADIOBUTTON , PDF::PDFViewCtrl::e_radio_button_create ),
168 ToolModeMapType( ID_TOOL_LISTBOX , PDF::PDFViewCtrl::e_list_box_create ),
169 ToolModeMapType( ID_TOOL_COMBOBOX , PDF::PDFViewCtrl::e_combo_box_create ),
170 ToolModeMapType( ID_TOOL_BUTTONCREATIONTOOL , PDF::PDFViewCtrl::e_button_create )
171};
172const ToolModeMapType* const toolModeMapEnd = toolModeMap + sizeof(toolModeMap)/sizeof(ToolModeMapType);
173struct ToolModePred {
174 int m_code;
175 ToolModePred( int c ) : m_code(c) {}
176 bool operator()( ToolModeMapType tp ) { return tp.first == m_code; }
177};
178
179
180
181// FUNCTION: InitInstance(HINSTANCE, int)
182//
183// PURPOSE: Saves instance handle and creates main window
184//
185// COMMENTS:
186//
187// In this function, we save the instance handle in a global variable and
188// create and display the main program window.
189//
190BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
191{
192 PDFNet::Initialize(LicenseKey);
193 // PDFNet::SetColorManagement();
194
195 HWND hWnd;
196 hInst = hInstance; // Store instance handle in our global variable
197
198 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
199 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
200
201
202 if (!hWnd)
203 {
204 return FALSE;
205 }
206
207 ShowWindow(hWnd, nCmdShow);
208
209 // Optional: PDFViewCtrl can save its UI state across different sessions.
210 // In this case the config file is save in the current working folder.
211 //m_view->LoadCurrentConfiguration( "my.cfg" );
212 UpdateWindow(hWnd);
213
214 return TRUE;
215}
216
217void ErrorCallback(const char* message, void* custom_data)
218{
219 static bool reported_once = false;
220 if (!reported_once) {
221 reported_once = true;
222 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
223 ::MessageBoxA(hwnd, message, "Error", MB_OK);
224 }
225}
226
227void DownloadCallback(DownloadedType type, PDFDoc* doc, int page_num, int obj_num, const char* message, void* custom_data)
228{
229 switch(type)
230 {
231 case PDF::e_downloadedtype_opened :
232 // e_opened indicates that we have a valid, but incomplete PDFDoc.
233 // the PDF should be treated as read only, and only simple functions
234 // should be called on the doc, until e_finished has been called.
235 break;
236 case PDF::e_downloadedtype_page :
237 // this indicates the entire page is downloaded and it is safe to modify
238 // for example add a new annotation
239 break;
240 case PDF::e_downloadedtype_finished :
241 {
242 // we now have the full PDF file and it can be treated like any other
243 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
244 if(::MessageBoxA(hwnd, "Download complete, would you like to save the PDF locally?",
245 "PDF Downloaded", MB_YESNO)==IDYES)
246 {
247 ::PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_FILE_SAVEAS,0), 0);
248 }
249 }
250 break;
251 case PDF::e_downloadedtype_failed :
252 {
253 // downloading has stopped if this occurs
254 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
255 ::MessageBoxA(hwnd, message, "Error", MB_OK);
256 }
257 break;
258 }
259}
260
261TRN_Bool MyActionHandler( TRN_Action act, void* custom_data )
262{
263 Action action(act);
264 if (!action.IsValid()) return 1;
265
266 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
267
268 Action::Type type = action.GetType();
269 if (type == Action::e_GoTo)
270 {
271 Destination dest = action.GetDest();
272 if (!dest.IsValid()) {
273 MessageBoxA(hwnd, "Destination is not valid", "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
274 }
275 else {
276 int page_num = dest.GetPage().GetIndex();
277 char buf[256];
278 sprintf(buf, " Links to: page number %d in this document", page_num);
279 MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
280 return 0; // -> execute the default action handler.
281 }
282 }
283 else if (type == Action::e_URI)
284 {
285 UString uri;
286 action.GetSDFObj().Get("URI").Value().GetAsPDFText(uri);
287
288 char buf[256];
289 sprintf(buf, " Links to: %s", uri.ConvertToAscii().c_str());
290 MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK);
291 }
292 else
293 {
294 MessageBoxA(hwnd, "Other Action Type -> Handled by PDFViewCtrl", "MyURLActionHandler", MB_OK);
295 return 0; // -> execute the default action handler.
296 }
297
298 // If this function returns true, PDFViewCtrl will not execute the default
299 // action internally (in case of URL the default action is to open the URL
300 // link in a web browser).
301 return 1;
302}
303
304TRN_Bool MyMouseDoubleClickEvent( PDFViewCtrl::MouseEvent* evt, void* custom_data)
305{
306 if (!evt->m_pdfviewctrl_processed) // Display the message box before the message is processed by PDFNet?
307 {
308 HWND hwnd = (HWND) custom_data; // Case custom data to the expected argument.
309 MessageBoxA(hwnd, "Example of a custom event", "MyMouseDoubleClickEvent", MB_OK);
310 return false; // execute built-in event. To skip event processing in PDFViewCtrl return true.
311 }
312 return false;
313}
314
315BOOL OpenURLProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
316{
317 switch( iMessage ){
318 case WM_COMMAND:
319 switch( LOWORD( wParam ) ){
320 case IDOK :
321 {
322 char url[MAX_PATH];
323 char pass[MAX_PATH];
324 GetDlgItemTextA(hDlg, IDC_OPENURL_URL, url, MAX_PATH);
325 GetDlgItemTextA(hDlg, IDC_OPENURL_PASSWORD, pass, MAX_PATH);
326 m_view->CloseDoc();
327 mp_doc.reset();
328 // Open a PDF file at the given url. This works best with PDF's that
329 // are linearized, as pages can be downloaded and viewed in random access order,
330 // without the need to download the entire document. A viewing session can also be
331 // persisted across multiple viewing/application sessions to remove redundant downloads
332 // and improve overall performance by using the optional cache_file parameter.
333 m_view->OpenURLAsync(&url[0], "", &pass[0]);
334 // IMPORTANT: PDFViewCtrl 'owns' downloaded documents, so don't take
335 // ownership of the document (mp_doc == null)
336 }
337 // fall through
338 case IDCANCEL:
339 EndDialog(hDlg, wParam);
340 return TRUE;
341 }
342 break;
343 }
344 return FALSE;
345}
346
347LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
348{
349 int wmId, wmEvent;
350 PAINTSTRUCT ps;
351 HDC hdc;
352 static HMENU hMenu ;
353
354 switch (message)
355 {
356 case WM_CREATE:
357 {
358 m_view = std::auto_ptr<pdftron::PDF::PDFViewCtrl>(new pdftron::PDF::PDFViewCtrl(hWnd, hInst));
359 hMenu = LoadMenu (hInst, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));
360 hMenu = GetSubMenu (hMenu, 0);
361
362 // m_view->SetProgressiveRendering(false);
363 // m_view->SetPageBorderVisibility(false);
364 // m_view->SetPageSpacing(0, 0, 0, 0);
365 // m_view->SetDefaultPageColor(255, 255, 255);
366 // m_view->ShowNavPanel(true);
367 // m_view->ShowNavToolbar(true);
368 // m_view->SetAntiAliasing( true );
369 // m_view->SetGamma(0.01);
370
371 m_view->SetErrorReportHandler(ErrorCallback, hWnd);
372 m_view->SetActionHandler(MyActionHandler, hWnd);
373 m_view->SetDownloadReportHandler(DownloadCallback, hWnd);
374
375 PDFViewCtrl::EventHandlers my_handlers;
376 my_handlers.mouse_left_dclick = MyMouseDoubleClickEvent;
377 my_handlers.custom_data = hWnd;
378 m_view->SetCustomEventHandlers( &my_handlers );
379 }
380 break;
381
382 case WM_COMMAND:
383 {
384 wmId = LOWORD(wParam);
385 wmEvent = HIWORD(wParam);
386
387 const ToolModeMapType* const wmId_it = std::find_if( toolModeMap, toolModeMapEnd, ToolModePred(wmId) );
388 if( wmId_it != toolModeMapEnd )
389 m_view->SetToolMode( wmId_it->second );
390 else {
391
392 switch (wmId)
393 {
394 case IDM_ABOUT:
395 // DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
396 break;
397 case IDM_EXIT:
398 DestroyWindow(hWnd);
399 break;
400 case IDM_FILE_PRINT:
401 {
402 if(m_view->GetDoc())
403 m_view->Print();
404 }
405 break;
406 case IDM_FILE_SAVEAS:
407 {
408 if(m_view->GetDoc())
409 {
410 TCHAR szFile[256] = { 0 };
411 TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
412 TEXT("*.pdf\0")
413 TEXT("All Files\0")
414 TEXT("*.*\0");
415 OPENFILENAME ofn;
416 ZeroMemory(&ofn, sizeof(OPENFILENAME));
417 ofn.lStructSize=sizeof(OPENFILENAME);
418 ofn.lpstrFilter=szFilter;
419 ofn.nFilterIndex=1;
420 ofn.lpstrFile=szFile;
421 ofn.nMaxFile=sizeof(szFile);
422 ofn.lpstrTitle=_T("Save PDF File");
423 ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
424 //===Start the File Dialog
425 if(GetSaveFileName(&ofn))
426 {
427 m_view->GetDoc()->Save(UString(ofn.lpstrFile), SDF::SDFDoc::e_linearized, 0);
428 }
429 }
430 }
431 break;
432 case IDM_FILE_SAVE:
433 {
434 if(m_view->GetDoc())
435 {
436 if(m_view->GetDoc())
437 {
438 m_view->GetDoc()->Save(m_doc_name, SDF::SDFDoc::e_remove_unused, 0);
439 }
440 }
441 }
442 break;
443 case IDM_FILE_OPEN:
444 {
445 //===File path
446 TCHAR szFile[256] = { 0 };
447 //===Filter
448 TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
449 TEXT("*.pdf\0")
450 TEXT("All Files\0")
451 TEXT("*.*\0");
452 OPENFILENAME ofn;
453 ZeroMemory(&ofn, sizeof(OPENFILENAME));
454 ofn.lStructSize=sizeof(OPENFILENAME);
455 ofn.lpstrFilter=szFilter;
456 ofn.nFilterIndex=1;
457 ofn.lpstrFile=szFile;
458 ofn.nMaxFile=sizeof(szFile);
459 ofn.lpstrTitle=_T("Open PDF File");
460 ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
461 //===Start the File Dialog
462 if(GetOpenFileName(&ofn))
463 {
464 m_doc_name=UString(ofn.lpstrFile);
465 try{
466 std::auto_ptr<PDF::PDFDoc> doc(new PDF::PDFDoc(m_doc_name));
467 if(m_view->SetDoc(*doc))
468 {
469 mp_doc=doc;
470 // m_view->ShowNavPanel(true);
471 // m_view->ShowNavToolbar(true);
472 }
473 }
474 catch(...)
475 {
476 ::MessageBoxA(hWnd,"An error occurred while opening a file","PDFViewSimple Error",MB_OK);
477 }
478 }
479 }
480 break;
481 case IDM_FILE_OPENURL:
482 {
483 ::DialogBox(hInst, MAKEINTRESOURCE(IDD_OPENURL), hWnd, DLGPROC(OpenURLProc));
484 }
485 break;
486 case IDM_PAGELAYOUT_SINGLEPAGE:
487 {
488 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_page);
489 }
490 break;
491 case IDM_PAGELAYOUT_SINGLECONTINUOUS:
492 {
493 if(m_view->GetDoc())
494 {
495 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_continuous);
496 }
497 }
498 break;
499 case IDM_PAGELAYOUT_FACING:
500 {
501 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing);
502 }
503 break;
504 case IDM_PAGELAYOUT_FACINGCONTINUOUS:
505 {
506 if(m_view->GetDoc())
507 {
508 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous);
509 }
510 }
511 break;
512 case IDM_PAGELAYOUT_FACING_COVER:
513 {
514 if(m_view->GetDoc())
515 {
516 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_cover);
517 }
518 }
519 break;
520 case IDM_PAGELAYOUT_FACINGCONTINUOUS_COVER:
521 {
522 if(m_view->GetDoc())
523 {
524 m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous_cover);
525 }
526 }
527 break;
528 case IDM_PAGEVIEWMODE_FITPAGE:
529 {
530 m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_page);
531 }
532 break;
533 case IDM_PAGEVIEWMODE_FITWIDTH:
534 {
535 m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_width);
536 }
537 break;
538 case IDM_VIEW_ZOOMIN:
539 {
540 if(m_view->GetDoc())
541 {
542 m_view->SetZoom(m_view->GetZoom()*2);
543 }
544 }
545 break;
546 case IDM_VIEW_ZOOMOUT:
547 {
548 if(m_view->GetDoc())
549 {
550 m_view->SetZoom(m_view->GetZoom()/2);
551 }
552 }
553 break;
554 case IDM_PAGENAVIGATION_GOTONEXTPAGE:
555 {
556 if(m_view->GetDoc())
557 {
558 m_view->GotoNextPage();
559 }
560 }
561 break;
562 case IDM_PAGENAVIGATION_GOTOPREVIOUSPAGE:
563 {
564 if(m_view->GetDoc())
565 {
566 m_view->GotoPreviousPage();
567 }
568 }
569 break;
570 case IDM_PAGENAVIGATION_GOT:
571 {
572 if(m_view->GetDoc())
573 {
574 m_view->GotoLastPage();
575 }
576 }
577 break;
578 case IDM_PAGENAVIGATION_GOTOFIRSTPAGE:
579 {
580 if(m_view->GetDoc())
581 {
582 m_view->GotoFirstPage();
583 }
584 }
585 break;
586 case IDM_EDIT_COPY:
587 {
588 if(m_view->GetDoc())
589 {
590 m_view->Copy();
591 }
592 }
593 break;
594 case IDM_EDIT_FIND:
595 {
596 if(m_view->GetDoc())
597 {
598 m_view->Find();
599 }
600 }
601 break;
602 case IDM_EDIT_SELECTALL:
603 {
604 if(m_view->GetDoc())
605 {
606 m_view->SelectAll();
607 }
608 }
609 break;
610 case ID_TOGGLE_NAV_PANEL:
611 m_view->ShowNavPanel(!m_view->IsNavPanelVisible());
612 break;
613 default:
614 return DefWindowProc(hWnd, message, wParam, lParam);
615 }
616 }
617 }
618 break;
619 case WM_PAINT:
620 hdc = BeginPaint(hWnd, &ps);
621 // TODO: Add any drawing code here...
622 EndPaint(hWnd, &ps);
623 break;
624 case WM_CLOSE:
625 //m_view->SaveCurrentConfiguration("my.cfg");
626 m_view.reset();
627 DestroyWindow(hWnd);
628 return 0;
629 case WM_DESTROY:
630 PostQuitMessage(0);
631 return 0;
632 case WM_SIZE:
633 // this is never getting called, wxWidgets handles these events internally
634 break;
635 default:
636 return DefWindowProc(hWnd, message, wParam, lParam);
637 }
638 return 0;
639}
640
641// Message handler for about box.
642INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
643{
644 UNREFERENCED_PARAMETER(lParam);
645 switch (message)
646 {
647 case WM_INITDIALOG:
648 return (INT_PTR)TRUE;
649
650 case WM_COMMAND:
651 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
652 {
653 EndDialog(hDlg, LOWORD(wParam));
654 return (INT_PTR)TRUE;
655 }
656 break;
657 }
658 return (INT_PTR)FALSE;
659}
1Imports System
2Imports System.Drawing
3Imports System.Collections
4Imports System.ComponentModel
5Imports System.Windows.Forms
6
7Imports pdftron
8Imports pdftron.PDF
9Imports pdftron.Filters
10Imports pdftron.Common
11Imports pdftron.SDF
12
13Namespace PDFViewSimpleTestVB
14 Module PDFViewSimpleTestVB
15 Dim pdfNetLoader As PDFNetLoader
16 Sub New()
17 pdfNetLoader = pdftron.PDFNetLoader.Instance()
18 End Sub
19
20 <STAThread()> Sub Main()
21 PDFNet.Initialize(PDFTronLicense.Key)
22 Application.Run(New PDFViewSimple)
23 End Sub
24 End Module
25End Namespace
26
27Public Class PDFViewSimple
28 Inherits System.Windows.Forms.Form
29 Private components As System.ComponentModel.IContainer
30 Private mainMenu1 As System.Windows.Forms.MainMenu
31 Private menuItem1 As System.Windows.Forms.MenuItem
32 Private menuItem5 As System.Windows.Forms.MenuItem
33 Private WithEvents MenuFileOpen As System.Windows.Forms.MenuItem
34 Private WithEvents MenuFileExit As System.Windows.Forms.MenuItem
35 Private _pdfview As PDFViewCtrl
36 Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
37 Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
38 Friend WithEvents MenuViewZoomIn As System.Windows.Forms.MenuItem
39 Friend WithEvents MenuViewZoomOut As System.Windows.Forms.MenuItem
40 Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
41 Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
42 Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
43 Friend WithEvents MenuFileSave As System.Windows.Forms.MenuItem
44 Friend WithEvents MenuFileSaveAs As System.Windows.Forms.MenuItem
45 Friend WithEvents MenuFilePrint As System.Windows.Forms.MenuItem
46 Friend WithEvents MenuEditFind As System.Windows.Forms.MenuItem
47 Friend WithEvents MenuEditCopy As System.Windows.Forms.MenuItem
48 Friend WithEvents MenuEditSelectAll As System.Windows.Forms.MenuItem
49 Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
50 Friend WithEvents MenuSinglePage As System.Windows.Forms.MenuItem
51 Friend WithEvents MenuSingleContinuous As System.Windows.Forms.MenuItem
52 Friend WithEvents MenuFacing As System.Windows.Forms.MenuItem
53 Friend WithEvents MenuFacingContinuous As System.Windows.Forms.MenuItem
54 Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem
55 Friend WithEvents MenuFitPage As System.Windows.Forms.MenuItem
56 Friend WithEvents MenuFitWidth As System.Windows.Forms.MenuItem
57 Friend WithEvents MenuToolPan As System.Windows.Forms.MenuItem
58 Friend WithEvents MenuGotoNext As System.Windows.Forms.MenuItem
59 Friend WithEvents MenuHelpAbout As System.Windows.Forms.MenuItem
60 Friend WithEvents MenuGotoPrev As System.Windows.Forms.MenuItem
61 Friend WithEvents MenuGotoLast As System.Windows.Forms.MenuItem
62 Friend WithEvents MenuGotoFirst As System.Windows.Forms.MenuItem
63 Friend WithEvents MenuToolStructSelect As System.Windows.Forms.MenuItem
64 Friend WithEvents MenuToolRectSelect As System.Windows.Forms.MenuItem
65 Friend WithEvents MenuToolRectZoomIn As System.Windows.Forms.MenuItem
66 Friend WithEvents MenuToolRectZoomOut As System.Windows.Forms.MenuItem
67 Friend WithEvents MenuToolAnnotEdit As System.Windows.Forms.MenuItem
68 Friend WithEvents MenuToolLineCreate As System.Windows.Forms.MenuItem
69 Friend WithEvents MenuToolRectCreate As System.Windows.Forms.MenuItem
70 Friend WithEvents MenuToolOvalCreate As System.Windows.Forms.MenuItem
71 Friend WithEvents MenuToolArrayCreate As System.Windows.Forms.MenuItem
72 Friend WithEvents MenuToolFreeHand As System.Windows.Forms.MenuItem
73 Private _pdfdoc As PDFDoc
74
75 Public Sub New()
76 InitializeComponent()
77 _pdfview = New PDFViewCtrl
78 _pdfview.Location = New System.Drawing.Point(0, 0)
79 _pdfview.Dock = System.Windows.Forms.DockStyle.Fill
80 Controls.Add(_pdfview)
81 End Sub
82
83 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
84 If disposing Then
85 If Not (components Is Nothing) Then
86 components.Dispose()
87 End If
88 End If
89 MyBase.Dispose(disposing)
90 End Sub
91
92 Private Sub InitializeComponent()
93 Me.components = New System.ComponentModel.Container
94 Me.mainMenu1 = New System.Windows.Forms.MainMenu
95 Me.menuItem1 = New System.Windows.Forms.MenuItem
96 Me.MenuFileOpen = New System.Windows.Forms.MenuItem
97 Me.MenuFileSave = New System.Windows.Forms.MenuItem
98 Me.MenuFileSaveAs = New System.Windows.Forms.MenuItem
99 Me.MenuFilePrint = New System.Windows.Forms.MenuItem
100 Me.menuItem5 = New System.Windows.Forms.MenuItem
101 Me.MenuFileExit = New System.Windows.Forms.MenuItem
102 Me.MenuItem2 = New System.Windows.Forms.MenuItem
103 Me.MenuEditFind = New System.Windows.Forms.MenuItem
104 Me.MenuEditCopy = New System.Windows.Forms.MenuItem
105 Me.MenuEditSelectAll = New System.Windows.Forms.MenuItem
106 Me.MenuItem3 = New System.Windows.Forms.MenuItem
107 Me.MenuItem14 = New System.Windows.Forms.MenuItem
108 Me.MenuSinglePage = New System.Windows.Forms.MenuItem
109 Me.MenuSingleContinuous = New System.Windows.Forms.MenuItem
110 Me.MenuFacing = New System.Windows.Forms.MenuItem
111 Me.MenuFacingContinuous = New System.Windows.Forms.MenuItem
112 Me.MenuItem15 = New System.Windows.Forms.MenuItem
113 Me.MenuFitPage = New System.Windows.Forms.MenuItem
114 Me.MenuFitWidth = New System.Windows.Forms.MenuItem
115 Me.MenuViewZoomIn = New System.Windows.Forms.MenuItem
116 Me.MenuViewZoomOut = New System.Windows.Forms.MenuItem
117 Me.MenuItem4 = New System.Windows.Forms.MenuItem
118 Me.MenuToolPan = New System.Windows.Forms.MenuItem
119 Me.MenuToolStructSelect = New System.Windows.Forms.MenuItem
120 Me.MenuToolRectSelect = New System.Windows.Forms.MenuItem
121 Me.MenuToolRectZoomIn = New System.Windows.Forms.MenuItem
122 Me.MenuToolRectZoomOut = New System.Windows.Forms.MenuItem
123 Me.MenuToolAnnotEdit = New System.Windows.Forms.MenuItem
124 Me.MenuToolLineCreate = New System.Windows.Forms.MenuItem
125 Me.MenuToolRectCreate = New System.Windows.Forms.MenuItem
126 Me.MenuToolOvalCreate = New System.Windows.Forms.MenuItem
127 Me.MenuToolArrayCreate = New System.Windows.Forms.MenuItem
128 Me.MenuToolFreeHand = New System.Windows.Forms.MenuItem
129 Me.MenuItem6 = New System.Windows.Forms.MenuItem
130 Me.MenuGotoNext = New System.Windows.Forms.MenuItem
131 Me.MenuGotoPrev = New System.Windows.Forms.MenuItem
132 Me.MenuGotoLast = New System.Windows.Forms.MenuItem
133 Me.MenuGotoFirst = New System.Windows.Forms.MenuItem
134 Me.MenuItem7 = New System.Windows.Forms.MenuItem
135 Me.MenuHelpAbout = New System.Windows.Forms.MenuItem
136 Me.SuspendLayout()
137 '
138 'mainMenu1
139 '
140 Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem6, Me.MenuItem7})
141 '
142 'menuItem1
143 '
144 Me.menuItem1.Index = 0
145 Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuFileOpen, Me.MenuFileSave, Me.MenuFileSaveAs, Me.MenuFilePrint, Me.menuItem5, Me.MenuFileExit})
146 Me.menuItem1.Text = "File"
147 '
148 'MenuFileOpen
149 '
150 Me.MenuFileOpen.Index = 0
151 Me.MenuFileOpen.Text = "Open"
152 '
153 'MenuFileSave
154 '
155 Me.MenuFileSave.Index = 1
156 Me.MenuFileSave.Text = "Save"
157 '
158 'MenuFileSaveAs
159 '
160 Me.MenuFileSaveAs.Index = 2
161 Me.MenuFileSaveAs.Text = "Save As"
162 '
163 'MenuFilePrint
164 '
165 Me.MenuFilePrint.Index = 3
166 Me.MenuFilePrint.Text = "Print"
167 '
168 'menuItem5
169 '
170 Me.menuItem5.Index = 4
171 Me.menuItem5.Text = "-"
172 '
173 'MenuFileExit
174 '
175 Me.MenuFileExit.Index = 5
176 Me.MenuFileExit.Text = "Exit"
177 '
178 'MenuItem2
179 '
180 Me.MenuItem2.Index = 1
181 Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuEditFind, Me.MenuEditCopy, Me.MenuEditSelectAll})
182 Me.MenuItem2.Text = "Edit"
183 '
184 'MenuEditFind
185 '
186 Me.MenuEditFind.Index = 0
187 Me.MenuEditFind.Text = "Find..."
188 '
189 'MenuEditCopy
190 '
191 Me.MenuEditCopy.Index = 1
192 Me.MenuEditCopy.Text = "Copy"
193 '
194 'MenuEditSelectAll
195 '
196 Me.MenuEditSelectAll.Index = 2
197 Me.MenuEditSelectAll.Text = "Select All"
198 '
199 'MenuItem3
200 '
201 Me.MenuItem3.Index = 2
202 Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem14, Me.MenuItem15, Me.MenuViewZoomIn, Me.MenuViewZoomOut})
203 Me.MenuItem3.Text = "View"
204 '
205 'MenuItem14
206 '
207 Me.MenuItem14.Index = 0
208 Me.MenuItem14.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuSinglePage, Me.MenuSingleContinuous, Me.MenuFacing, Me.MenuFacingContinuous})
209 Me.MenuItem14.Text = "Page Layout"
210 '
211 'MenuSinglePage
212 '
213 Me.MenuSinglePage.Index = 0
214 Me.MenuSinglePage.Text = "Single Page"
215 '
216 'MenuSingleContinuous
217 '
218 Me.MenuSingleContinuous.Index = 1
219 Me.MenuSingleContinuous.Text = "Single Continuous"
220 '
221 'MenuFacing
222 '
223 Me.MenuFacing.Index = 2
224 Me.MenuFacing.Text = "Facing"
225 '
226 'MenuFacingContinuous
227 '
228 Me.MenuFacingContinuous.Index = 3
229 Me.MenuFacingContinuous.Text = "Facing Continuous"
230 '
231 'MenuItem15
232 '
233 Me.MenuItem15.Index = 1
234 Me.MenuItem15.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuFitPage, Me.MenuFitWidth})
235 Me.MenuItem15.Text = "Page ViewMode"
236 '
237 'MenuFitPage
238 '
239 Me.MenuFitPage.Index = 0
240 Me.MenuFitPage.Text = "Fit Page"
241 '
242 'MenuFitWidth
243 '
244 Me.MenuFitWidth.Index = 1
245 Me.MenuFitWidth.Text = "Fit Width"
246 '
247 'MenuViewZoomIn
248 '
249 Me.MenuViewZoomIn.Index = 2
250 Me.MenuViewZoomIn.Text = "Zoom In"
251 '
252 'MenuViewZoomOut
253 '
254 Me.MenuViewZoomOut.Index = 3
255 Me.MenuViewZoomOut.Text = "Zoom Out"
256 '
257 'MenuItem4
258 '
259 Me.MenuItem4.Index = 3
260 Me.MenuItem4.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuToolPan, Me.MenuToolStructSelect, Me.MenuToolRectSelect, Me.MenuToolRectZoomIn, Me.MenuToolRectZoomOut, Me.MenuToolAnnotEdit, Me.MenuToolLineCreate, Me.MenuToolRectCreate, Me.MenuToolOvalCreate, Me.MenuToolArrayCreate, Me.MenuToolFreeHand})
261 Me.MenuItem4.Text = "Tool"
262 '
263 'MenuToolPan
264 '
265 Me.MenuToolPan.Index = 0
266 Me.MenuToolPan.Text = "Pan"
267 '
268 'MenuToolStructSelect
269 '
270 Me.MenuToolStructSelect.Index = 1
271 Me.MenuToolStructSelect.Text = "Structural Selection"
272 '
273 'MenuToolRectSelect
274 '
275 Me.MenuToolRectSelect.Index = 2
276 Me.MenuToolRectSelect.Text = "Rectangle Selection"
277 '
278 'MenuToolRectZoomIn
279 '
280 Me.MenuToolRectZoomIn.Index = 3
281 Me.MenuToolRectZoomIn.Text = "Rectangle Zoom In"
282 '
283 'MenuToolRectZoomOut
284 '
285 Me.MenuToolRectZoomOut.Index = 4
286 Me.MenuToolRectZoomOut.Text = "Rectangle Zoom Out"
287 '
288 'MenuToolAnnotEdit
289 '
290 Me.MenuToolAnnotEdit.Index = 5
291 Me.MenuToolAnnotEdit.Text = "Annotation Editing"
292 '
293 'MenuToolLineCreate
294 '
295 Me.MenuToolLineCreate.Index = 6
296 Me.MenuToolLineCreate.Text = "Line Creation"
297 '
298 'MenuToolRectCreate
299 '
300 Me.MenuToolRectCreate.Index = 7
301 Me.MenuToolRectCreate.Text = "Rectangle Creation"
302 '
303 'MenuToolOvalCreate
304 '
305 Me.MenuToolOvalCreate.Index = 8
306 Me.MenuToolOvalCreate.Text = "Oval Creation"
307 '
308 'MenuToolArrayCreate
309 '
310 Me.MenuToolArrayCreate.Index = 9
311 Me.MenuToolArrayCreate.Text = "Arrow Creation"
312 '
313 'MenuToolFreeHand
314 '
315 Me.MenuToolFreeHand.Index = 10
316 Me.MenuToolFreeHand.Text = "FreeHand Tool"
317 '
318 'MenuItem6
319 '
320 Me.MenuItem6.Index = 4
321 Me.MenuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuGotoNext, Me.MenuGotoPrev, Me.MenuGotoLast, Me.MenuGotoFirst})
322 Me.MenuItem6.Text = "Page Navigation"
323 '
324 'MenuGotoNext
325 '
326 Me.MenuGotoNext.Index = 0
327 Me.MenuGotoNext.Text = "Go to Next Page"
328 '
329 'MenuGotoPrev
330 '
331 Me.MenuGotoPrev.Index = 1
332 Me.MenuGotoPrev.Text = "Go to Previous Page"
333 '
334 'MenuGotoLast
335 '
336 Me.MenuGotoLast.Index = 2
337 Me.MenuGotoLast.Text = "Go to Last Page"
338 '
339 'MenuGotoFirst
340 '
341 Me.MenuGotoFirst.Index = 3
342 Me.MenuGotoFirst.Text = "Go to First Page"
343 '
344 'MenuItem7
345 '
346 Me.MenuItem7.Index = 5
347 Me.MenuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuHelpAbout})
348 Me.MenuItem7.Text = "Help"
349 '
350 'MenuHelpAbout
351 '
352 Me.MenuHelpAbout.Index = 0
353 Me.MenuHelpAbout.Text = "About..."
354 '
355 'PDFViewSimple
356 '
357 Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
358 Me.ClientSize = New System.Drawing.Size(744, 512)
359 Me.Menu = Me.mainMenu1
360 Me.Name = "PDFViewSimple"
361 Me.Text = "PDFViewSimple"
362 Me.ResumeLayout(False)
363
364 End Sub
365
366 Private Sub menuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileOpen.Click
367 Dim dlg As OpenFileDialog = New OpenFileDialog
368 dlg.CheckFileExists = True
369 dlg.CheckPathExists = True
370 dlg.Filter = "PDF (*.pdf)|*.pdf|All files (*.*)|*.*"
371 dlg.DefaultExt = ".pdf"
372 If dlg.ShowDialog = DialogResult.OK Then
373 OpenPDF(dlg.FileName)
374 End If
375 End Sub
376
377 Public Function OpenPDF(ByVal filename As String) As Boolean
378 Try
379 'close old document if opening new file was successful
380 Dim olddoc As PDFDoc = _pdfview.GetDoc()
381 _pdfdoc = New PDFDoc(filename)
382 _pdfview.SetDoc(_pdfdoc)
383
384 ' Use built-in navigation (thumbnails, bookmarks, layers, etc)?
385 ' _pdfview.ShowNavToolbar(true)
386 ' _pdfview.ShowNavPanel(true)
387
388 If Not (olddoc Is Nothing) Then
389 olddoc.Dispose()
390 End If
391
392 Catch ex As PDFNetException
393 MessageBox.Show(ex.Message)
394 Return False
395 Catch ex As Exception
396 MessageBox.Show(ex.ToString)
397 Return False
398 End Try
399 Me.Text = filename
400 Return True
401 End Function
402
403 Private Sub MenuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileSave.Click
404 If Not (_pdfdoc Is Nothing) Then
405 Me.Save(Me.Text)
406 End If
407 End Sub
408
409 Private Sub MenuFileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileSaveAs.Click
410 If Not (_pdfdoc Is Nothing) AndAlso Not (_pdfview Is Nothing) Then
411 'opens a save dialog
412 Dim dlg As SaveFileDialog = New SaveFileDialog
413 dlg.Filter = "PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*"
414 dlg.DefaultExt = ".pdf"
415 dlg.FileName = Text
416 Dim res As DialogResult = dlg.ShowDialog
417 If res = DialogResult.OK Then
418 'saves the file
419 Me.Save(dlg.FileName)
420 End If
421 End If
422 End Sub
423
424 Public Sub Save(ByVal fileName As String)
425 _pdfdoc.Lock()
426 Try
427 _pdfdoc.Save(fileName, SDFDoc.SaveOptions.e_remove_unused)
428 Catch ex As Exception
429 MessageBox.Show(ex.ToString(), "Error during the Save")
430 End Try
431 _pdfdoc.Unlock()
432 End Sub
433
434 Private Sub MenuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFilePrint.Click
435 If Not (_pdfview.GetDoc() Is Nothing) Then
436 _pdfview.Print()
437 End If
438 End Sub
439
440 Private Sub MenuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileExit.Click
441 PDFNet.Terminate()
442 Application.Exit()
443 End Sub
444
445
446 Private Sub MenuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditCopy.Click
447 If Not (_pdfview.GetDoc() Is Nothing) Then
448 _pdfview.Copy()
449 End If
450 End Sub
451
452 Private Sub MenuEditFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditFind.Click
453 If Not (_pdfview.GetDoc() Is Nothing) Then
454 _pdfview.Find()
455 End If
456 End Sub
457
458 Private Sub MenuEditSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditSelectAll.Click
459 If Not (_pdfview.GetDoc() Is Nothing) Then
460 _pdfview.SelectAll()
461 End If
462 End Sub
463
464 Private Sub MenuViewZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuViewZoomIn.Click
465 If Not (_pdfview.GetDoc() Is Nothing) Then
466 _pdfview.SetZoom(_pdfview.GetZoom() * 2)
467 End If
468 End Sub
469
470
471 Private Sub MenuViewZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuViewZoomOut.Click
472 If Not (_pdfview.GetDoc() Is Nothing) Then
473 _pdfview.SetZoom(_pdfview.GetZoom() / 2)
474 End If
475 End Sub
476
477 Private Sub MenuNextPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoNext.Click
478 If Not (_pdfview.GetDoc() Is Nothing) Then
479 _pdfview.GotoNextPage()
480 End If
481 End Sub
482
483 Private Sub MenuPreviousPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoPrev.Click
484 If Not (_pdfview.GetDoc() Is Nothing) Then
485 _pdfview.GotoPreviousPage()
486 End If
487 End Sub
488
489 Private Sub MenuLastPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoLast.Click
490 If Not (_pdfview.GetDoc() Is Nothing) Then
491 _pdfview.GotoLastPage()
492 End If
493 End Sub
494
495 Private Sub MenuFirstPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoFirst.Click
496 If Not (_pdfview.GetDoc() Is Nothing) Then
497 _pdfview.GotoFirstPage()
498 End If
499 End Sub
500
501 Private Sub MenuPageLayoutSinglePage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSinglePage.Click
502 If Not (_pdfview.GetDoc() Is Nothing) Then
503 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_page)
504 End If
505 End Sub
506
507 Private Sub MenuPageLayoutSingleContinous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSingleContinuous.Click
508 If Not (_pdfview.GetDoc() Is Nothing) Then
509 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_continuous)
510 End If
511 End Sub
512
513 Private Sub MenuPageLayoutFacing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFacing.Click
514 If Not (_pdfview.GetDoc() Is Nothing) Then
515 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing)
516 End If
517 End Sub
518
519 Private Sub MenuPageLayoutFacingContinuous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFacingContinuous.Click
520 If Not (_pdfview.GetDoc() Is Nothing) Then
521 _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing_continuous)
522 End If
523 End Sub
524
525 Private Sub MenuPageViewModeFitPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFitPage.Click
526 If Not (_pdfview.GetDoc() Is Nothing) Then
527 _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_page)
528 End If
529 End Sub
530
531 Private Sub MenuPageViewModeFitWidth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFitWidth.Click
532 If Not (_pdfview.GetDoc() Is Nothing) Then
533 _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_width)
534 End If
535 End Sub
536
537 Private Sub MenuToolPan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolPan.Click
538 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_pan)
539 End Sub
540
541 Private Sub MenuToolStructuralSelection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolStructSelect.Click
542 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_struct_select)
543 End Sub
544
545 Private Sub MenuToolRectangleSelection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectSelect.Click
546 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_rect_select)
547 End Sub
548
549 Private Sub MenuToolRectangleZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectZoomIn.Click
550 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_in)
551 End Sub
552
553 Private Sub MenuToolRectangleZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectZoomOut.Click
554 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_out)
555 End Sub
556
557 Private Sub MenuToolAnnotationEditing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolAnnotEdit.Click
558 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_annot_edit)
559 End Sub
560
561 Private Sub MenuToolLineCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolLineCreate.Click
562 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_line_create)
563 End Sub
564
565 Private Sub MenuToolRectangleCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectCreate.Click
566 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_rect_create)
567 End Sub
568
569 Private Sub MenuToolOvalCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolOvalCreate.Click
570 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_oval_create)
571 End Sub
572
573 Private Sub MenuToolArrowCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolArrayCreate.Click
574 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_arrow_create)
575 End Sub
576
577 Private Sub MenuToolFreeHandToolCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolFreeHand.Click
578 _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_ink_create)
579 End Sub
580
581 Private Sub MenuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuHelpAbout.Click
582 MessageBox.Show("PDFView Sample Application, Version 1.0", "About PDFViewSimple")
583 End Sub
584
585End Class
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales