Ejemplo n.º 1
0
        protected void voucherPDF(List <vendacliente> pVendaCliente)
        {
            var document      = new PdfDocument();
            var page          = document.AddPage();
            var graphics      = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
            var textFormatter = new PdfSharp.Drawing.Layout.XTextFormatter(graphics);
            var font          = new PdfSharp.Drawing.XFont("Calibri", 12);
            var fontColuna    = new PdfSharp.Drawing.XFont("Calibri", 14);


            int y = 55;

            textFormatter.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left;
            textFormatter.DrawString("Voucher ", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(30, y, page.Width - 60, page.Height - 60));
            textFormatter.DrawString("Destino: " + ddlViagem.SelectedItem.ToString(), font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(200, y, page.Width - 60, page.Height - 60));

            y = y + 40;
            textFormatter.DrawString("Cliente", fontColuna, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(30, y, page.Width - 60, page.Height - 60));
            textFormatter.DrawString("Faixa Etaria", fontColuna, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(200, y, page.Width - 60, page.Height - 60));
            textFormatter.DrawString("Assento", fontColuna, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, y, page.Width - 60, page.Height - 60));
            textFormatter.DrawString("Valor Pago", fontColuna, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(370, y, page.Width - 60, page.Height - 60));
            y = y + 5;
            decimal ValorTotal = 0;

            foreach (var item in pVendaCliente)
            {
                ValorTotal += item.VendaValorPago;
                y           = y + 30;
                textFormatter.DrawString(SvcCliente.BuscarCliente(item.VendaIdCliente).Nome, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(30, y, page.Width - 60, page.Height - 60));
                textFormatter.DrawString(item.FaixaEtaria, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(200, y, page.Width - 60, page.Height - 60));
                textFormatter.DrawString(item.Assento.ToString(), font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, y, page.Width - 60, page.Height - 60));
                textFormatter.DrawString(item.VendaValorPago.ToString(), font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(370, y, page.Width - 60, page.Height - 60));
            }
            textFormatter.DrawString("Valor Total: " + ValorTotal.ToString(), font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(100, 50 + y, page.Width - 60, page.Height - 60));
            textFormatter.DrawString("Autorizado por: ____________________________________ ", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(100, 100 + y, page.Width - 60, page.Height - 60));

            PdfSharp.Drawing.XRect  layoutRectangle = new PdfSharp.Drawing.XRect(0 /*X*/, page.Height - font.Height /*Y*/, page.Width /*Width*/, font.Height /*Height*/);
            PdfSharp.Drawing.XBrush brush           = PdfSharp.Drawing.XBrushes.Black;
            string noPages = document.Pages.Count.ToString();

            for (int i = 0; i < document.Pages.Count; ++i)
            {
                graphics.DrawString(
                    "Page " + (i + 1).ToString() + " of " + noPages,
                    font,
                    brush,
                    layoutRectangle,
                    PdfSharp.Drawing.XStringFormats.Center);

                graphics.DrawString(
                    "Data: " + DateTime.Now,
                    font,
                    brush,
                    layoutRectangle,
                    PdfSharp.Drawing.XStringFormats.TopLeft);
            }

            document.Save("Vendas.pdf");
            System.Diagnostics.Process.Start("chrome.exe", "Vendas.pdf");
        }
Ejemplo n.º 2
0
        static void CropPdf2()
        {
            string fn = @"D:\username\Desktop\0001 Altstetten - GB01 H602 - OG14.pdf";

            int ten     = (int)(28.3465 * 10);
            int hundred = (int)(28.3465 * 100);

            int x = ten / 20;
            int y = hundred / 20;

            PdfSharp.Drawing.XRect cropDim = new PdfSharp.Drawing.XRect(0, 0, 200, 200);
            cropDim = new PdfSharp.Drawing.XRect(200, 200, 200, 200);

            using (PdfSharp.Pdf.PdfDocument sourceDocument = PdfSharp.Pdf.IO.PdfReader.Open(fn))
            {
                PdfSharp.Pdf.PdfPage sourcePage = sourceDocument.Pages[0];

                // Crop the PDF - DOES IT WRONG...
                // sourcePage.CropBox = new PdfSharp.Pdf.PdfRectangle(cropDim);

                PdfSharp.Drawing.XRect cropRect = new PdfSharp.Drawing.XRect(cropDim.X, sourcePage.Height.Point - cropDim.Height - cropDim.Y, cropDim.Width, cropDim.Height);
                sourcePage.CropBox = new PdfSharp.Pdf.PdfRectangle(cropRect);

                sourceDocument.Save("CropPdf2.pdf");
            } // End Using sourceDocument
        }     // End Sub CropPdf2
Ejemplo n.º 3
0
 /// <summary>Set page margins in millimeter</summary>
 /// <param name="left_mm">Left margin in millimetter</param>
 /// <param name="rigth_mm">Rigth margin in millimetter</param>
 /// <param name="top_mm">Top margin in millimetter</param>
 /// <param name="bottom_mm">Bottom margin in millimetter</param>
 public void setMargins(int left_mm, int rigth_mm, int top_mm, int bottom_mm)
 {
     PdfSharp.Drawing.XUnit left = PdfSharp.Drawing.XUnit.FromMillimeter(left_mm);
     PdfSharp.Drawing.XUnit top  = PdfSharp.Drawing.XUnit.FromMillimeter(top_mm);
     _horizontalePosition = _horizontalePosition + left - _area.X;
     _verticalPosition    = _verticalPosition + top - _area.Y;
     _area = new PdfSharp.Drawing.XRect {
         X      = left,
         Y      = top,
         Width  = _page.Width - PdfSharp.Drawing.XUnit.FromMillimeter(left_mm + rigth_mm),
         Height = _page.Height - PdfSharp.Drawing.XUnit.FromMillimeter(top_mm + bottom_mm)
     };
 }
Ejemplo n.º 4
0
 /// <summary>Add a new page if the current page is not empty</summary>
 public void addPage()
 {
     if (!_isPageEmpty)
     {
         if (_pageCount != 0)
         {
             addPagenumber();
         }
         _page = new PdfSharp.Pdf.PdfPage();
         if (_pageCount == 0)
         {
             _size.Width  = _page.Width;
             _size.Height = _page.Height;
             _area        = new PdfSharp.Drawing.XRect {
                 X      = PdfSharp.Drawing.XUnit.FromMillimeter(10),
                 Y      = PdfSharp.Drawing.XUnit.FromMillimeter(10),
                 Width  = _page.Width - PdfSharp.Drawing.XUnit.FromMillimeter(20),
                 Height = _page.Height - PdfSharp.Drawing.XUnit.FromMillimeter(45)
             };
         }
         else
         {
             _page        = new PdfSharp.Pdf.PdfPage();
             _page.Width  = _size.Width;
             _page.Height = _size.Height;
         }
         _horizontalePosition = _area.X;
         _verticalPosition    = _area.Y;
         _doc.AddPage(_page);
         if (_graphics != null)
         {
             _graphics.Dispose();
         }
         _graphics     = PdfSharp.Drawing.XGraphics.FromPdfPage(_page);
         _textformater = new PdfSharp.Drawing.Layout.XTextFormatter(_graphics);
         _pageCount++;
         _isPageEmpty = true;
     }
 }
Ejemplo n.º 5
0
        public static void CropPdf1(double crop_width, double crop_height)
        {
            string fn = @"D:\username\Desktop\0001 Altstetten - GB01 H602 - OG14.pdf";

            // fn = @"D:\username\Desktop\0030 Sentimatt - GB01 Sentimatt - EG00.pdf";


            // The current implementation of PDFsharp has only one layout of the graphics context.
            // The origin(0, 0) is top left and coordinates grow right and down.
            // The unit of measure is always point (1 / 72 inch).

            // 1 pt = 0,0352778 cm
            // 1 pt = 0,352778 mm
            // 1 inch = 2,54 cm
            // 1/72 inch to cm = 0,035277777777777776 cm


            // A0:
            // w: 2384 pt =  84,10222 cm
            // h: 3370 pt = 118,8861  cm

            // A3:
            // w:  842 pt = 29,7039  cm
            // h: 1191 pt = 42,01583 cm

            // A4:
            // 595 pt to cm = 20,9903 w
            // 842 pt to cm = 29,7039 h


            using (PdfSharp.Drawing.XPdfForm sourceForm = PdfSharp.Drawing.XPdfForm.FromFile(fn))
            {
                sourceForm.PageNumber = 1;

                int numHori  = (int)System.Math.Ceiling(sourceForm.Page.Width.Point / crop_width);
                int numVerti = (int)System.Math.Ceiling(sourceForm.Page.Height.Point / crop_height);
                PdfSharp.Drawing.XRect pageDimenstions = new PdfSharp.Drawing.XRect(0, 0, sourceForm.Page.Width.Point, sourceForm.Page.Height.Point);


                // Crop the PDF - HAS NO EFFECT...
                // sourceForm.Page.CropBox = new PdfSharp.Pdf.PdfRectangle(cropDim);

                using (PdfSharp.Pdf.PdfDocument destDocument = new PdfSharp.Pdf.PdfDocument())
                {
                    for (int iverti = 0; iverti < numHori; iverti++)
                    {
                        for (int ihori = 0; ihori < numHori; ihori++)
                        {
                            PdfSharp.Pdf.PdfPage destPage = destDocument.AddPage();
                            destPage.Width  = sourceForm.Page.Width;
                            destPage.Height = sourceForm.Page.Height;


                            PdfSharp.Drawing.XRect cropDim = new PdfSharp.Drawing.XRect(ihori * crop_width, iverti * crop_height, crop_width, crop_height);

                            PdfSharp.Drawing.XRect cropRect = new PdfSharp.Drawing.XRect(cropDim.X, destPage.Height.Point - cropDim.Height - cropDim.Y, cropDim.Width, cropDim.Height);

                            using (PdfSharp.Drawing.XGraphics destGFX = PdfSharp.Drawing.XGraphics.FromPdfPage(destPage))
                            {
                                destGFX.DrawImage(sourceForm, pageDimenstions);
                                destGFX.DrawRectangle(PdfSharp.Drawing.XPens.DeepPink, cropDim);
                            } // End Using destGFX

                            // PdfSharp.Drawing.XRect cropRect1 = new PdfSharp.Drawing.XRect(cropRect.X - 30, cropRect.Y - 30, cropRect.Width + 30, cropRect.Height + 30);

                            destPage.CropBox = new PdfSharp.Pdf.PdfRectangle(cropRect);
                            // destPage.MediaBox = new PdfSharp.Pdf.PdfRectangle(cropRect1);

                            // destPage.CropBox = new PdfSharp.Pdf.PdfRectangle(new XPoint(cropDim.X, destPage.Height - cropDim.Height - cropDim.Y),
                            //                      new XSize(cropDim.Width, cropDim.Height));
                        } // Next ihori
                    }     // Next iverti

                    destDocument.Save("CropPdf1.pdf");
                } // End Using gfx
            }     // End Using document
        }         // End Sub CropPdf1
Ejemplo n.º 6
0
        public static string makeIt(string out_name, string source, ID_MACROS.IDS.PAGE_MODE md)
        {
            if (md == ID_MACROS.IDS.PAGE_MODE.mode1)
            {
                string                         filename       = source;
                PdfDocument                    outputDocument = new PdfDocument();
                PdfSharp.Drawing.XFont         font           = new PdfSharp.Drawing.XFont("Times New Roman", 10, PdfSharp.Drawing.XFontStyle.Regular);
                PdfSharp.Drawing.XStringFormat format         = new PdfSharp.Drawing.XStringFormat();
                format.Alignment     = PdfSharp.Drawing.XStringAlignment.Near;
                format.LineAlignment = PdfSharp.Drawing.XLineAlignment.Far;
                PdfSharp.Drawing.XGraphics gfx;
                PdfSharp.Drawing.XRect     box;
                PdfSharp.Drawing.XPdfForm  form = PdfSharp.Drawing.XPdfForm.FromFile(filename);
                for (int idx = 0; idx < form.PageCount; idx++)
                {
                    PdfPage page   = outputDocument.AddPage();
                    double  width  = page.Width;
                    double  height = page.Height;
                    gfx             = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
                    form.PageNumber = idx + 1;
                    box             = new PdfSharp.Drawing.XRect(0, 0, width, height);
                    gfx.DrawImage(form, box);
                    box.Inflate(0, -30);
                }
                filename = out_name;
                outputDocument.Save(filename);
                return(filename);
            }
            else
            {
                int[]                          lst            = PDF_MAKER.PDF_MAKER.Page_Number_List;
                string                         filename       = source;
                PdfDocument                    outputDocument = new PdfDocument();
                PdfSharp.Drawing.XFont         font           = new PdfSharp.Drawing.XFont("Times New Roman", 10, PdfSharp.Drawing.XFontStyle.Regular);
                PdfSharp.Drawing.XStringFormat format         = new PdfSharp.Drawing.XStringFormat();
                format.Alignment     = PdfSharp.Drawing.XStringAlignment.Center;
                format.LineAlignment = PdfSharp.Drawing.XLineAlignment.Far;
                PdfSharp.Drawing.XGraphics gfx;
                PdfSharp.Drawing.XRect     box;
                PdfSharp.Drawing.XPdfForm  form = PdfSharp.Drawing.XPdfForm.FromFile(filename);
                for (int idx = 0; idx < form.PageCount; idx++)
                {
                    PdfPage page   = outputDocument.AddPage();
                    double  width  = page.Width;
                    double  height = page.Height;
                    gfx             = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
                    form.PageNumber = idx + 1;
                    box             = new PdfSharp.Drawing.XRect(0, 0, width, height);
                    gfx.DrawImage(form, box);
                    box.Inflate(0, -30);

                    if (lst[idx] == 2)
                    {
                        gfx.DrawString(String.Format("{1}", filename, idx + 1), font, PdfSharp.Drawing.XBrushes.Black, box, format);
                    }
                    else if (lst[idx] == 1)
                    {
                        gfx.DrawString(String.Format("{1}", filename, PAGE_MODE_II_NUMBERS.RomanNumbers.convert(idx + 1)), font, PdfSharp.Drawing.XBrushes.Black, box, format);
                    }
                    else
                    {
                    }
                }
                filename = out_name;
                outputDocument.Save(filename);
                return(filename);
            }
        }
Ejemplo n.º 7
0
        private void ToDaysFinances_Click(object sender, EventArgs e)
        {
            MiddleWare.middle.OpenConnection();
                    SqlCommand GetData = new SqlCommand(string.Format("select FeeID, GrossCost, TotalCost, comments from Fees;"), MiddleWare.middle.dbConnection);
                    String feeID = "";
                    String grossCost = "";
                    String DiscountedCost = "";
                    String comments = "";
                    int totalCost = 0;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    adapter.SelectCommand = GetData;
                    adapter.Fill(ds);

                    MiddleWare.middle.CloseConnection();

                    string printString;
                    PdfSharp.Pdf.PdfDocument PDFDocument = new PdfSharp.Pdf.PdfDocument();
                    PDFDocument.Info.Title = "Financial History";
                    PdfSharp.Pdf.PdfPage PDFPage = PDFDocument.AddPage();
                    PdfSharp.Drawing.XGraphics PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);
                    PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Verdana", 12, PdfSharp.Drawing.XFontStyle.Bold);
                    PdfSharp.Drawing.XRect rec = new PdfSharp.Drawing.XRect((PDFPage.Width / 8), 110, PDFPage.Width, PDFPage.Height);
                    // 0 - 90 banner
                    PDFGraphics.DrawString("Q Medic Hospital Banner Goes Here", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect((PDFPage.Width / 4), 50, PDFPage.Width, PDFPage.Height), PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Q Medic Financials";
                    rec.Y = 150;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    int yPoint = 220;

                    PDFGraphics.DrawString("Invoice No", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("Gross Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(120, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("Discounted Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(220, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("TotalCost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(360, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("Comments", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(500, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    yPoint = 250;
                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
                        if (yPoint > 820){
                            yPoint = 50;
                            PDFPage = PDFDocument.AddPage();
                            PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);
                            PDFGraphics.DrawString("Invoice No", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                            PDFGraphics.DrawString("Gross Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(120, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                            PDFGraphics.DrawString("Discounted Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(220, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                            PDFGraphics.DrawString("TotalCost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(360, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                            PDFGraphics.DrawString("Comments", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(500, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                            yPoint = 70;
                        }
                        feeID = ds.Tables[0].Rows[i].ItemArray[0].ToString();
                        grossCost = ds.Tables[0].Rows[i].ItemArray[1].ToString();
                        DiscountedCost = ds.Tables[0].Rows[i].ItemArray[2].ToString();
                        comments = ds.Tables[0].Rows[i].ItemArray[3].ToString();

                        PDFGraphics.DrawString(feeID, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        PDFGraphics.DrawString("$" + grossCost + ".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(120, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        PDFGraphics.DrawString("$" + DiscountedCost + ".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(220, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        try {
                            totalCost += Convert.ToInt32(DiscountedCost);
                            PDFGraphics.DrawString("$" + totalCost + ".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(360, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        }
                        catch {
                            PDFGraphics.DrawString("NaN", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(500, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        }
                        PDFGraphics.DrawString(comments, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(500, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        yPoint = yPoint + 20;
                    }
                    yPoint += 40;
                    PDFGraphics.DrawString("Grand Total: ", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(320, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    PDFGraphics.DrawString("$" + totalCost + ".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    String filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HospitalExport\\" +  "Hospital_Takings.pdf";
                    PDFDocument.Save(filename);

            // tabel of all the treatments
        }
Ejemplo n.º 8
0
        private void ExportPaitentDetails_Click(object sender, EventArgs e)
        {
            int PID;
            try {
                PID = Convert.ToInt32(PatientBox.Text);
            }
            catch {
                PID = -1;
                PatientBox.Text = "Number Reqired";
            }

            if (PID > -1) {
                MiddleWare.middle.OpenConnection();

                SqlCommand GetData = new SqlCommand(string.Format("select FirstName, LastName, Gender, DateOfBirth, StreetNo, StreetAddress, Suburb, PostCode, PhoneNumber, MobileNumber, Email from Patients WHERE PatientID='{0}';", PID), MiddleWare.middle.dbConnection);
                SqlDataReader dataReader = GetData.ExecuteReader();
                if (dataReader.HasRows) {
                    dataReader.Read();
                    String name = dataReader.GetString(0) + " " + dataReader.GetString(1);
                    String gender;
                    if (dataReader.GetBoolean(2) == true) {
                        gender = "Female";
                    } else {
                        gender = "Male";
                    }
                    String DOB = dataReader.GetString(3);
                    String address = dataReader.GetString(4) + " " + dataReader.GetString(5) + " " + dataReader.GetString(6) + " - PostCode: " + dataReader.GetString(7);
                    String phoneNumber = dataReader.GetString(8);
                    String mobileNumber = dataReader.GetString(9);
                    String Email = dataReader.GetString(10);

                    MiddleWare.middle.CloseConnection();

                    string printString;
                    PdfSharp.Pdf.PdfDocument PDFDocument = new PdfSharp.Pdf.PdfDocument();
                    PDFDocument.Info.Title = "Patient Details";
                    PdfSharp.Pdf.PdfPage PDFPage = PDFDocument.AddPage();
                    PdfSharp.Drawing.XGraphics PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);
                    PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Verdana", 12, PdfSharp.Drawing.XFontStyle.Bold);
                    PdfSharp.Drawing.XRect rec = new PdfSharp.Drawing.XRect((PDFPage.Width / 8), 110, PDFPage.Width, PDFPage.Height);
                    // 0 - 90 banner
                    PDFGraphics.DrawString("Q Medic Hospital Banner Goes Here", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect((PDFPage.Width / 4), 50, PDFPage.Width, PDFPage.Height), PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Patient ID: " + PID;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    rec.X = (PDFPage.Width / 8) + 20;

                    printString = "Name: " + name;
                    rec.Y = 150;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Gender: " + gender;
                    rec.Y = 170;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Date Of Birth: " + DOB;
                    rec.Y = 190;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Address: " + address;
                    rec.Y = 210;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Phone Number: " + phoneNumber;
                    rec.Y = 230;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Mobile Number: " + mobileNumber;
                    rec.Y = 250;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "E-mail: " + Email;
                    rec.Y = 270;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);

                    String filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HospitalExport\\" +  PID + "_PaitentDetails.pdf";
                    PDFDocument.Save(filename);
                }
            }
        }
Ejemplo n.º 9
0
        private void PaitentTreatments_Click(object sender, EventArgs e)
        {
            int PID;
            try {
                PID = Convert.ToInt32(PatientBox.Text);
            }
            catch {
                PID = -1;
                PatientBox.Text = "Number Reqired";
            }

            if (PID > -1) {
                MiddleWare.middle.OpenConnection();

                SqlCommand GetData = new SqlCommand(string.Format("select FirstName, LastName from Patients WHERE PatientID='{0}';", PID), MiddleWare.middle.dbConnection);
                SqlDataReader dataReader = GetData.ExecuteReader();
                if (dataReader.HasRows) {
                    dataReader.Read();
                    String name = dataReader.GetString(0) + " " + dataReader.GetString(1);
                    MiddleWare.middle.CloseConnection();

                    MiddleWare.middle.OpenConnection();
                    String TreatmentID = "";
                    String staffName = "";
                    String TreatmentDate = "";
                    String TreatmentTime = "";
                    int totalCost = 0;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    GetData = new SqlCommand(string.Format("SELECT Treatment.TreatmentID, Staff.StaffID, StaffType.StaffTypeName, Staff.FirstName, Staff.LastName, Treatment.PatientID, Treatment.TreatmentDate, Treatment.TreatmentTime FROM Treatment INNER JOIN Staff ON Treatment.StaffID = Staff.StaffID INNER JOIN StaffType ON Staff.StaffTypeID = StaffType.StaffTypeID WHERE (Treatment.PatientID = '{0}')", PID), MiddleWare.middle.dbConnection);
                    adapter.SelectCommand = GetData;
                    adapter.Fill(ds);

                    MiddleWare.middle.CloseConnection();

                    string printString;
                    PdfSharp.Pdf.PdfDocument PDFDocument = new PdfSharp.Pdf.PdfDocument();
                    PDFDocument.Info.Title = "Patient Treatments";
                    PdfSharp.Pdf.PdfPage PDFPage = PDFDocument.AddPage();
                    PdfSharp.Drawing.XGraphics PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);
                    PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Verdana", 12, PdfSharp.Drawing.XFontStyle.Bold);
                    PdfSharp.Drawing.XRect rec = new PdfSharp.Drawing.XRect((PDFPage.Width / 8), 110, PDFPage.Width, PDFPage.Height);
                    // 0 - 90 banner
                    PDFGraphics.DrawString("Q Medic Hospital Banner Goes Here", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect((PDFPage.Width / 4), 50, PDFPage.Width, PDFPage.Height), PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Patient ID: " + PID;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    rec.X = (PDFPage.Width / 8) + 20;

                    printString = "Name: " + name;
                    rec.Y = 150;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    int yPoint = 220;

                    PDFGraphics.DrawString("Treatment ID", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    PDFGraphics.DrawString("Staff", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(180, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    PDFGraphics.DrawString("Treatment Date", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    PDFGraphics.DrawString("Treatment Time", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    yPoint = 250;
                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) {
                        TreatmentID = ds.Tables[0].Rows[i].ItemArray[0].ToString();
                        staffName = ds.Tables[0].Rows[i].ItemArray[3].ToString() + " " + ds.Tables[0].Rows[i].ItemArray[4].ToString();
                        TreatmentDate = ds.Tables[0].Rows[i].ItemArray[6].ToString();
                        TreatmentTime = ds.Tables[0].Rows[i].ItemArray[7].ToString();

                        PDFGraphics.DrawString(TreatmentID, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        PDFGraphics.DrawString(staffName, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(180, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        PDFGraphics.DrawString(TreatmentDate, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                       PDFGraphics.DrawString(TreatmentTime, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        yPoint = yPoint + 20;
                    }

                    String filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HospitalExport\\" + PID + "_PaitentTreatment.pdf";
                    PDFDocument.Save(filename);
                }
            }
            // treatment for patients
        }
Ejemplo n.º 10
0
 /// <summary>Set page margins in millimeter</summary>
 /// <param name="left_mm">Left margin in millimetter</param>
 /// <param name="rigth_mm">Rigth margin in millimetter</param>
 /// <param name="top_mm">Top margin in millimetter</param>
 /// <param name="bottom_mm">Bottom margin in millimetter</param>
 public void setMargins(int left_mm, int rigth_mm, int top_mm, int bottom_mm) {
     PdfSharp.Drawing.XUnit left = PdfSharp.Drawing.XUnit.FromMillimeter(left_mm);
     PdfSharp.Drawing.XUnit top = PdfSharp.Drawing.XUnit.FromMillimeter(top_mm);
     _horizontalePosition = _horizontalePosition + left - _area.X;
     _verticalPosition = _verticalPosition + top - _area.Y;
     _area = new PdfSharp.Drawing.XRect {
         X = left,
         Y = top,
         Width = _page.Width - PdfSharp.Drawing.XUnit.FromMillimeter(left_mm + rigth_mm),
         Height = _page.Height - PdfSharp.Drawing.XUnit.FromMillimeter(top_mm + bottom_mm)
     };
 }
Ejemplo n.º 11
0
 private void AddTextToPdf(string text, PdfSharp.Drawing.XFont xfont, PdfSharp.Drawing.XBrush xBrush, PdfSharp.Drawing.XRect rect)
 {
     rect.X = _horizontalePosition + rect.X;
     rect.Y = _verticalPosition + rect.Y;
     _textformater.DrawString(text, xfont, xBrush, rect, PdfSharp.Drawing.XStringFormats.TopLeft);
     _verticalPosition = rect.Y + rect.Height;
     _isPageEmpty      = false;
 }
Ejemplo n.º 12
0
        /// <summary>Add text</summary>
        /// <param name="text">Text to add</param>
        /// <param name="size">Optional - font size</param>
        /// <param name="color">Optional - font color</param>
        /// <param name="bold">Optional - bold</param>
        /// <param name="italic">Optional - italic</param>
        /// <param name="underline">Optional - underline</param>
        /// <param name="center">Optional - center the texte</param>
        /// <param name="font">Optional - Font name. Default is Helvetica</param>
        public void addText(string text,
                            int size       = 10,
                            string color   = "Black",
                            bool bold      = false,
                            bool italic    = false,
                            bool underline = false,
                            bool center    = false,
                            string font    = "Helvetica")
        {
            PdfSharp.Drawing.XFontStyle xfontStyle =
                (bold ? PdfSharp.Drawing.XFontStyle.Bold : 0)
                | (underline ? PdfSharp.Drawing.XFontStyle.Underline : 0)
                | (italic ? PdfSharp.Drawing.XFontStyle.Italic : 0);
            PdfSharp.Drawing.XFont xfont;
            if (bold || underline || italic)
            {
                xfont = new PdfSharp.Drawing.XFont(font, size, xfontStyle);
            }
            else
            {
                xfont = new PdfSharp.Drawing.XFont(font, size);
            }
            PdfSharp.Drawing.XBrush xBrush;
            try {
                xBrush = (PdfSharp.Drawing.XSolidBrush) typeof(PdfSharp.Drawing.XBrushes).GetProperty(color).GetValue(null, null);
            } catch (Exception) {
                throw new ArgumentException("Color <" + color + "> is not available!");
            }

            if (center)
            {
                PdfSharp.Drawing.XSize strSize = _graphics.MeasureString(text, xfont);
                double minWidth             = Math.Min(strSize.Width, _area.Width);
                PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                    X      = (_area.Width / 2) - (minWidth / 2),
                    Y      = +2,
                    Width  = minWidth,
                    Height = strSize.Height
                };
                this.AddTextToPdf(text, xfont, xBrush, rect);
            }
            else
            {
                string leftText = text;
                while (true)
                {
                    int    lenToAdd;
                    string textToAdd;
                    PdfSharp.Drawing.XSize textSize = _graphics.MeasureString(leftText, xfont, PdfSharp.Drawing.XStringFormats.Default);
                    double textHeight;
                    if (textSize.Width < _area.Width)
                    {
                        textHeight = textSize.Height;
                    }
                    else
                    {
                        textHeight = textSize.Height * 1.2 * (textSize.Width / _area.Width);
                    }

                    if (textHeight < this.AvailableHeigth)
                    {
                        PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                            X      = 0,
                            Y      = 2,
                            Width  = _area.Width,
                            Height = textHeight
                        };
                        this.AddTextToPdf(leftText, xfont, xBrush, rect);
                        break;
                    }
                    else
                    {
                        if (textSize.Width < _area.Width)
                        {
                            lenToAdd  = leftText.Length;
                            textToAdd = leftText.Substring(0, lenToAdd);
                        }
                        else
                        {
                            lenToAdd = (int)(((float)leftText.Length) * this.AvailableHeigth / textHeight * 1.1);
                            while (true)
                            {
                                lenToAdd = leftText.LastIndexOf(' ', lenToAdd - 1);
                                string str = leftText.Substring(0, lenToAdd);
                                textSize   = _graphics.MeasureString(str, xfont);
                                textHeight = textSize.Height * 1.2 * textSize.Width / _area.Width;
                                if (textHeight < this.AvailableHeigth)
                                {
                                    break;
                                }
                            }
                            textToAdd = leftText.Substring(0, lenToAdd);
                        }
                        if (lenToAdd == 0)
                        {
                            break;
                        }

                        PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                            X      = 0,
                            Y      = 2,
                            Width  = _area.Width,
                            Height = textHeight
                        };
                        this.AddTextToPdf(textToAdd, xfont, xBrush, rect);
                        this.addPage();
                        if (leftText.Length == 0)
                        {
                            break;
                        }
                        leftText = leftText.Substring(lenToAdd);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>Add text</summary>
        /// <param name="text">Text to add</param>
        /// <param name="size">Optional - font size</param>
        /// <param name="color">Optional - font color</param>
        /// <param name="bold">Optional - bold</param>
        /// <param name="italic">Optional - italic</param>
        /// <param name="underline">Optional - underline</param>
        /// <param name="center">Optional - center the texte</param>
        /// <param name="font">Optional - Font name. Default is Helvetica</param>
        public void addText(string text,
            int size = 10,
            string color = "Black",
            bool bold = false,
            bool italic = false,
            bool underline = false,
            bool center = false,
            string font = "Helvetica") {
            PdfSharp.Drawing.XFontStyle xfontStyle =
                (bold ? PdfSharp.Drawing.XFontStyle.Bold : 0)
                | (underline ? PdfSharp.Drawing.XFontStyle.Underline : 0)
                | (italic ? PdfSharp.Drawing.XFontStyle.Italic : 0);
            PdfSharp.Drawing.XFont xfont;
            if (bold || underline || italic)
                xfont = new PdfSharp.Drawing.XFont(font, size, xfontStyle);
            else
                xfont = new PdfSharp.Drawing.XFont(font, size);
            PdfSharp.Drawing.XBrush xBrush;
            try {
                xBrush = (PdfSharp.Drawing.XSolidBrush)typeof(PdfSharp.Drawing.XBrushes).GetProperty(color).GetValue(null, null);
            } catch (Exception) {
                throw new ArgumentException("Color <" + color + "> is not available!");
            }

            if (center) {
                PdfSharp.Drawing.XSize strSize = _graphics.MeasureString(text, xfont);
                double minWidth = Math.Min(strSize.Width, _area.Width);
                PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                    X = (_area.Width / 2) - (minWidth / 2),
                    Y = +2,
                    Width = minWidth,
                    Height = strSize.Height
                };
                this.AddTextToPdf(text, xfont, xBrush, rect);
            } else {
                string leftText = text;
                while (true) {
                    int lenToAdd;
                    string textToAdd;
                    PdfSharp.Drawing.XSize textSize = _graphics.MeasureString(leftText, xfont, PdfSharp.Drawing.XStringFormats.Default);
                    double textHeight;
                    if (textSize.Width < _area.Width)
                        textHeight = textSize.Height;
                    else
                        textHeight = textSize.Height * 1.2 * (textSize.Width / _area.Width);

                    if (textHeight < this.AvailableHeigth) {
                        PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                            X = 0,
                            Y = 2,
                            Width = _area.Width,
                            Height = textHeight
                        };
                        this.AddTextToPdf(leftText, xfont, xBrush, rect);
                        break;
                    } else {
                        if (textSize.Width < _area.Width) {
                            lenToAdd = leftText.Length;
                            textToAdd = leftText.Substring(0, lenToAdd);
                        } else {
                            lenToAdd = (int)(((float)leftText.Length) * this.AvailableHeigth / textHeight * 1.1);
                            while (true) {
                                lenToAdd = leftText.LastIndexOf(' ', lenToAdd - 1);
                                string str = leftText.Substring(0, lenToAdd);
                                textSize = _graphics.MeasureString(str, xfont);
                                textHeight = textSize.Height * 1.2 * textSize.Width / _area.Width;
                                if (textHeight < this.AvailableHeigth) break;
                            }
                            textToAdd = leftText.Substring(0, lenToAdd);
                        }
                        if (lenToAdd == 0) break;

                        PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect {
                            X = 0,
                            Y = 2,
                            Width = _area.Width,
                            Height = textHeight
                        };
                        this.AddTextToPdf(textToAdd, xfont, xBrush, rect);
                        this.addPage();
                        if (leftText.Length == 0) break;
                        leftText = leftText.Substring(lenToAdd);
                    }
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>Add a new page if the current page is not empty</summary>
 public void addPage() {
     if (!_isPageEmpty) {
         if (_pageCount != 0)
             addPagenumber();
         _page = new PdfSharp.Pdf.PdfPage();
         if (_pageCount == 0) {
             _size.Width = _page.Width;
             _size.Height = _page.Height;
             _area = new PdfSharp.Drawing.XRect {
                 X = PdfSharp.Drawing.XUnit.FromMillimeter(10),
                 Y = PdfSharp.Drawing.XUnit.FromMillimeter(10),
                 Width = _page.Width - PdfSharp.Drawing.XUnit.FromMillimeter(20),
                 Height = _page.Height - PdfSharp.Drawing.XUnit.FromMillimeter(45)
             };
         } else {
             _page = new PdfSharp.Pdf.PdfPage();
             _page.Width = _size.Width;
             _page.Height = _size.Height;
         }
         _horizontalePosition = _area.X;
         _verticalPosition = _area.Y;
         _doc.AddPage(_page);
         if (_graphics != null)
             _graphics.Dispose();
         _graphics = PdfSharp.Drawing.XGraphics.FromPdfPage(_page);
         _textformater = new PdfSharp.Drawing.Layout.XTextFormatter(_graphics);
         _pageCount++;
         _isPageEmpty = true;
     }
 }
Ejemplo n.º 15
0
        public static void ReadPdf()
        {
            // Get a fresh copy of the sample PDF file
            string filename = @"C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\R_SERVICES\doc\manual\R-intro.pdf";

            // Create the output document
            PdfSharp.Pdf.PdfDocument outputDocument =
                new PdfSharp.Pdf.PdfDocument();

            // Show single pages
            // (Note: one page contains two pages from the source document)
            outputDocument.PageLayout = PdfSharp.Pdf.PdfPageLayout.SinglePage;

            /*
             * PdfSharp.Drawing.XFont font =
             *  new PdfSharp.Drawing.XFont("Verdana", 8, PdfSharp.Drawing.XFontStyle.Bold);
             * PdfSharp.Drawing.XStringFormat format = new PdfSharp.Drawing.XStringFormat();
             * format.Alignment = PdfSharp.Drawing.XStringAlignment.Center;
             * format.LineAlignment = PdfSharp.Drawing.XLineAlignment.Far;
             */
            PdfSharp.Drawing.XGraphics gfx;
            PdfSharp.Drawing.XRect     box;

            // Open the external document as XPdfForm object
            PdfSharp.Drawing.XPdfForm form =
                PdfSharp.Drawing.XPdfForm.FromFile(filename);

            for (int idx = 0; idx < form.PageCount; idx += 2)
            {
                // Add a new page to the output document
                PdfSharp.Pdf.PdfPage page = outputDocument.AddPage();
                page.Orientation = PdfSharp.PageOrientation.Landscape;
                double width  = page.Width;
                double height = page.Height;

                int rotate = page.Elements.GetInteger("/Rotate");

                gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);

                // Set page number (which is one-based)
                form.PageNumber = idx + 1;

                box = new PdfSharp.Drawing.XRect(0, 0, width / 2, height);
                // Draw the page identified by the page number like an image
                gfx.DrawImage(form, box);


                // Write document file name and page number on each page
                box.Inflate(0, -10);

                /*
                 * gfx.DrawString(string.Format("- {1} -", filename, idx + 1),
                 *   font, PdfSharp.Drawing.XBrushes.Red, box, format);
                 */
                if (idx + 1 < form.PageCount)
                {
                    // Set page number (which is one-based)
                    form.PageNumber = idx + 2;

                    box = new PdfSharp.Drawing.XRect(width / 2, 0, width / 2, height);
                    // Draw the page identified by the page number like an image
                    gfx.DrawImage(form, box);

                    // Write document file name and page number on each page
                    box.Inflate(0, -10);

                    /*
                     * gfx.DrawString(string.Format("- {1} -", filename, idx + 2),
                     *  font, PdfSharp.Drawing.XBrushes.Red, box, format);
                     */
                }
            }

            // Save the document...
            filename = "TwoPagesOnOne_tempfile.pdf";
            outputDocument.Save(filename);
            // ...and start a viewer.
            System.Diagnostics.Process.Start(filename);
        }
Ejemplo n.º 16
0
        }     // End Sub CropPdf2

        static void CropPdf3(double page_width, double page_height)
        {
            string fn = @"D:\username\Desktop\0001 Altstetten - GB01 H602 - OG14.pdf";

            // fn = @"D:\username\Desktop\0030 Sentimatt - GB01 Sentimatt - EG00.pdf";
            fn = @"D:\username\Desktop\Altstetten_1_50.pdf";


            // The current implementation of PDFsharp has only one layout of the graphics context.
            // The origin(0, 0) is top left and coordinates grow right and down.
            // The unit of measure is always point (1 / 72 inch).

            // 1 pt = 0,0352778 cm
            // 1 pt = 0,352778 mm
            // 1 inch = 2,54 cm
            // 1/72 inch to cm = 0,035277777777777776 cm


            // A0:
            // w: 2384 pt =  84,10222 cm
            // h: 3370 pt = 118,8861  cm

            // A3:
            // w:  842 pt = 29,7039  cm
            // h: 1191 pt = 42,01583 cm

            // A4:
            // 595 pt to cm = 20,9903 w
            // 842 pt to cm = 29,7039 h



            // A0
            page_width  = 2384;
            page_height = 3370;

            // A3
            page_width  = 842;
            page_height = 1191;

            // A4
            page_width  = 595;
            page_height = 842;

            PdfMargin margin = new PdfMargin(mm2pt(10)); // 1cm in pt


            double crop_width  = page_width - margin.Left - margin.Right;
            double crop_height = page_height - margin.Top - margin.Bottom;


            using (PdfSharp.Drawing.XPdfForm sourceForm = PdfSharp.Drawing.XPdfForm.FromFile(fn))
            {
                sourceForm.PageNumber = 1;
                int numHori  = (int)System.Math.Ceiling(sourceForm.Page.Width.Point / crop_width);
                int numVerti = (int)System.Math.Ceiling(sourceForm.Page.Height.Point / crop_height);

                PdfSharp.Drawing.XRect pageDimenstions = new PdfSharp.Drawing.XRect(0, 0, sourceForm.Page.Width, sourceForm.Page.Height);

                using (PdfSharp.Pdf.PdfDocument destDocument = new PdfSharp.Pdf.PdfDocument())
                {
                    for (int iverti = 0; iverti < numVerti; iverti++)
                    {
                        for (int ihori = 0; ihori < numHori; ihori++)
                        {
                            PdfSharp.Pdf.PdfPage destPage = destDocument.AddPage();
                            destPage.Width  = crop_width;
                            destPage.Height = crop_height;

                            PdfSharp.Drawing.XRect cropRect = new PdfSharp.Drawing.XRect(ihori * crop_width, iverti * crop_height, sourceForm.Page.Width, sourceForm.Page.Height);

                            using (PdfSharp.Drawing.XGraphics destGFX = PdfSharp.Drawing.XGraphics.FromPdfPage(destPage))
                            {
                                destGFX.DrawImageCropped(sourceForm, cropRect, pageDimenstions, PdfSharp.Drawing.XGraphicsUnit.Point);
                            } // End Using destGFX
                        }     // ihori
                    }         // iverti

                    // destDocument.Save("chopped.pdf");

                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        destDocument.Save(ms);
                        ms.Position = 0;

                        using (PdfSharp.Drawing.XPdfForm croppedImages = PdfSharp.Drawing.XPdfForm.FromStream(ms))
                        {
                            using (PdfSharp.Pdf.PdfDocument finalDestination = new PdfSharp.Pdf.PdfDocument())
                            {
                                PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Arial", 8);

                                for (int i = 0; i < croppedImages.PageCount; ++i)
                                {
                                    PdfSharp.Pdf.PdfPage targetPage = finalDestination.AddPage();
                                    targetPage.Width  = page_width;
                                    targetPage.Height = page_height;

                                    PdfSharp.Drawing.XRect pageSize = new PdfSharp.Drawing.XRect(0, 0, targetPage.Width, targetPage.Height);

                                    try
                                    {
                                        croppedImages.PageIndex = i;

                                        using (PdfSharp.Drawing.XGraphics targetGFX = PdfSharp.Drawing.XGraphics.FromPdfPage(targetPage))
                                        {
#if DEBUG_ME
                                            targetGFX.DrawRectangle(XBrushes.Honeydew, pageSize);
#endif

                                            PdfSharp.Drawing.XRect targetRect = new PdfSharp.Drawing.XRect(margin.Left, margin.Top, crop_width, crop_height);

                                            targetGFX.DrawImage(croppedImages, targetRect, targetRect, PdfSharp.Drawing.XGraphicsUnit.Point);

                                            DrawBorder(targetGFX, targetPage.Width.Point, targetPage.Height.Point, margin);
                                            DrawCrosshairs(targetGFX, targetPage.Width.Point, targetPage.Height.Point, margin);

                                            // int numHori = (int)System.Math.Ceiling(sourceForm.Page.Width / crop_width);
                                            // int numVerti = (int)System.Math.Ceiling(sourceForm.Page.Height / crop_height);

                                            int col = i % numHori;
                                            int row = i / numHori;

                                            // targetGFX.DrawString($"Column {col + 1}/{numHori} Row {row + 1}/{numVerti}, Page {i + 1}/{croppedImages.PageCount}", font, PdfSharp.Drawing.XBrushes.Black, margin.Left + 5, targetPage.Height.Point - margin.Bottom + font.Size + 5);
                                            targetGFX.DrawString($"Spalte {col + 1}/{numHori} Zeile {row + 1}/{numVerti}, Seite {i + 1}/{croppedImages.PageCount}", font, PdfSharp.Drawing.XBrushes.Black, margin.Left + 5, targetPage.Height.Point - margin.Bottom + font.Size + 5);
                                        } // End using targetGFX
                                    }
                                    catch (System.Exception ex)
                                    {
                                        System.Console.WriteLine(croppedImages.PageIndex);
                                        System.Console.WriteLine(ex.Message);
                                    }
                                } // Next i

                                finalDestination.Save("CropPdf3.pdf");
                            } // End Using finalDestination
                        }     // End Using croppedImages
                    }         // End Using ms
                }             // End Using destDocument
            }                 // End Using sourceForm
        }                     // End Sub CropPdf3
Ejemplo n.º 17
0
        private void PaitentFinances_Click(object sender, EventArgs e)
        {
            int PID;
            try {
                PID = Convert.ToInt32(PatientBox.Text);
            }
            catch {
                PID = -1;
                PatientBox.Text = "Number Reqired";
            }

            if (PID > -1) {
                MiddleWare.middle.OpenConnection();

                SqlCommand GetData = new SqlCommand(string.Format("select FirstName, LastName from Patients WHERE PatientID='{0}';", PID), MiddleWare.middle.dbConnection);
                SqlDataReader dataReader = GetData.ExecuteReader();
                if (dataReader.HasRows) {
                    dataReader.Read();
                    String name = dataReader.GetString(0) + " " + dataReader.GetString(1);
                    MiddleWare.middle.CloseConnection();

                    MiddleWare.middle.OpenConnection();
                    String feeID = "";
                    String grossCost = "";
                    String DiscountedCost = "";
                    int totalCost = 0;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    GetData = new SqlCommand(string.Format("SELECT Treatment.PatientID, Fees.FeeID, Fees.GrossCost, Fees.TotalCost FROM Treatment INNER JOIN Fees ON Treatment.FeeID = Fees.FeeID WHERE Treatment.PatientID = '{0}'", PID), MiddleWare.middle.dbConnection);
                    adapter.SelectCommand = GetData;
                    adapter.Fill(ds);

                    MiddleWare.middle.CloseConnection();

                    string printString;
                    PdfSharp.Pdf.PdfDocument PDFDocument = new PdfSharp.Pdf.PdfDocument();
                    PDFDocument.Info.Title = "Patient Invoice";
                    PdfSharp.Pdf.PdfPage PDFPage = PDFDocument.AddPage();
                    PdfSharp.Drawing.XGraphics PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);
                    PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Verdana", 12, PdfSharp.Drawing.XFontStyle.Bold);
                    PdfSharp.Drawing.XRect rec = new PdfSharp.Drawing.XRect((PDFPage.Width / 8), 110, PDFPage.Width, PDFPage.Height);
                    // 0 - 90 banner
                    PDFGraphics.DrawString("Q Medic Hospital Banner Goes Here", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect((PDFPage.Width / 4), 50, PDFPage.Width, PDFPage.Height), PdfSharp.Drawing.XStringFormats.TopLeft);

                    printString = "Patient ID: " + PID;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    rec.X = (PDFPage.Width / 8) + 20;

                    printString = "Name: " + name;
                    rec.Y = 150;
                    PDFGraphics.DrawString(printString, font, PdfSharp.Drawing.XBrushes.Black, rec, PdfSharp.Drawing.XStringFormats.TopLeft);
                    int yPoint = 220;

                    PDFGraphics.DrawString("Invoice Number", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("Gross Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(180, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("Discounted Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("TotalCost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    yPoint = 250;
                    for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    if (yPoint > 820) {
                        yPoint = 50;
                        PDFPage = PDFDocument.AddPage();
                        PDFGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(PDFPage);

                        PDFGraphics.DrawString("Invoice Number", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        PDFGraphics.DrawString("Gross Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(180, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        PDFGraphics.DrawString("Discounted Cost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                        PDFGraphics.DrawString("TotalCost", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                        yPoint = 70;
                    }
                    feeID = ds.Tables[0].Rows[i].ItemArray[1].ToString ();
                    grossCost = ds.Tables[0].Rows[i].ItemArray[2].ToString();
                    DiscountedCost = ds.Tables[0].Rows[i].ItemArray[3].ToString();

                    PDFGraphics.DrawString(feeID, font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(40, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("$"+grossCost+".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(180, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    PDFGraphics.DrawString("$"+DiscountedCost+".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(300, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    try {
                        totalCost += Convert.ToInt32(DiscountedCost);
                        PDFGraphics.DrawString("$" + totalCost + ".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    }
                    catch {
                        PDFGraphics.DrawString("NaN", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    }
                        yPoint = yPoint + 20;
                }
                    yPoint += 40;
                    PDFGraphics.DrawString("Grand Total: ", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(320, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);
                    PDFGraphics.DrawString("$" + totalCost+".00", font, PdfSharp.Drawing.XBrushes.Black, new PdfSharp.Drawing.XRect(420, yPoint, PDFPage.Width.Point, PDFPage.Height.Point), PdfSharp.Drawing.XStringFormats.TopLeft);

                    String filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HospitalExport\\" +  PID + "_PaitentStatement.pdf";
                    PDFDocument.Save(filename);
                }
            }
            // finances for patient
        }