PDFViewSimple

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}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales