Bloom.Publish.PdfViewer.ShowPdf C# (CSharp) Method

ShowPdf() public method

public ShowPdf ( string pdfFile ) : bool
pdfFile string
return bool
		public bool ShowPdf(string pdfFile)
		{
			_pdfPath = pdfFile;
#if !__MonoCS__
			var arc = _pdfViewerControl as AdobeReaderControl;
			if (arc != null) // We haven't yet had a problem displaying with Acrobat...
			{
				if (arc.ShowPdf(pdfFile))
					return true; // success using acrobat
				// Acrobat not working (probably not installed). Switch to using Gecko to display PDF.
				UpdatePdfViewer(new GeckoWebBrowser());
				// and continue to show it using that.
			}
#endif
			// Escaping the filename twice for characters like # is needed in order to get the
			// pdf filename through Geckofx/xulrunner to our local server on Linux.  This is to
			// prevent the filename from being cut short at the # character.  As far as I can
			// tell, Linux xulrunner strips one level of escaping on input, then before passing
			// the query on to the localhost server it truncates the query portion at the first
			// # it sees.  The localhost processor expects one level of encoding, and we deal
			// with having a # in the query (file path) there without any problem.  You may
			// regard this double escaping as a hack to get around the Linux xulrunner which
			// behaves differently than the Windows xulrunner.  It is an exception to the rule
			// of matching EscapeCharsForHttp() with UnescapeCharsForHttp().  See a comment in
			// https://jira.sil.org/browse/BL-951 for a description of the buggy program
			// behavior without this hack.
			var file = pdfFile;
			if (SIL.PlatformUtilities.Platform.IsUnix)
				file = file.EscapeCharsForHttp().EscapeCharsForHttp();
			var url = string.Format("{0}{1}?file=/bloom/{2}",
				Bloom.Api.ServerBase.ServerUrlWithBloomPrefixEndingInSlash,
				FileLocator.GetFileDistributedWithApplication("pdf/web/viewer.html"),
				file);

			var browser = ((GeckoWebBrowser)_pdfViewerControl);
			browser.Navigate(url);
			browser.DocumentCompleted += (sender, args) =>
			{
				// We want to suppress several of the buttons that the control normally shows.
				// It's nice if we don't have to modify the html and related files, because they are unzipped from a package we install
				// from a source I'm not sure we control, and installed into a directory we can't modify at runtime.
				// A workaround is to tweak the stylesheet to hide them. The actual buttons (and two menu items) are easily
				// hidden by ID.
				// Unfortunately we're getting rid of a complete group in the pull-down menu, which leaves an ugly pair of
				// adjacent separators. And the separators don't have IDs so we can't easily select just one to hide.
				// Fortunately there are no other divs in the parent (besides the separator) so we just hide the second one.
				// This is unfortunately rather fragile and may not do exactly what we want if the viewer.html file
				// defining the pdfjs viewer changes.
				GeckoStyleSheet stylesheet = browser.Document.StyleSheets.First();
				stylesheet.CssRules.Add("#toolbarViewerRight, #viewOutline, #viewAttachments, #viewThumbnail, #viewFind {display: none}");
				stylesheet.CssRules.Add("#previous, #next, #pageNumberLabel, #pageNumber, #numPages {display: none}");
				stylesheet.CssRules.Add("#toolbarViewerLeft .splitToolbarButtonSeparator {display: none}");

#if !__MonoCS__
				if (!_haveShownAdobeReaderRecommendation)
				{
					_haveShownAdobeReaderRecommendation = true;
					var message = LocalizationManager.GetString("PublishTab.Notifications.AdobeReaderRecommendation",
						"This PDF viewer can be improved by installing the free Adobe Reader on this computer.");
					RunJavaScript("toastr.remove();" +
								  "toastr.options = { 'positionClass': 'toast-bottom-right','timeOut': '15000'};" +
								  "toastr['info']('" + message + "')");
				}
#endif
			};
			return true;
		}