コード例 #1
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);
            }
        }
コード例 #2
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"));
            }
        }
コード例 #3
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);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        public virtual void ShowTextAlignedTest01()
        {
            String      outFileName = destinationFolder + "showTextAlignedTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_showTextAlignedTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDocument);

            pdfDocument.AddNewPage();
            PdfCanvas canvas = new PdfCanvas(pdfDocument.GetLastPage());
            String    text   = "textapqgaPQGatext";
            float     width  = 200;
            float     x;
            float     y;

            y = 700;
            x = 115;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.BOTTOM, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 * 1
                                                                                                       ));
            x = 300;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.MIDDLE, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 * 3
                                                                                                       ));
            x = 485;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.TOP, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.LEFT, VerticalAlignment.TOP, (float)(Math.PI / 6 * 5));
            y = 400;
            x = 115;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 *
                                                                                                         2));
            x = 300;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 *
                                                                                                         4));
            x = 485;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.CENTER, VerticalAlignment.TOP, (float)(Math.PI / 6 * 8)
                                     );
            y = 100;
            x = 115;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, (float)(Math.PI / 6 *
                                                                                                        9));
            x = 300;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, (float)(Math.PI / 6 *
                                                                                                        7));
            x = 485;
            DrawCross(canvas, x, y);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.TOP, 0);
            document.ShowTextAligned(text, x, y, TextAlignment.RIGHT, VerticalAlignment.TOP, (float)(Math.PI / 6 * 6));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
コード例 #6
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        private void ElementOpacityTest(String elem)
        {
            String      outFileName     = destinationFolder + elem + "ElementOpacity01.pdf";
            String      cmpFileName     = sourceFolder + "cmp_" + elem + "ElementOpacity01.pdf";
            PdfDocument pdfDocument     = new PdfDocument(new PdfWriter(outFileName));
            Document    document        = new Document(pdfDocument);
            DeviceRgb   divBackground   = WebColors.GetRGBColor("#82abd6");
            DeviceRgb   paraBackground  = WebColors.GetRGBColor("#994ec7");
            DeviceRgb   textBackground  = WebColors.GetRGBColor("#009688");
            DeviceRgb   tableBackground = WebColors.GetRGBColor("#ffc107");

            document.SetFontColor(ColorConstants.WHITE);
            Div div = new Div().SetBackgroundColor(divBackground);

            if ("div".Equals(elem))
            {
                div.SetOpacity(0.3f);
            }
            div.Add(new Paragraph("direct div content"));
            Paragraph p = new Paragraph("direct paragraph content").SetBackgroundColor(paraBackground);

            if ("para".Equals(elem))
            {
                p.SetOpacity(0.3f);
            }
            Text text = new Text("text content").SetBackgroundColor(textBackground);

            p.Add(text);
            if ("text".Equals(elem))
            {
                text.SetOpacity(0.3f);
            }
            div.Add(p);
            iText.Layout.Element.Image image = new Image(ImageDataFactory.Create(sourceFolder + "itis.jpg"));
            div.Add(image);
            if ("image".Equals(elem))
            {
                image.SetOpacity(0.3f);
            }
            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth().SetBackgroundColor(tableBackground
                                                                                                               );

            table.AddCell("Cell00");
            table.AddCell("Cell01");
            Cell cell10 = new Cell().Add(new Paragraph("Cell10"));

            if ("cell".Equals(elem))
            {
                cell10.SetOpacity(0.3f);
            }
            table.AddCell(cell10);
            table.AddCell(new Cell().Add(new Paragraph("Cell11")));
            if ("table".Equals(elem))
            {
                table.SetOpacity(0.3f);
            }
            div.Add(table);
            List list = new List();

            if ("list".Equals(elem))
            {
                list.SetOpacity(0.3f);
            }
            ListItem listItem = new ListItem("item 0");

            list.Add(listItem);
            if ("listItem".Equals(elem))
            {
                listItem.SetOpacity(0.3f);
            }
            list.Add("item 1");
            div.Add(list);
            document.Add(div);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
コード例 #7
0
ファイル: ListTest.cs プロジェクト: zymemail/itext7-dotnet
        public virtual void ListWithSetHeightProperties01()
        {
            String      outFileName = destinationFolder + "listWithSetHeightProperties01.pdf";
            String      cmpFileName = sourceFolder + "cmp_listWithSetHeightProperties01.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc);

            doc.Add(new Paragraph("Default layout:"));
            ListItem item             = new ListItem();
            ListItem nestedItem       = new ListItem();
            List     list             = new List(ListNumberingType.DECIMAL);
            List     nestedList       = new List(ListNumberingType.ENGLISH_UPPER);
            List     nestedNestedList = new List(ListNumberingType.GREEK_LOWER);

            nestedNestedList.Add("Hello");
            nestedNestedList.Add("World");
            nestedItem.Add(nestedNestedList);
            nestedList.Add(nestedItem);
            nestedList.Add(nestedItem);
            item.Add(nestedList);
            list.Add(item);
            list.Add(item);
            list.SetBorder(new SolidBorder(ColorConstants.RED, 3));
            doc.Add(list);
            doc.Add(new AreaBreak());
            doc.Add(new Paragraph("List's height is set shorter than needed:"));
            list.SetHeight(50);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("List's min height is set shorter than needed:"));
            list.SetMinHeight(50);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("List's max height is set shorter than needed:"));
            list.SetMaxHeight(50);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("List's height is set bigger than needed:"));
            list.SetHeight(1300);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("List's min height is set bigger than needed:"));
            list.SetMinHeight(1300);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("List's max height is set bigger than needed:"));
            list.SetMaxHeight(1300);
            doc.Add(list);
            doc.Add(new AreaBreak());
            list.DeleteOwnProperty(Property.HEIGHT);
            list.DeleteOwnProperty(Property.MIN_HEIGHT);
            list.DeleteOwnProperty(Property.MAX_HEIGHT);
            doc.Add(new Paragraph("Some list items' and nested lists' heights are set bigger or shorter than needed:")
                    );
            nestedList.SetHeight(400);
            nestedItem.SetHeight(300);
            doc.Add(list);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }