コード例 #1
0
ファイル: Form1.cs プロジェクト: Antoha2020/OrderOptimization
        private void RouteListPdf(Master master)
        {
            string strPdf = DateTime.Now.ToString("dd.MM.yyyy HH:mm") + "\n" + master.Name + "\nМаршрутный лист на " + dateTimePicker1.Value.ToShortDateString() + "\n";

            strPdf += "---------------------------------------------\n";
            for (int i = 0; i < master.myOrders.Count; i++)
            {
                string intercom = master.myOrders[i].Intercom?"есть":"нет";

                strPdf += (i + 1).ToString() + "  " + master.myOrders[i].Name + "  " + master.myOrders[i].TimeBeg + "  " +
                          master.myOrders[i].City + ", " + master.myOrders[i].Street + " д." + master.myOrders[i].House + ", кв." +
                          master.myOrders[i].Flat + " (оф." + master.myOrders[i].Office + "), под." + master.myOrders[i].Porch + ", эт." +
                          master.myOrders[i].Floor + ", домофон " + intercom + ", тел.1:" + master.myOrders[i].Phone1 + ", тел.2:" +
                          master.myOrders[i].Phone2 + "   " + master.myOrders[i].Description + "\n";
            }
            saveFileDialog1.Filter = "Формат .PDF (*.pdf)|*.pdf|Все файлы (*.*)|*.*";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //using (PdfWriter pdfWriter = new PdfWriter(Constants.MASTERS[0].Name+"_"+dateTimePicker1.Value.ToShortDateString()+".pdf"))
                using (PdfWriter pdfWriter = new PdfWriter(saveFileDialog1.FileName))
                    using (PdfDocument pdfDocument = new PdfDocument(pdfWriter))
                        using (Document document = new Document(pdfDocument))
                        {
                            PdfFont f2 = PdfFontFactory.CreateFont(FONT, "Identity-H", true);
                            document.Add(new Paragraph(strPdf).SetFont(f2));
                        }
            }
        }
コード例 #2
0
 /// <summary>
 /// 字符串对象写入
 /// </summary>
 /// <param name="document">itext Document对象</param>
 /// <param name="contentEntity">内容对象</param>
 /// <returns>itext Document对象</returns>
 public static iText.Layout.Document Write <T>(this iText.Layout.Document document, T content)
     where T : IPDFBlockElement, IContentEntity
 {
     if (content == null)
     {
         return(document);
     }
     document.Add(content.CreateBlock());
     return(document);
 }
コード例 #3
0
        /// <summary>
        /// Prompts the user with a requested save location for the to-be-generated PDF
        /// Iterates through all elements inside of relevant lists to create the required number of labels inside
        /// of the PDF document, separated by pages.
        /// </summary>
        /// <param name="lstArkSerials">List of strings, representative of the entered ARK serial numbers</param>
        /// <param name="lstInjectorSerials">List of strings, representative of the entered Injector serial numbers</param>
        public void saveLabels(List <string> lstArkSerials, List <string> lstInjectorSerials)
        {
            try
            {
                using (PdfWriter outWriter = new PdfWriter(fm.choseDirectory() + "/Smart-i-" + DateTime.UtcNow.ToString("MM-dd-yyyy") + ".pdf"))
                {
                    bool multipleCopies = false;

                    PdfDocument outPDF = new PdfDocument(outWriter);

                    //Set to this size because an internet wizard said that it is 1 inch per 72 user units.
                    //I have no idea where this number comes from but it makes something printable for 3"x3"
                    iText.Kernel.Geom.Rectangle labelSize   = new iText.Kernel.Geom.Rectangle(0, 0, 216, 216);
                    iText.Layout.Document       outDocument = new iText.Layout.Document(outPDF, new PageSize(labelSize));

                    if (Settings.Default.copies > 1)
                    {
                        multipleCopies = true;
                    }

                    for (int i = 0; i < lstArkSerials.Count(); i++)
                    {
                        for (int j = 1; j <= Settings.Default.copies; j++)
                        {
                            createLabel(outDocument, outPDF, lstArkSerials.ElementAt(i), lstInjectorSerials.ElementAt(i), multipleCopies, j, Settings.Default.copies);
                        }
                    }

                    outDocument.Close();
                    outPDF.Close();
                    outWriter.Close();

                    MessageBox.Show("Your file was successfully exported in your chosen directory as 'Smart-i-" + DateTime.UtcNow.ToString("MM-dd-yyyy") + ".pdf'", "Success!", MessageBoxButtons.OK);
                }
            }
            catch (System.IO.IOException)
            {
                MessageBox.Show("An unexcected error occured when trying to save the file in that location. Is there already a file" +
                                " with that name open and in use? Does the selected directory exist? Do you have permissions to save inside of it?" +
                                "\nPlease try again.",
                                "Unexected Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.InvalidOperationException)
            {
                MessageBox.Show("Export was cancelled. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #4
0
        public FileResult CreatePDF()
        {
            string[] urlLinks = new string[12];
            urlLinks = (string[])Request.Form["urls"].Split(',');
            string filepath = "E:\\demo.pdf";

            if (urlLinks[0].Length > 10)
            {
                System.Drawing.Image img = getOnineImage(urlLinks[0]);

                PdfWriter             pdfwriter = new PdfWriter(filepath);
                PdfDocument           pdf       = new PdfDocument(pdfwriter);
                iText.Layout.Document document  = new iText.Layout.Document(pdf, PageSize.A4);
                PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
                document.Add(new Paragraph("This pdf is created by gongjing457!")).Add(new Image(ImageDataFactory.Create(img, System.Drawing.Color.White))).SetFont(font);
                document.Close();
                return(File(new FileStream(filepath, FileMode.Open), "application/pdf", "demo"));
            }
            else
            {
                return(File(new FileStream(filepath, FileMode.Open), "application/pdf", "demo"));
            }
        }
コード例 #5
0
        private bool BuildAstroCharts(string strAstroData, string strPDFFile, ref string strErrorMessage)
        {
            bool        bResult = false;
            string      strData = "";
            astroPerson apObj   = new astroPerson();

            PdfWriter   pdfWriterObj = null;
            PdfDocument pdfDoc       = null;

            iText.Layout.Document docObj = null;

            try
            {
                strErrorMessage = "";

                #region Data File Processing
                pdfWriterObj = new PdfWriter(strPDFFile);
                pdfDoc       = new PdfDocument(pdfWriterObj);
                pdfDoc.SetDefaultPageSize(PageSize.A4);
                pdfDoc.GetCatalog().SetPageLayout(PdfName.SinglePage);
                docObj = new iText.Layout.Document(pdfDoc);

                string[] strFileLineElements = strAstroData.Split('|');

                if (strFileLineElements.Length != 9)
                {
                    strErrorMessage = string.Format("Invalid record found in data\r\nRecord:" + strAstroData);
                    return(false);
                }

                apObj.Clear();

                apObj.Name          = strFileLineElements[0].Trim();
                apObj.Sex           = strFileLineElements[1].Trim();
                apObj.BirthDateTime = DateTime.Parse(strFileLineElements[2].Trim().Replace(".", ":"), CultureInfo.CreateSpecificCulture("ta-IN"), DateTimeStyles.None);

                strData             = strFileLineElements[3].Trim();
                apObj.TimeZoneValue = strData;
                int nTZHours   = Convert.ToInt32(strData.Substring(1, 2));
                int nTZMinutes = Convert.ToInt32(strData.Substring(4, 2));
                if (strData[0] == '-')
                {
                    apObj.TimeZoneDifference -= TimeSpan.Parse(string.Format("0.{0}:{1}:00", nTZHours, nTZMinutes));
                }
                else
                {
                    apObj.TimeZoneDifference += TimeSpan.Parse(string.Format("0.{0}:{1}:00", nTZHours, nTZMinutes));
                }

                apObj.PlaceOfBirth = strFileLineElements[4].Trim();

                strData         = strFileLineElements[5].Trim();
                apObj.Longitude = strData;
                string x = strData.Substring(5, 3);
                apObj.LongitudeDegrees = Convert.ToInt32(strData.Substring(5, 3));
                apObj.LongitudeMinutes = Convert.ToInt32(strData.Substring(9, 2));
                if (strData.Substring(0, 4) == "WEST")
                {
                    apObj.LongitudeDegrees *= -1;
                    apObj.LongitudeMinutes *= -1;
                }

                strData               = strFileLineElements[6].Trim();
                apObj.Latitude        = strData;
                apObj.LatitudeDegrees = Convert.ToInt32(strData.Substring(6, 2));
                apObj.LatitudeMinutes = Convert.ToInt32(strData.Substring(9, 2));
                if (strData.Substring(0, 5) == "SOUTH")
                {
                    apObj.LatitudeDegrees *= -1;
                    apObj.LatitudeMinutes *= -1;
                }

                apObj.TimeZoneName   = strFileLineElements[7].Trim();
                apObj.HourCorrection = Convert.ToInt32(strFileLineElements[8].Trim());

                apObj.BirthDateTimeUTC = apObj.BirthDateTime + apObj.TimeZoneDifference;
                if (apObj.HourCorrection > 0)
                {
                    apObj.BirthDateTimeUTC -= new TimeSpan(apObj.HourCorrection, 0, 0);
                }

                astroChart acObj = new astroChart();

                astroChart.SwissPath                = m_strSWEParentFolder;
                astroChart.SWEConFilePath           = m_strSWEConFilePath;
                astroChart.SWEFolderPath            = m_strSWEFolderPath;
                astroChart.HousingSystem            = "P";
                astroChart.PrintAyanamsaCalculation = 0;
                astroChart.PrintAstroTables         = 0;
                astroChart.PrintDasaTables          = 1;

                if (acObj.AstroSwissEphemerisService(ref apObj, m_nAyanamsa, ref docObj, ref strErrorMessage) == true)
                {
                    bResult = true;
                }
                else
                {
                    bResult = false;
                }

                return(bResult);

                #endregion
            }
            catch (Exception ex)
            {
                strErrorMessage = ex.Message;
            }
            finally
            {
                if (docObj != null)
                {
                    docObj.Close();
                }
                docObj       = null;
                pdfWriterObj = null;
                pdfDoc       = null;
            }

            return(false);
        }
コード例 #6
0
        public bool CreateVMDasaChart(ref iText.Layout.Document pdfDocObj, DateTime dtDasaStartDate, string strDasaLord, ref string errorMessage)
        {
            try
            {
                CalculateVMDasa(dtDasaStartDate, strDasaLord);

                float   PdfDefaultFontSize = 10.0f;
                float[] columnHouses       = { 4f, 4f, 4f, 4f, 4f, 4f };

                iText.Layout.Element.Table vmDasaTable = new iText.Layout.Element.Table(UnitValue.CreatePercentArray(columnHouses)).UseAllAvailableWidth();

                int  nLineNumber = 0;
                bool bPrintTitle = true;
                for (int nDasaEntry = 1; nDasaEntry <= DasaList.Count; nDasaEntry++)
                {
                    if (nDasaEntry >= 729)
                    {
                        break;
                    }

                    if (bPrintTitle == true)
                    {
                        if (((vmDasaElement)DasaList[nDasaEntry]).DasaBeginning == true)
                        {
                            int      nDasaPlanetIndex = GetDasaPlanetIndex(((vmDasaElement)DasaList[nDasaEntry]).DasaLord);
                            DateTime dtVMDasaEndDate  = ((vmDasaElement)DasaList[nDasaEntry]).dtStartDate;
                            dtVMDasaEndDate = dtVMDasaEndDate.AddYears(DasaYears[nDasaPlanetIndex]);
                            string strVMDasaTitle = string.Format("{0} Dasa from {1} to {2} (Anthara Ending Dates)", GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry]).DasaLord), ((vmDasaElement)DasaList[nDasaEntry]).dtStartDate.ToString("dd-MM-yyyy"), dtVMDasaEndDate.ToString("dd-MM-yyyy"));
                            vmDasaTable.AddCell(new Cell(1, 6).SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(strVMDasaTitle).SetFont(PdfFontBoldObj).SetFontSize(PdfDefaultFontSize)).SetBackgroundColor(new DeviceRgb(180, 230, 99)));
                        }

                        vmDasaTable.AddCell(new Cell(1, 2).SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry]).BukthiLord) + " Bukthi").SetFont(PdfFontBoldObj).SetFontSize(PdfDefaultFontSize)));
                        vmDasaTable.AddCell(new Cell(1, 2).SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry + 9]).BukthiLord) + " Bukthi").SetFont(PdfFontBoldObj).SetFontSize(PdfDefaultFontSize)));
                        vmDasaTable.AddCell(new Cell(1, 2).SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry + 18]).BukthiLord) + " Bukthi").SetFont(PdfFontBoldObj).SetFontSize(PdfDefaultFontSize)));
                        nLineNumber++;
                        bPrintTitle = false;
                    }

                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry]).AntharaLord)).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));
                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(((vmDasaElement)DasaList[nDasaEntry]).EndDate).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));

                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry + 9]).AntharaLord)).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));
                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(((vmDasaElement)DasaList[nDasaEntry + 9]).EndDate).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));

                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(GetDasaPlanetName(((vmDasaElement)DasaList[nDasaEntry + 18]).AntharaLord)).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));
                    vmDasaTable.AddCell(new Cell().SetHeight(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE).Add(new Paragraph(((vmDasaElement)DasaList[nDasaEntry + 18]).EndDate).SetFont(PdfFontObj).SetFontSize(PdfDefaultFontSize)));
                    nLineNumber++;

                    if ((nDasaEntry + 18) % 27 == 0)
                    {
                        nDasaEntry  = nDasaEntry + 18;
                        bPrintTitle = true;
                    }
                }

                pdfDocObj.Add(vmDasaTable);

                return(true);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            return(false);
        }
コード例 #7
0
        public void printLabels(List <string> lstArkSerials, List <string> lstInjectorSerials)
        {
            try
            {
                using (var stream = new MemoryStream())
                {
                    using (PdfWriter outWriter = new PdfWriter(stream))
                    {
                        bool        multipleCopies = false;
                        PdfDocument outPDF         = new PdfDocument(outWriter);

                        //Set to this size because an internet wizard said that it is 1 inch per 72 user units.
                        //I have no idea where this number comes from but it makes something printable for 3"x3"
                        iText.Kernel.Geom.Rectangle labelSize   = new iText.Kernel.Geom.Rectangle(0, 0, 216, 216);
                        iText.Layout.Document       outDocument = new iText.Layout.Document(outPDF, new PageSize(labelSize));

                        if (Settings.Default.copies > 1)
                        {
                            multipleCopies = true;
                        }

                        for (int i = 0; i < lstArkSerials.Count(); i++)
                        {
                            for (int j = 1; j <= Settings.Default.copies; j++)
                            {
                                createLabel(outDocument, outPDF, lstArkSerials.ElementAt(i), lstInjectorSerials.ElementAt(i), multipleCopies, j, Settings.Default.copies);
                            }
                        }

                        outDocument.Close();
                        outPDF.Close();
                        outWriter.Close();

                        byte[] bytes = stream.ToArray();

                        using (var outStream = new MemoryStream(bytes))
                        {
                            using (var document = PdfiumViewer.PdfDocument.Load(outStream))
                            {
                                using (var printDocument = document.CreatePrintDocument())
                                {
                                    using (PrintDialog dialog = new PrintDialog())
                                    {
                                        printDocument.PrinterSettings.PrintFileName = "Smart-i-" + DateTime.UtcNow.ToString("MM-dd-yyyy") + ".pdf";
                                        printDocument.DocumentName = "Smart-i-" + DateTime.UtcNow.ToString("MM-dd-yyyy") + ".pdf";
                                        printDocument.PrinterSettings.PrintFileName = "file.pdf";
                                        printDocument.PrintController               = new StandardPrintController();
                                        printDocument.PrinterSettings.MinimumPage   = 1;
                                        printDocument.PrinterSettings.FromPage      = 1;
                                        printDocument.PrinterSettings.ToPage        = document.PageCount;
                                        printDocument.DefaultPageSettings.PaperSize = new PaperSize("3 x 3 inches", 300, 300);
                                        dialog.Document         = printDocument;
                                        dialog.AllowPrintToFile = true;
                                        dialog.AllowSomePages   = true;
                                        if (dialog.ShowDialog() == DialogResult.OK)
                                        {
                                            dialog.Document.Print();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (System.InvalidOperationException)
            {
                MessageBox.Show("Printer job was cancelled. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }