Ejemplo n.º 1
0
        public static void CreatePdf(string htmlPath,
                                     IEnumerable <string> styleSheetPaths,
                                     string pdfPath)
        {
            string princePath = GetPrincePath();
            Prince p;

            if (File.Exists(princePath))
            {
                p = new Prince(princePath);
            }
            else
            {
                p = new Prince();                 //maybe it would look in %path%?
            }
            // no: this makes princexml think we're putting out ascii:  p.SetHTML(true);
            using (var log = new TempFile())
            {
                p.SetLog(log.Path);
                foreach (string styleSheetPath in styleSheetPaths)
                {
                    p.AddStyleSheet(styleSheetPath);
                }
                if (!p.Convert(htmlPath, pdfPath))
                {
                    throw new ApplicationException(File.ReadAllText(log.Path));
                }
            }
        }
Ejemplo n.º 2
0
        protected SingleConvertToPDF()
        {
            try {
                string sPathExe = "C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe";
                if (File.Exists(sPathExe))
                {
                    // instantiate Prince by specifying the full path to the engine executable
                    prn = new Prince("C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe");
                    // specify the log file for error and warning messages
                    // make sure that you have write permissions for this file
                    sPathDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
                    prn.SetLog(sPathDirectory + "\\HtmlToPdf\\logPrinceHtmlToPdf.txt");
                    // apply a CSS style sheet (optional)

                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.min.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap.min.css");
                    prn.AddStyleSheet(sPathDirectory + "\\css\\UserPourPdf.css");

                    // apply an external JavaScript file (optional)
                    //prn.AddScript("C:\\docs\\js\\test.js");
                }
                else
                {
                    sInitLog = "Fichier exe Prince n'esiste pas en : " + sPathExe;
                    SingleLogFileAsXml.Instance().AjouteLog("Init", sInitLog);
                }
            }
            catch (Exception ex) {
                sInitLog = ex.Message;
                SingleLogFileAsXml.Instance().AjouteLog("Init", "SingleConvertToPDF : Exception : " + ex.Message);
            }
        }
Ejemplo n.º 3
0
		public static bool CreatePdf(string htmlPath,
									 IEnumerable<string> styleSheetPaths,
									 string pdfPath)
		{
			if (Environment.OSVersion.Platform == PlatformID.Unix)
			{
				return false;
			}
			string princePath = GetPrincePath();
			Prince p;
			if (File.Exists(princePath))
			{
				p = new Prince(princePath);
			}
			else
			{
				p = new Prince(); //maybe it would look in %path%?
			}
			p.SetHTML(true);
			foreach (string styleSheetPath in styleSheetPaths)
			{
				p.AddStyleSheet(styleSheetPath);
			}
			return p.Convert(htmlPath, pdfPath);
		}
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     isDancing    = false;
     pressedE     = false;
     bear         = GameObject.Find("Bear");
     prince       = GameObject.Find("Prince");
     bearScript   = bear.GetComponent <Bear>();
     princeScript = prince.GetComponent <Prince>();
 }
Ejemplo n.º 5
0
        public Chessboard()
        {
            #region Black pieces initialisation

            StartBoard[0, 0] = new Rook(PlayerColor.Black, new Cell(0, 0), this);
            StartBoard[0, 1] = new Knight(PlayerColor.Black, new Cell(0, 1), this);
            StartBoard[0, 2] = new Bishop(PlayerColor.Black, new Cell(0, 2), this);
            StartBoard[0, 3] = new Queen(PlayerColor.Black, new Cell(0, 3), this);
            StartBoard[0, 4] = new King(PlayerColor.Black, new Cell(0, 4), this);
            StartBoard[0, 5] = new Prince(PlayerColor.Black, new Cell(0, 5), this);
            StartBoard[0, 6] = new Knight(PlayerColor.Black, new Cell(0, 6), this);
            StartBoard[0, 7] = new Bishop(PlayerColor.Black, new Cell(0, 7), this);
            StartBoard[0, 8] = new Rook(PlayerColor.Black, new Cell(0, 8), this);

            StartBoard[1, 0] = new Pawn(PlayerColor.Black, new Cell(1, 0), this);
            StartBoard[1, 1] = new Pawn(PlayerColor.Black, new Cell(1, 1), this);
            StartBoard[1, 2] = new Pawn(PlayerColor.Black, new Cell(1, 2), this);
            StartBoard[1, 3] = new Pawn(PlayerColor.Black, new Cell(1, 3), this);
            StartBoard[1, 4] = new Pawn(PlayerColor.Black, new Cell(1, 4), this);
            StartBoard[1, 5] = new Pawn(PlayerColor.Black, new Cell(1, 5), this);
            StartBoard[1, 6] = new Pawn(PlayerColor.Black, new Cell(1, 6), this);
            StartBoard[1, 7] = new Pawn(PlayerColor.Black, new Cell(1, 7), this);
            StartBoard[1, 8] = new Pawn(PlayerColor.Black, new Cell(1, 8), this);

            #endregion

            #region White pieces initialisation

            StartBoard[7, 0] = new Pawn(PlayerColor.White, new Cell(7, 0), this);
            StartBoard[7, 1] = new Pawn(PlayerColor.White, new Cell(7, 1), this);
            StartBoard[7, 2] = new Pawn(PlayerColor.White, new Cell(7, 2), this);
            StartBoard[7, 3] = new Pawn(PlayerColor.White, new Cell(7, 3), this);
            StartBoard[7, 4] = new Pawn(PlayerColor.White, new Cell(7, 4), this);
            StartBoard[7, 5] = new Pawn(PlayerColor.White, new Cell(7, 5), this);
            StartBoard[7, 6] = new Pawn(PlayerColor.White, new Cell(7, 6), this);
            StartBoard[7, 7] = new Pawn(PlayerColor.White, new Cell(7, 7), this);
            StartBoard[7, 8] = new Pawn(PlayerColor.White, new Cell(7, 8), this);

            StartBoard[8, 0] = new Rook(PlayerColor.White, new Cell(8, 0), this);
            StartBoard[8, 1] = new Bishop(PlayerColor.White, new Cell(8, 1), this);
            StartBoard[8, 2] = new Knight(PlayerColor.White, new Cell(8, 2), this);
            StartBoard[8, 3] = new Prince(PlayerColor.White, new Cell(8, 3), this);
            StartBoard[8, 4] = new King(PlayerColor.White, new Cell(8, 4), this);
            StartBoard[8, 5] = new Queen(PlayerColor.White, new Cell(8, 5), this);
            StartBoard[8, 6] = new Bishop(PlayerColor.White, new Cell(8, 6), this);
            StartBoard[8, 7] = new Knight(PlayerColor.White, new Cell(8, 7), this);
            StartBoard[8, 8] = new Rook(PlayerColor.White, new Cell(8, 8), this);

            #endregion

            _whiteKing   = StartBoard[8, 4];
            _blackKing   = StartBoard[0, 4];
            _whitePrince = StartBoard[8, 3];
            _blackPrince = StartBoard[0, 5];

            Reset();
        }
Ejemplo n.º 6
0
        private static void AttachPrinceFilter(HttpApplication httpApplication)
        {
            var path = GetPrincePath(httpApplication);
            var prince = new Prince(path);
            prince.SetBaseURL(httpApplication.Request.Url.AbsoluteUri);
            prince.SetLog("prince.log");
            prince.SetInsecure(true);

            httpApplication.Response.Filter = new PrinceFilter(prince, httpApplication.Response.Filter);
        }
Ejemplo n.º 7
0
        private static void AttachPrinceFilter(HttpApplication httpApplication)
        {
            var path   = GetPrincePath(httpApplication);
            var prince = new Prince(path);

            prince.SetBaseURL(httpApplication.Request.Url.AbsoluteUri);
            prince.SetLog("prince.log");
            prince.SetInsecure(true);

            httpApplication.Response.Filter = new PrinceFilter(prince, httpApplication.Response.Filter);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Write the Pdf file
        /// </summary>
        /// <param name="outName">Name to use for Pdf file</param>
        public void Create(string outName)
        {
            Debug.Assert(!string.IsNullOrEmpty(Xhtml), "xhtml not set");

            if (Common.UnixVersionCheck())
            {
                if (!File.Exists("/usr/bin/Prince"))
                {
                    throw new MISSINGPRINCE();
                }
                Common.RunCommand("Prince ", Xhtml + " " + Css + " -o " + outName, 1);
                return;
            }
            RegistryKey regPrinceKey;

            try
            {
                regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                }
                if (regPrinceKey == null)
                {
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                }
            }
            catch (Exception)
            {
                regPrinceKey = null;
            }
            if (regPrinceKey != null)
            {
                object princePath     = regPrinceKey.GetValue("InstallLocation");
                string princeFullName = Common.PathCombine(princePath as string, "Engine/Bin/Prince.exe");
                var    myPrince       = new Prince(princeFullName);
                var    mc             = new MergeCss();
                if (File.Exists(Css))
                {
                    myPrince.AddStyleSheet(mc.Make(Css, "Temp1.css"));
                }
                myPrince.Convert(Xhtml, outName);
            }
            else
            {
                throw new MISSINGPRINCE();
            }
        }
Ejemplo n.º 9
0
        public FileStreamResult Get()
        {
            string princePath   = Path.Combine(_env.ContentRootPath, @"prince\bin\prince.exe");
            string fontsCssPath = Path.Combine(_env.ContentRootPath, @"fonts\inter.css");
            Prince prn          = new Prince(princePath, _princeLogger);

            prn.StyleSheets.Add(fontsCssPath);
            Stream pdfOutput = new MemoryStream(10000);

            prn.ConvertString(ExampleHtml, pdfOutput);

            pdfOutput.Flush();
            pdfOutput.Position = 0;
            return(File(pdfOutput, "application/pdf", "prince-demo.pdf"));
        }
    void Update()
    {
        Guard guard = null;

        if (currentEnemy)
        {
            guard = currentEnemy.GetComponent <Guard>();
        }
        if (targetPlayer)
        {
            if (!prince)
            {
                prince = targetPlayer.GetComponent <Prince>();
            }
            else
            {
                GameCore.uIHandler.UpdateUIPrince(prince);
            }
        }
        if (guard)
        {
            GameCore.uIHandler.UpdateUIEnemy(guard);
            if (targetPlayer && guard.canCombat)
            {
                canCombat = true;
            }
        }
        else
        {
            canCombat = false;
        }

        if (targetPlayer && currentEnemy)
        {
            if ((isEnemyAttacking && isPlayerParring) && !parringTrigger)
            {
                guard.OnTakeParry();
                parringTrigger = true;
                Invoke("ResetParry", 0.5f);
            }
            else if ((isEnemyParrying && isPlayerAttacking) && !parringTrigger)
            {
                prince.OnTakeParry();
                parringTrigger = true;
                Invoke("ResetParry", 0.5f);
            }
        }
    }
Ejemplo n.º 11
0
        protected void SetPDFOutput(string baseUrl)
        {
            string princePath = ConfigurationManager.AppSettings["PrincePath"];

            if (string.IsNullOrEmpty(princePath))
            {
                this.HttpContext.Response.Write("<div style=\"color:red\">PrincePath not set in web.config</div>");
                return;
            }

            Prince prince = new Prince(princePath);

            prince.SetBaseURL("file:///" + baseUrl);

            this.HttpContext.Response.Filter      = new PrinceFilter(prince, this.HttpContext.Response.Filter);
            this.HttpContext.Response.ContentType = "application/pdf";
            this.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=sar-cards.pdf");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initialize document.
        /// </summary>
        /// <param name="conf">Config object that defines which pages and images to use.</param>
        /// <param name="princePath">Path to the PrinceXML binary.</param>
        public PrinceDocument(PDF.Config conf, string princePath)
        {
            prince = new Prince(princePath);

            // We are dealing with Html
            prince.SetHTML(true);

            // Add default stylesheets
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\mediawiki.css");
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\book.css");
            prince.AddStyleSheet(AppDomain.CurrentDomain.BaseDirectory + "\\assets\\ruby.css");

            // Add additional stylesheets
            foreach (Uri path in conf.StyleSheets)
            {
                prince.AddStyleSheet(path.AbsolutePath);
            }

            this.conf = conf;
        }
Ejemplo n.º 13
0
        public static bool CreatePdf(string htmlPath,
                                     IEnumerable <string> styleSheetPaths,
                                     string pdfPath)
        {
            bool   retval     = true;
            string princePath = GetPrincePath();
            Prince p;

            if (File.Exists(princePath))
            {
                p = new Prince(princePath);
            }
            else
            {
                p = new Prince();                 //maybe it would look in %path%?
            }
            // no: this makes princexml think we're putting out ascii:  p.SetHTML(true);
            using (var log = new TempFile())
            {
                p.SetLog(log.Path);
                foreach (string styleSheetPath in styleSheetPaths)
                {
                    p.AddStyleSheet(styleSheetPath);
                }
                if (!p.Convert(htmlPath, pdfPath))
                {
                    string errorString = File.ReadAllText(log.Path);
                    if (errorString.Contains("error: can't open output file: Permission denied"))
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem("Sorry! We couldn't generate the PDF file, probably because the old one is still open in your PDF viewer. Close the PDF and then try again. (Permission denied writing to PDF file)");
                        retval = false;
                    }
                    else
                    {
                        throw new ApplicationException(errorString);
                    }
                }
            }
            return(retval);
        }
Ejemplo n.º 14
0
    public void UpdateUIPrince(Prince princeScript)
    {
        for (int i = 0; i < prince.Length; i++)
        {
            prince[i].enabled = false;
        }
        var maxHealth = princeScript.MaxHealth;

        for (int i = 0; i < maxHealth; i++)
        {
            prince[i].enabled = true;
        }
        for (int i = 0; i < prince.Length; i++)
        {
            prince[i].sprite = princeUIHealthSprite[0];
        }
        var currentHealth = princeScript.health;

        for (int i = 0; i < currentHealth; i++)
        {
            prince[i].sprite = princeUIHealthSprite[1];
        }
    }
Ejemplo n.º 15
0
 private byte[] MakePdf(string html)
 {
     try {
         var prince = new Prince(HttpContext.Current.Server.MapPath("~/CommandLine/PrinceEngine/bin/prince.exe"));
         prince.SetLicenseFile(HttpContext.Current.Server.MapPath("~/CommandLine/PrinceEngine/license/license.dat").Replace("\\", "/"));
         //prince.SetLicenseFile("../license/license.dat");
         prince.SetHtml(true);
         //prince.SetFileRoot(tempPath.EndsWith("\\") ? tempPath.Substring(0, tempPath.Length - 1) : tempPath);
         prince.SetLog(HttpContext.Current.Server.MapPath("~/App_Data/Blobs/prince.log"));
         using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(html))
         {
             Position = 0
         }) {
             using (var pdf = new MemoryStream()) {
                 prince.ConvertMemoryStream(ms, pdf);
                 return(pdf.ToArray());
             }
         }
     } catch (Exception ex) {
         Debug.WriteLine(ex.Message);
         return(null);
     } finally {
     }
 }
Ejemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     prince       = GameObject.Find("Prince");
     eKey         = GameObject.Find("e key");
     princeScript = prince.GetComponent <Prince>();
 }
Ejemplo n.º 17
0
        private static bool ExportPrince(PublicationInformation projInfo, string xhtmlFileName, bool isUnixOS,
                                         RegistryKey regPrinceKey, string defaultCSS)
        {
            if (!isUnixOS)
            {
                Object princePath = regPrinceKey.GetValue("InstallLocation");
                _fullPrincePath = Common.PathCombine((string)princePath, "Engine/bin/prince.exe");
                var myPrince = new Prince(_fullPrincePath);
                if (projInfo.IsReversalExist && projInfo.IsLexiconSectionExist)
                {
                    string[] xhtmlFiles   = new string[2];
                    var      reversalFile = Path.GetDirectoryName(_processedXhtml);
                    xhtmlFiles[0] = _processedXhtml;
                    xhtmlFiles[1] = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    myPrince.AddStyleSheet(defaultCSS);
                    myPrince.ConvertMultiple(xhtmlFiles, xhtmlFileName + ".pdf");
                }
                else
                {
                    if (File.Exists(_fullPrincePath))
                    {
                        myPrince.AddStyleSheet(defaultCSS);
                        myPrince.Convert(_processedXhtml, xhtmlFileName + ".pdf");
                    }
                }
            }
            else
            {
                if (isUnixOS)
                {
                    if (!Directory.Exists("/usr/lib/prince/bin"))
                    {
                        return(false);
                    }
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath));

                string inputArguments;
                if (projInfo.IsReversalExist)
                {
                    var reversalFile     = Path.GetDirectoryName(_processedXhtml);
                    var reversalFilename = Common.PathCombine(reversalFile, "FlexRev.xhtml");
                    inputArguments = "-s " + defaultCSS + " " + _processedXhtml + " " + reversalFilename + " " + " -o " + xhtmlFileName + ".pdf";
                }
                else
                {
                    inputArguments = "-s " + defaultCSS + " " + _processedXhtml + " -o " + xhtmlFileName + ".pdf";
                }

                using (Process p1 = new Process())
                {
                    p1.StartInfo.FileName = "prince";
                    if (File.Exists(_processedXhtml))
                    {
                        p1.StartInfo.Arguments = inputArguments;
                    }
                    p1.StartInfo.RedirectStandardOutput = true;
                    p1.StartInfo.RedirectStandardError  = p1.StartInfo.RedirectStandardOutput;
                    p1.StartInfo.UseShellExecute        = !p1.StartInfo.RedirectStandardOutput;
                    p1.Start();
                    p1.WaitForExit();
                }
            }
            return(true);
        }
 private void Awake()
 {
     objectParent = transform.parent.gameObject;
     prince       = GetComponentInParent <Prince>();
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Write the Pdf file
        /// </summary>
        /// <param name="outName">Name to use for Pdf file</param>
        public void Create(string outName)
        {
            Debug.Assert(!string.IsNullOrEmpty(Xhtml), "xhtml not set");

            if (Common.UnixVersionCheck())
            {
                if (!File.Exists("/usr/bin/Prince"))
                    throw new MISSINGPRINCE();
                Common.RunCommand("Prince ", Xhtml + " " + Css + " -o " + outName, 1);
                return;
            }
            RegistryKey regPrinceKey;
            try
            {
                regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\Prince_is1");
                if (regPrinceKey == null)
                    regPrinceKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{3AC28E9C-8F06-4E2C-ADDA-726E2230A03A}");

            }
            catch (Exception)
            {
                regPrinceKey = null;
            }
            if (regPrinceKey != null)
            {
                object princePath = regPrinceKey.GetValue("InstallLocation");
                string princeFullName = Common.PathCombine(princePath as string, "Engine/Bin/Prince.exe");
                var myPrince = new Prince(princeFullName);
                var mc = new MergeCss();
                if (File.Exists(Css))
                    myPrince.AddStyleSheet(mc.Make(Css, "Temp1.css"));
                myPrince.Convert(Xhtml, outName);
            }
            else
            {
                throw new MISSINGPRINCE();
            }
        }
Ejemplo n.º 20
0
        private static bool ExportPrince(PublicationInformation projInfo, string xhtmlFileName, bool isUnixOS,
                                   RegistryKey regPrinceKey, string defaultCSS)
        {
            if (!isUnixOS)
            {
                Object princePath = regPrinceKey.GetValue("InstallLocation");
                _fullPrincePath = Common.PathCombine((string) princePath, "Engine/bin/prince.exe");

                if (File.Exists(_fullPrincePath))
                {
                    var myPrince = new Prince(_fullPrincePath);
                    myPrince.AddStyleSheet(defaultCSS);
                    myPrince.Convert(_processedXhtml, xhtmlFileName + ".pdf");
                }
            }
            else
            {
                if (isUnixOS)
                {
                    if (!Directory.Exists("/usr/lib/prince/bin"))
                    {
                        return false;
                    }
                }
                Environment.CurrentDirectory = Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath);
                Directory.SetCurrentDirectory(Path.GetDirectoryName(projInfo.DefaultXhtmlFileWithPath));
                string p1Error = string.Empty;
                string inputArguments = "";
                inputArguments = _processedXhtml + " -o " + xhtmlFileName + ".pdf";
                using (Process p1 = new Process())
                {
                    p1.StartInfo.FileName = "prince";
                    if (File.Exists(_processedXhtml))
                    {
                        p1.StartInfo.Arguments = inputArguments;
                    }
                    p1.StartInfo.RedirectStandardOutput = true;
                    p1.StartInfo.RedirectStandardError = p1.StartInfo.RedirectStandardOutput;
                    p1.StartInfo.UseShellExecute = !p1.StartInfo.RedirectStandardOutput;
                    p1.Start();
                    p1.WaitForExit();
                    p1Error = p1.StandardError.ReadToEnd();
                }
            }
            return true;
        }