public IEnumerable <string> Get()
        {
            Properties.Settings S = new Properties.Settings();
            string DocName        = "doc";
            string HTML           = "https://google.com";

            using (connection = new SqlConnection(S.Database2ConnectionString))
            {
                connection.Open();

                SqlCommand HTMLCommand = new SqlCommand("SELECT HTML FROM Settings WHERE Id = 1", connection);

                SqlDataReader reader = HTMLCommand.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine("\nDatabase value for HTML is: " + reader[0].ToString());
                    HTML = reader[0].ToString();
                }
                connection.Close();

                connection.Open();

                SqlCommand DocNameCommand = new SqlCommand("SELECT NewDocName FROM Settings WHERE Id = 1", connection);

                reader = DocNameCommand.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine("Database value for the new Document Name is: " + reader[0].ToString());

                    DocName = reader[0].ToString();
                }
                Console.WriteLine(HTML + DocName);

                connection.Close();
            };

            Console.WriteLine("\nPreparing to Convert Website: " + HTML);
            Console.WriteLine("New Document Name will be named: " + DocName);

            APWebGrabber wg = new APWebGrabber();

            wg.OutputDirectory = @"C:/Users/Administrator/Desktop";
            wg.NewDocumentName = DocName;
            wg.URL             = HTML;
            wg.ConvertToPDF("127.0.0.1", 52525);
            Console.WriteLine("\nDone!");
            return(new string[] {});
        }
Exemple #2
0
        /// <summary>
        /// Method to perform tasks on captured HTML
        /// </summary>
        /// <param name="html">HTML to act on - returned from CaptureHtml</param>
        /// <param name="controllerContext">ControllerContext of the calling Controller - contains ViewData, etc.</param>
        /// <param name="view">Instantiated RazorView</param>
        protected override void ActOnHtml(string html, ControllerContext controllerContext, IView view)
        {
            // WebGrabber doesn't like this
            html = html.Replace("<!DOCTYPE html>", string.Empty);

            // create the activePDF WebGrabber object
            var grabber = new APWebGrabber()
            {
                CreateFromHTMLText = html,              // the HTML to convert
                OutputDirectory    = Directory,         // the directory the file will be written to
                NewDocumentName    = DocId,             // the name of the PDF document
                UserStyleSheetUrl  = Css(),             // style the HTML - CSS must be Base64-encoded for some reason and is NOT the URL
                Orientation        = 1                  // 0 = portrait, 1 = landscape
            };

            // generate the PDF
            var result = grabber.DoPrint(Host, Port);

            // clean up after ourselves
            grabber.CleanUp(Host, Port);
        }