Esempio n. 1
0
        private byte[] ExportLetterToPdf(string html)
        {
            //recomend to use Pechkin.Synhrozine for generating pdf from html
            //recomend to use Pechkin.Synhrozine for generating pdf from html
            // byte[] bytes = new SimplePechkin(new GlobalConfig()).Convert(html);
            //IPechkin pechkin = new SynchronizedPechkin(new GlobalConfig());
            //byte[] bytes = pechkin.Convert(html);

            byte[] bytes;
            using (MemoryStream ms = new MemoryStream())
            {
                var config = new PdfGenerateConfig();
                config.PageSize = PageSize.Letter;
                // config.PageSize = PageSize.A4;
                //todo: load margins from letter user settings for pdf
                config.MarginLeft   = 20;
                config.MarginRight  = 20;
                config.MarginTop    = 25;
                config.MarginBottom = 25;
                using (var pdf = PdfGenerator.GeneratePdf(html, config))
                {
                    if (pdf.PageCount == 0)
                    {
                        pdf.Close();
                        bytes = new byte[0];
                        return(bytes);
                    }
                    pdf.Save(ms, false);
                    bytes = ms.ToArray();
                }
            }
            return(bytes);
        }
Esempio n. 2
0
        public void GeneratePDF(HttpResponse Response, string StoredProcedure, string[] StoredProcedureParams = null, string FileName = "Report")
        {
            DataTable   dt       = dh.GetData(StoredProcedure, StoredProcedureParams);
            string      header   = "<h3 style='text-align:center'>Referee Performance Report</h3>";
            string      html     = header + ConvertDataTableToHTML(dt);
            PdfDocument document = PdfGenerator.GeneratePdf(html, PageSize.A4);            // Create new PDF document

            document.Info.Title   = FileName;
            document.Info.Author  = "Kishea Moses";
            document.Info.Subject = "Created On: " +
                                    DateTime.Now.ToString("F", CultureInfo.InvariantCulture);
            document.Options.NoCompression = true;
            document.Info.ModificationDate = DateTime.Now;
            // Send PDF to browser
            MemoryStream stream = new MemoryStream();

            document.Save(stream, false);
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", stream.Length.ToString());
            Response.BinaryWrite(stream.ToArray());
            Response.Flush();
            stream.Close();
            Response.End();
        }
 private void buttonExportPDF_Click(object sender, EventArgs e)
 {
     if (MessagesTreeView.Nodes.Count > 0)
     {
         saveFileDialogExport.FileName = "ExportedMessages" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm");
         if (saveFileDialogExport.ShowDialog() == DialogResult.OK)
         {
             var messages =
                 MessagesTreeView.Nodes
                 .OfType <TreeNode>()
                 .Select(
                     node => new EmailModel
             {
                 From       = node.Nodes["fromNode"] != null ? (node.Nodes["fromNode"].Tag.ToString()) : (string.Empty),
                 Subject    = node.Text,
                 Body       = node.Tag.ToString(),
                 ReceivedOn = node.Nodes["ReceivedOn"].Tag.ToString()
             })
                 .ToList();
             string errorMessage;
             if (!PdfGenerator.GeneratePdf(messages, saveFileDialogExport.FileName, out errorMessage))
             {
                 MessageBox.Show("Error in generating pdf:" + errorMessage);
             }
         }
     }
     else
     {
         MessageBox.Show("Please add some messages first");
     }
 }
Esempio n. 4
0
        public void GeneratePdfBase64_Success()
        {
            // Arrange
            var html = @"
                <html>
                    <body>
                        <p>Test document</p>
                    </body>
                </html>
            ";

            // Act
            var result = string.Empty;

            using (var stream = new MemoryStream())
            {
                var pdf = PdfGenerator.GeneratePdf(html, PdfSharpCore.PageSize.A4);

                pdf.Save(stream);

                result = Convert.ToBase64String(stream.ToArray());
            }

            // Assert
            result.Should().NotBeNullOrEmpty();
        }
Esempio n. 5
0
        public void WritePdf(string html, string path)
        {
            // generate a pdf and save
            var pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);

            pdf.Save(path);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var argsResult = new ApplicationArguments();

            argsResult.GetOptionSet().Parse(args);

            var builder = new ConfigurationBuilder()
                          .AddJsonFile($"appsettings.json", true, true)
                          .AddEnvironmentVariables();

            var config      = builder.Build();
            var pdfSettings = new PdfSettings();

            config.GetSection("PdfSettings").Bind(pdfSettings);
            try
            {
                using (var reader = File.OpenText(argsResult.InputFile))
                {
                    var html        = reader.ReadToEnd();
                    var pdfDocument = PdfGenerator.GeneratePdf(html, pdfSettings, null);
                    using (var writeStream = File.OpenWrite(argsResult.OutputFile))
                    {
                        using (var writer = new BinaryWriter(writeStream))
                        {
                            writer.Write(pdfDocument);
                        }
                    }
                }
                Console.WriteLine("Done!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            string currentDirectory    = Directory.GetCurrentDirectory();
            string phantomJsRootFolder = Path.Combine(currentDirectory, "PhantomJsRoot");

            // the pdf generator needs to know the path to the folder with .exe files.
            PdfGenerator generator = new PdfGenerator(phantomJsRootFolder);

            string htmlToConvert =
                @"
<!DOCTYPE html>
<html>
<head>

</head>
<body>
    <h1>Hello World!</h1>
    <p>This PDF has been generated by PhantomJs ;)</p>
</body>
</html>
";
            // Generate pdf from html and place in the current folder.
            string pathOftheGeneratedPdf = generator.GeneratePdf(htmlToConvert, currentDirectory);

            Console.WriteLine("Pdf generated at: " + pathOftheGeneratedPdf);
        }
        public static void stampajUgovor()
        {
            PdfDocument pdf = PdfGenerator.GeneratePdf(
                @"<html>
                            <body style=""text-align:center;background-color:red"">
                                <p>
                                    <a href=""www.google.rs"">Hello World</a>
                                    This is html rendered text
                                </p>
                            </body>
                      </html>", PageSize.A4);

            pdf.Save("document.pdf");
            PrintDialog pDialog = new PrintDialog();

            pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;

            // Display the dialog. This returns true if the user presses the Print button.
            bool?print = pDialog.ShowDialog();

            Aspose.Pdf.Document.Convert("document.pdf", null, "hello.xps", new XpsSaveOptions());
            if (print == true)
            {
                XpsDocument           xpsDocument = new XpsDocument("hello.xps", FileAccess.ReadWrite);
                FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
            }
        }
Esempio n. 9
0
        public string writeHTMLtoPDF(string html, string pfad)
        {
            PdfDocument pdf1 = PdfGenerator.GeneratePdf(html, config);

            pfad = checkSlash(pfad);
            string alternativerPfad = pfad.Remove(pfad.Length - 5, 1);

            try
            {
                pdf1.Save(pfad);
                return(checkSlash(pfad));
            }
            catch (Exception ef)
            {
            }
            try
            {
                pdf1.Save(alternativerPfad);
                return(checkSlash(alternativerPfad));
            }

            catch (Exception e) {
            }


            return(pfad);
        }
Esempio n. 10
0
        public HttpResponseMessage ExportAsPDF()
        {
            // https://www.nuget.org/packages/HtmlRenderer.PdfSharp/
            // Install-Package HtmlRenderer.PdfSharp -Version 1.5.0.6

            var sDocument = @"
                <h1>Header<h1>
                <p>Content</p>
            ";

            var pdfDoc = PdfGenerator.GeneratePdf(sDocument, PageSize.A4);
            var stream = new MemoryStream();

            pdfDoc.Save(stream);
            ///pdfDoc.Save("D:\\1.pdf");

            var response = new HttpResponseMessage();

            response.Content = new ByteArrayContent(stream.ToArray());
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = "export.pdf";
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return(response);
        }
Esempio n. 11
0
        public void CreatePdfReport(DateTime startDate, DateTime endDate, string pdfFullFileName, string cssFullFileName)
        {
            IList <SqlPdfFormat> data =
                SqlServerToPdf.GenerateSalesReport(sQLServerContext, startDate, endDate);

            PdfGenerator.GeneratePdf(data, pdfFullFileName, cssFullFileName);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void exportAsPDFMenuItem_Click(object sender, EventArgs e)
        {
            //Save!
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            //Default name of the file is the editor file name
            saveFileDialog.FileName = Path.GetFileNameWithoutExtension(this.FileInfo.FileName) + ".pdf";
            //The current path
            saveFileDialog.InitialDirectory = this.markdownViewer.Notepad.GetCurrentDirectory();
            //
            saveFileDialog.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*";
            //
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Build a config based on made settings
                PdfGenerateConfig pdfConfig = new PdfGenerateConfig();
                pdfConfig.PageOrientation = this.markdownViewer.Options.pdfOrientation;
                pdfConfig.PageSize        = this.markdownViewer.Options.pdfPageSize;
                //Set margins
                int[] margins = this.markdownViewer.Options.GetMargins();
                pdfConfig.MarginLeft   = MilimiterToPoint(margins[0]);
                pdfConfig.MarginTop    = MilimiterToPoint(margins[1]);
                pdfConfig.MarginRight  = MilimiterToPoint(margins[2]);
                pdfConfig.MarginBottom = MilimiterToPoint(margins[3]);
                //Generate PDF and save
                PdfDocument pdf = PdfGenerator.GeneratePdf(BuildHtml(ConvertedText, this.FileInfo.FileName), pdfConfig, PdfGenerator.ParseStyleSheet(this.getCSS()));
                pdf.Save(saveFileDialog.FileName);

                //Open if requested
                if (this.markdownViewer.Options.pdfOpenExport)
                {
                    Process.Start(saveFileDialog.FileName);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Create PDF using PdfSharp project, save to file and open that file.
        /// </summary>
        private void OnGeneratePdf_Click(object sender, EventArgs e)
        {
            string outPDFPath = @"C:\Users\tmi\Downloads\obnova_kulturnych_pamiatok.1.0 (2)TMI (2).pdf";
            string htmlstring = generateHtml();

            if (!string.IsNullOrEmpty(htmlstring))
            {
                PdfGenerateConfig x = new PdfGenerateConfig();
                x.EnablePageNumbering        = true;
                x.PageNumbersFont            = new XFont("Times New Roman", 11);
                x.PageNumbersPattern         = "{0}/{1}";
                x.PageNumberLocation         = PageNumberLocation.Middle;
                x.PageNumbersMarginBottom    = 20;
                x.PageNumbersLeftRightMargin = 10;
                x.PageSize = PageSize.A4;
                x.SetMargins(30);
                var pdf = PdfGenerator.GeneratePdf(htmlstring, x, null, null, null);

                using (FileStream fs = new FileStream(outPDFPath, FileMode.Create))
                {
                    pdf.Save(fs, true);
                }

                System.Diagnostics.Process.Start(outPDFPath);
            }
        }
Esempio n. 14
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            /*
             * PdfDocument document = new PdfDocument();
             *
             * PdfPage page = document.Pages.Add();
             *
             * PdfGraphics pdfGraphics = page.Graphics;
             *
             * PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14);
             *
             * pdfGraphics.DrawString("Testing!!", font, PdfBrushes.Black, new PointF(0,0));
             *
             * string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "./Pdf/DocTest.pdf");
             *
             * document.Save(filePath);
             */



            string      html = File.ReadAllText(path);
            PdfDocument pdf  = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);



            pdf.Save("document.pdf");

            string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "./document.pdf");

            Process.Start(filePath);
        }
        public static void Main(string[] args)
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            var generator        = new PdfGenerator();

            var htmlToConvert = @"
        <!DOCTYPE html>
        <html>
          <head>
          <style>
          /* Had to use this to fix the font sizing problem in linux. */
          html {
              height: 0;
              transform-origin: 0 0;
              -webkit-transform-origin: 0 0;
              transform: scale(0.53);
              -webkit-transform: scale(0.53);
          }
          </style>
          </head>
          <body>
              <h1>Hello World!</h1>
              <p>This PDF has been generated by PhantomJs ;)</p>
          </body>
        </html>";

            // Generate pdf from html and place in the current folder.
            var pathOfGeneratedPdf = generator.GeneratePdf(htmlToConvert, currentDirectory);

            Console.WriteLine("Pdf generated at: " + pathOfGeneratedPdf);
            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
Esempio n. 16
0
        public int TestGen()
        {
            PdfDocument document = new PdfDocument();

            document.Info.Title = "Test Generation";

            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);
            XFont     font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

            // Draw the text
            gfx.DrawString("Hello, World!", font, XBrushes.Black,
                           new XRect(0, 0, page.Width, page.Height),
                           XStringFormats.Center);

            // Save the document...
            const string filename = "HelloWorld.pdf";
            string       test     = AppDomain.CurrentDomain.BaseDirectory;
            string       html     = System.IO.File.ReadAllText(test + "test.html");
            PdfDocument  htmltest = PdfGenerator.GeneratePdf(html, PageSize.Letter);

            htmltest.Save(test + filename);
            //// ...and start a viewer.
            //Process.Start(filename);
            return(1);
        }
Esempio n. 17
0
        public static byte[] BuildTicketPdf(IEnumerable <PassengerForEditDto> passengers, Booking booking, FlightDetailsDto flight, User user)
        {
            var data = "<h2>Opole Airport reservation</h2>";

            data += $"Customer: {user.FirstName} {user.LastName}<br/>";
            data += $"Number of passengers: {booking.NumberOfPassengers}.<br/>";
            data += $"Flight from {flight.Origin.City}, " +
                    $"departure: {flight.DateOfDeparture:dddd, dd MMMM yyyy, HH:mm} UTC " +
                    $"to {flight.Destination.City}, " +
                    $"arrival: {flight.DateOfArrival:dddd, dd MMMM yyyy, HH:mm} UTC<br/>";
            data += $"Passengers for booking number {booking.Id}: <br/>";
            foreach (var passenger in passengers)
            {
                data += "<hr>";
                data += $"Name <b>{passenger.FirstName}</b>, Surname: <b>{passenger.LastName}</b>, " +
                        $"PESEL/Passport no.: <b>{passenger.IDNumber}</b> <br/>";
                data += $"Address: <b>{passenger.Street} {passenger.StreetNumber}</b>, City: <b>{passenger.City}</b>, " +
                        $"Post code: <b>{passenger.PostCode}</b>, Country: <b>{passenger.Country}</b><br/>";
            }

            using var ms = new MemoryStream();
            var pdf = PdfGenerator.GeneratePdf(data, PageSize.A4);

            pdf.Save(ms);
            return(ms.ToArray());
        }
        public IHttpActionResult GetInvoicePdf(string orderNumber)
        {
            var oderSearchResult = _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria
            {
                Number = orderNumber,
                Take   = 1
            });

            var order = oderSearchResult.Results.FirstOrDefault();

            if (order == null)
            {
                throw new NullReferenceException("order not found");
            }

            var invoice = _notificationManager.GetNewNotification(nameof(Invoice), null, null, "en-US");

            ((Invoice)invoice).Order = order;
            _notificationTemplateResolver.ResolveTemplate(invoice);

            var stream = new MemoryStream();
            var pdf    = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4);

            pdf.Save(stream, false);
            stream.Seek(0, SeekOrigin.Begin);

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(stream)
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return(ResponseMessage(result));
        }
Esempio n. 19
0
        public void Should_SuccessfulLogin_When_ValidCredentialsAreUsed()
        {
            _videoRecorder.StartRecording();

            var loginPage = new LoginPage(_driver);

            loginPage.Navigate();

            _screenShot.Take();

            InboxPage inboxPage = loginPage.Login(mailAddress, mailPassword);

            _screenShot.Take();

            Assert.IsTrue(inboxPage.IsPageLoaded());

            _screenShot.Take();

            log.Info(_screenShot.GeneratedFilesLog());

            _pdfGenerator.ImageFileNames = _screenShot.GeneratedFiles;

            _pdfGenerator.GeneratePdf();

            _emailSender.SendEmail(
                mailto: "*****@*****.**",
                subject: "Run - Test PDF File",
                body: "Attached the screenshot of this great and fantastic text",
                attachementFileName: _pdfGenerator.FileName);

            _videoRecorder.StopRecording();
        }
Esempio n. 20
0
        public HttpResponseMessage CreatePdf(int projectId)
        {
            //add a draft thus this is not a published pdf
            bool draft = true;
            //there is no version, only projectId
            int versionId = 0;
            var project   = CoreFactory.ProjectRepository.GetProject(projectId);

            var creator = string.Empty;

            if (project.CreatedBy != null)
            {
                if (!string.IsNullOrEmpty(project.CreatedBy.Name))
                {
                    creator = project.CreatedBy.Name;
                }
            }

            PdfGenerator.GeneratePdf(project, creator, versionId, draft, projectRepository.GetRoles());

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <object>(new
                {
                    VersionId = versionId,
                    ProjectId = project.Id
                }, Configuration.Formatters.JsonFormatter)
            });
        }
Esempio n. 21
0
        public int CreateVersion(ProjectVersionModel projectVersion)
        {
            var version = new ProjectVersion();

            if (projectVersion != null)
            {
                version = ApplicationMapper.MapProjectVersion(projectVersion);
            }

            var project = new Project();

            if (projectVersion != null)
            {
                project = projectRepository.GetProject(projectVersion.ProjectId);
            }

            ISerializer xmlSerializer = new SerializeXml();

            xmlSerializer.Serialize(project);
            version.ProjectData = xmlSerializer.Serialize(project);

            int versionId = projectRepository.CreateVersion(version);

            //generate PDF
            PdfGenerator.GeneratePdf(project, projectVersion.PublishedByName, versionId, false, projectRepository.GetRoles());

            return(versionId);
        }
Esempio n. 22
0
        public IHttpActionResult GetInvoicePdf(string orderNumber)
        {
            var searchCriteria = AbstractTypeFactory <CustomerOrderSearchCriteria> .TryCreateInstance();

            searchCriteria.Number = orderNumber;
            searchCriteria.Take   = 1;

            var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault();

            if (order == null)
            {
                throw new InvalidOperationException($"Cannot find order with number {orderNumber}");
            }

            var invoice = _notificationManager.GetNewNotification <InvoiceEmailNotification>(order.StoreId, "Store", order.LanguageCode);

            invoice.CustomerOrder = order;
            _notificationTemplateResolver.ResolveTemplate(invoice);

            var stream = new MemoryStream();
            var pdf    = PdfGenerator.GeneratePdf(invoice.Body, PdfSharp.PageSize.A4);

            pdf.Save(stream, false);
            stream.Seek(0, SeekOrigin.Begin);

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(stream)
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return(ResponseMessage(result));
        }
Esempio n. 23
0
        public static void PdfSharpConvert(string filename)
        {
            /*Converts the html in html.txt to pdf*/
            string      html = File.ReadAllText(".\\html.txt");
            PdfDocument pdf  = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);

            pdf.Save(filename);
        }
Esempio n. 24
0
        private static void Main(string[] args)
        {
            string      html = "<p><h1>Hello World</h1>This is html rendered text <span class='blue'>with css styling in blue</span></p>";
            string      css  = ".blue { color: blue; }";
            PdfDocument pdf  = PdfGenerator.GeneratePdf(html, PageSize.A4, 20, PdfGenerator.ParseStyleSheet(css));

            pdf.Save("document.pdf");
        }
Esempio n. 25
0
        private void button4_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = PdfGenerator.GeneratePdf("<p style='text-align: center;'><img src='https://scontent.fewr1-5.fna.fbcdn.net/v/t1.0-9/88015798_190546708840534_8824736610076590080_n.jpg?_nc_cat=105&amp;_nc_sid=85a577&amp;_nc_ohc=XI_tDXqyW2kAX-jLCnQ&amp;_nc_ht=scontent.fewr1-5.fna&amp;oh=50e8f3b3ff3ac5f47de1667d4299bfd5&amp;oe=5E94C262' alt='' width='740' height='740' /></p> <p style='text-align: center;'>sdfsdf</p> <table style='height: 187px; margin-left: auto; margin-right: auto;' width='574'> <tbody> <tr> <td style='width: 108px;'>sdf</td> <td style='width: 108px;'>sdf</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px; text-align: center;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> </tr> <tr> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>sdf</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> </tr> <tr> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>sdf</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> </tr> <tr> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>sdf</td> <td style='width: 108px;'>&nbsp;</td> </tr> <tr> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>&nbsp;</td> <td style='width: 108px;'>sdf</td> </tr> </tbody> </table>", PageSize.A4);

            //PdfImage pdi = PdfImage.;
            pdf.Save("document.pdf");
            System.Diagnostics.Process.Start("document.pdf");
        }
Esempio n. 26
0
        public ActionResult GeneratePdf(int id)
        {
            var application = _applicationService.GetApplication(id);

            var pdf = _pdfGenerator.GeneratePdf(application, out var title);

            return(File(pdf, "application/pdf", title));
        }
Esempio n. 27
0
        public static PdfDocument Generate(string template, IDictionary <string, string> tags)
        {
            foreach (var item in tags)
            {
                template = template.Replace(item.Key, item.Value);
            }

            return(PdfGenerator.GeneratePdf(template, PdfSharp.PageSize.A4));
        }
Esempio n. 28
0
        private static void WriteHTMLtoPDF(string _HTMLstring, string destination_file)
        {
            PdfSharp.Pdf.PdfDocument pdf = PdfGenerator.GeneratePdf(_HTMLstring, PdfSharp.PageSize.A4, 60);


            pdf.Save(destination_file);

            Console.WriteLine("Ready writing PDF file to disk!");
        }
 public static MemoryStream PdfSharpConvert(string html, CssData css)
 {
     using (var file = new MemoryStream())
     {
         var pdf = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4, 25, css);
         pdf.Save(file);
         return(file);
     }
 }
Esempio n. 30
0
 private void OnGeneratePdf_Click(object sender, RoutedEventArgs e)
 {
     using (var pdfDocument = PdfGenerator.GeneratePdf(_mainControl.GetHtml(), PageSize.A4))
     {
         var tmpFile = Path.ChangeExtension(Path.GetTempFileName(), ".pdf");
         pdfDocument.Save(tmpFile);
         Process.Start(tmpFile);
     }
 }