Ejemplo n.º 1
0
        //private void PDF_PreviewMouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        //{
        //    Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
        //    saveFileDialog.Filter = "PDF File|*.pdf";
        //    saveFileDialog.Title = "Save to a PDF file";
        //    saveFileDialog.ShowDialog();
        //    if (!string.IsNullOrEmpty(saveFileDialog.FileName))
        //    {
        //        float docWidth = (float)diagramView.Page.ActualWidth;
        //        float docHeight = (float)diagramView.Page.ActualHeight;
        //        string jpgFileName = "tempjpg.jpg";
        //        string xpsFileName = "tempXpS.xps";
        //        Syncfusion.XPS.XPSToPdfConverter xpsTopdfConverter = new Syncfusion.XPS.XPSToPdfConverter();
        //        Syncfusion.Pdf.Graphics.PdfUnitConvertor converter = new Syncfusion.Pdf.Graphics.PdfUnitConvertor();
        //        float pdfHeight = converter.ConvertUnits(docHeight, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Inch, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Point);
        //        float pdfWidth = converter.ConvertUnits(docWidth, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Inch, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Point);
        //        System.Drawing.SizeF pageSize = new System.Drawing.SizeF(pdfWidth, pdfHeight);
        //        diagramView.Save(jpgFileName, new Size(docWidth * 1.5, docHeight * 1.5), ImageStretch.Expand);
        //        Syncfusion.Pdf.PdfDocument pdfDocument = new Syncfusion.Pdf.PdfDocument();
        //        pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
        //        pdfDocument.PageSettings.Margins.All = 0;
        //        PdfImage image = new PdfBitmap(jpgFileName);
        //        pdfDocument.PageSettings.Size = image.PhysicalDimension;
        //        Syncfusion.Pdf.PdfPage page = pdfDocument.Pages.Add();
        //        page.Graphics.DrawImage(image, 0, 0);
        //        pdfDocument.Save(saveFileDialog.FileName);
        //        pdfDocument.Close(true);
        //        UpadteImageformat();
        //    }
        //}

        private void ExportToPDF_Click_1(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "PDF File|*.pdf";
            saveFileDialog.Title    = "Save to a PDF file";
            saveFileDialog.FileName = "Diagram";
            saveFileDialog.ShowDialog();
            if (!string.IsNullOrEmpty(saveFileDialog.FileName))
            {
                float  docWidth    = (float)diagramView.Page.ActualWidth;
                float  docHeight   = (float)diagramView.Page.ActualHeight;
                string jpgFileName = "tempjpg.jpg";
                string xpsFileName = "tempXpS.xps";
                Syncfusion.XPS.XPSToPdfConverter         xpsTopdfConverter = new Syncfusion.XPS.XPSToPdfConverter();
                Syncfusion.Pdf.Graphics.PdfUnitConvertor converter         = new Syncfusion.Pdf.Graphics.PdfUnitConvertor();
                float pdfHeight = converter.ConvertUnits(docHeight, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Inch, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Point);
                float pdfWidth  = converter.ConvertUnits(docWidth, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Inch, Syncfusion.Pdf.Graphics.PdfGraphicsUnit.Point);
                System.Drawing.SizeF pageSize = new System.Drawing.SizeF(pdfWidth, pdfHeight);
                diagramView.Save(jpgFileName, new Size(docWidth * 1.5, docHeight * 1.5), ImageStretch.Expand);
                Syncfusion.Pdf.PdfDocument pdfDocument = new Syncfusion.Pdf.PdfDocument();
                pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
                pdfDocument.PageSettings.Margins.All = 0;
                PdfImage image = new PdfBitmap(jpgFileName);
                pdfDocument.PageSettings.Size = image.PhysicalDimension;
                Syncfusion.Pdf.PdfPage page = pdfDocument.Pages.Add();
                page.Graphics.DrawImage(image, 0, 0);
                pdfDocument.Save(saveFileDialog.FileName);
                pdfDocument.Close(true);
                //UpadteImageformat();
            }
        }
Ejemplo n.º 2
0
        private void BtnPDF_Click(object sender, EventArgs e)
        {
            List <Sport> sport = new List <Sport>();

            sport = Info();
            //Create a new PDF document
            Syncfusion.Pdf.PdfDocument doc = new PdfDocument();
            //Add a page
            PdfPage page = doc.Pages.Add();
            // Create a PdfLightTable
            PdfLightTable pdfLightTable = new PdfLightTable();

            // Initialize DataTable to assign as DateSource to the light table
            System.Data.DataTable table = new System.Data.DataTable();
            //Include columns to the DataTable

            table.Columns.Add("Kolesar");
            table.Columns.Add("Total distance");
            table.Columns.Add("Total calories");
            table.Columns.Add("Total time");
            //Include rows to the DataTable
            int count = sport.Count;

            int stevec = 1;

            foreach (var item in sport)
            {
                table.Rows.Add(new string[] { stevec.ToString(), item.Stevilo_prevozenih_km, item.Porabljene_kalorije, item.Trajanje_aktivnosti });
                stevec++;
            }

            //Applying cell padding to table
            pdfLightTable.Style.CellPadding = 3;
            pdfLightTable.ApplyBuiltinStyle(PdfLightTableBuiltinStyle.GridTable3Accent3);
            //Assign data source
            pdfLightTable.DataSource = table;
            //Setting this property to true to show the header of table
            pdfLightTable.Style.ShowHeader = true;
            //Draw PdfLightTable
            pdfLightTable.Draw(page, new PointF(0, 0));
            //Save the document

            doc.Save("PdfTable.pdf");
            //Close the document
            doc.Close(true);
            //This will open the PDF file so, the result will be seen in default PDF viewer
            Process.Start("PdfTable.pdf");
        }
Ejemplo n.º 3
0
        private void BtnPK_Click(object sender, EventArgs e)
        {
            List <Sport> sport = new List <Sport>();

            sport = InfoWhole();
            //Create a new PDF document
            PdfDocument doc = new PdfDocument();
            //Add a page
            PdfPage page = doc.Pages.Add();
            // Create a PdfLightTable
            PdfLightTable pdfLightTable = new PdfLightTable();

            // Initialize DataTable to assign as DateSource to the light table
            System.Data.DataTable table = new System.Data.DataTable();
            //Include columns to the DataTable

            table.Columns.Add("Kalorije");
            table.Columns.Add("Vzpon distance");
            table.Columns.Add("Kadenca");
            table.Columns.Add("Avg kadenca");
            //Include rows to the DataTable
            int count = sport.Count;

            int stevec = 1;

            foreach (var item in sport)
            {
                table.Rows.Add(new string[] { item.Porabljene_kalorije, item.Skupen_vzpon, item.Max_kadenca, item.Povp_kadenca });
                stevec++;
            }

            //Applying cell padding to table
            pdfLightTable.Style.CellPadding = 3;
            pdfLightTable.ApplyBuiltinStyle(PdfLightTableBuiltinStyle.GridTable3Accent3);
            //Assign data source
            pdfLightTable.DataSource = table;
            //Setting this property to true to show the header of table
            pdfLightTable.Style.ShowHeader = true;
            //Draw PdfLightTable
            pdfLightTable.Draw(page, new PointF(0, 0));
            //Save the document

            doc.Save("PdfTable.pdf");
            //Close the document
            doc.Close(true);
            //This will open the PDF file so, the result will be seen in default PDF viewer
            Process.Start("PdfTable.pdf");
        }
Ejemplo n.º 4
0
        public static async void SaveChangesFile(string text)
        {
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument();
            await loadedDocument.OpenAsync(openFile).ConfigureAwait(true);

            loadedDocument.Pages.RemoveAt(0);
            Syncfusion.Pdf.PdfPage page     = (Syncfusion.Pdf.PdfPage)loadedDocument.Pages.Add();
            PdfGraphics            graphics = page.Graphics;

            Syncfusion.Pdf.Graphics.PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 0));
            await loadedDocument.Save().ConfigureAwait(true);

            loadedDocument.Dispose();
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Create a new PDF document
            using (PdfDocument document = new PdfDocument())
            {
                //Add a page to the document
                Syncfusion.Pdf.PdfPage page = document.Pages.Add();

                //Create PDF graphics for a page
                PdfGraphics graphics = page.Graphics;

                string column1   = String.Format("Вес: {0}\nРост: {1}\nAge: {2}\nАктивность: {3}\n", user.Weight, user.Height, user.Age, user.Activity);
                string column2   = String.Format("Белки: {0}\nЖиры: {1}\nУглеводы: {2}\nККалории: {3}\n", 0, 0, 0, user.GetDailyCalories());
                string copyright = "Copyright © 2019 - A.Karkanitsa Inc. All Rights Reserved";

                //Set the standard font
                PdfFont font1 = new PdfStandardFont(PdfFontFamily.Courier, 28, PdfFontStyle.Bold);
                PdfFont font2 = new PdfTrueTypeFont(new Font("Bookman Old Style", 14), true);
                PdfFont font3 = new PdfTrueTypeFont(new Font("Georgia", 14, FontStyle.Bold), true);
                PdfFont font4 = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Bold);
                PdfFont font5 = new PdfTrueTypeFont(new Font("Arial Unicode MS", 10), true);
                PdfFont font6 = new PdfTrueTypeFont(new Font("Georgia", 14), true);


                graphics.DrawString("Daily ", font1, PdfBrushes.Brown, new PointF(10, 10));
                graphics.DrawString("   Food ", font1, PdfBrushes.Brown, new PointF(10, 40));
                graphics.DrawString("      Ration ", font1, PdfBrushes.Brown, new PointF(10, 70));

                //Draw the image
                PdfImage image = PdfImage.FromFile("header.jpg");
                graphics.DrawImage(image, 300, 5);
                graphics.DrawLine(new PdfPen(Color.DarkBlue, 1), new PointF(10, 105), new PointF(500, 105));

                graphics.DrawString("Данные пользователя", font6, PdfBrushes.Blue, new PointF(10, 110));
                graphics.DrawString(column1, font2, PdfBrushes.Black, new PointF(10, 125));

                graphics.DrawString("КБЖУ", font6, PdfBrushes.Blue, new PointF(300, 110));
                graphics.DrawString(column2, font2, PdfBrushes.Black, new PointF(300, 125));
                graphics.DrawLine(new PdfPen(Color.DarkBlue, 1), new PointF(10, 200), new PointF(500, 200));

                //Write Ration
                int posY       = 215;
                int imageindex = 1;
                foreach (string s in service.GetRation().MealTimes.Keys)
                {
                    graphics.DrawString(s, font3, PdfBrushes.Brown, new PointF(55, posY));
                    posY += 15;
                    image = PdfImage.FromFile("mealtime" + imageindex + ".png");
                    imageindex++;
                    graphics.DrawImage(image, 10, posY, 40, 40);
                    foreach (Product p in service.GetRation().MealTimes[s].Meal)
                    {
                        string menuitem = String.Format("{0}: {1} грамм", p.Name, p.Weight);
                        graphics.DrawString(menuitem, font5, PdfBrushes.Black, new PointF(55, posY));
                        posY += 15;
                    }
                }
                graphics.DrawLine(new PdfPen(Color.DarkBlue, 2), new PointF(10, posY + 5), new PointF(500, posY + 5));
                graphics.DrawString("Итого (ккалорий): ", font3, PdfBrushes.Brown, new PointF(10, posY + 15));
                graphics.DrawString(service.GetRation().GetCalories().ToString(), font3, PdfBrushes.Green, new PointF(150, posY + 15));
                graphics.DrawString(copyright, font4, PdfBrushes.Black, new PointF(250, 750));

                document.Save("DailyRation.pdf");
                document.Close(true);
            }
        }