예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            ListItem item      = new ListItem();
            string   startPath = reader.Path;

            do
            {
                reader.Read(); // Read next json token
                if (reader.TokenType == JsonToken.PropertyName)
                {
                    reader.Read(); // read value from property
                    string[] path     = reader.Path.Split(new[] { '.' });
                    string   lastPath = path.LastOrDefault();
                    switch (lastPath)
                    {
                    case "Client":
                        item.Client = (Client)serializer.Deserialize(reader, typeof(Client));
                        break;

                    default:
                        int index = 0;
                        if (int.TryParse(path.LastOrDefault(), out index))
                        {
                            item.Add((Stats)serializer.Deserialize(reader, typeof(Stats)));
                        }
                        break;
                    }
                }
            }while (reader.TokenType != JsonToken.None && !((reader.TokenType == JsonToken.EndObject || reader.TokenType == JsonToken.EndArray) && startPath == reader.Path));

            return(item);
        }
예제 #2
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                var SQL =
                    @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
  FROM film_country c, film_movie_country mc
  WHERE c.id = mc.country_id
  GROUP BY mc.country_id, country ORDER BY c DESC";
                // Create a list for the countries
                List list = new List(List.ORDERED);
                list.First = 9;
                // loop over the countries
                using (var c = AdoDB.Provider.CreateConnection()) {
                    c.ConnectionString = AdoDB.CS;
                    using (DbCommand cmd = c.CreateCommand()) {
                        cmd.CommandText = SQL;
                        c.Open();
                        using (var r = cmd.ExecuteReader()) {
                            while (r.Read())
                            {
                                // create a list item for the country
                                ListItem item = new ListItem(
                                    string.Format("{0}: {1} movies",
                                                  r["country"].ToString(), r["c"].ToString()
                                                  )
                                    );
                                // Create a list for the movies
                                List movielist = new List();
                                movielist.ListSymbol = new Chunk("Movie: ", FilmFonts.BOLD);
                                foreach (Movie movie in
                                         PojoFactory.GetMovies(r["country_id"].ToString())
                                         )
                                {
                                    ListItem movieitem = new ListItem(movie.MovieTitle);
                                    // Create a list for the directors
                                    List directorlist = new ZapfDingbatsList(42);
                                    foreach (Director director in movie.Directors)
                                    {
                                        directorlist.Add(String.Format("{0}, {1}",
                                                                       director.Name, director.GivenName
                                                                       ));
                                    }
                                    movieitem.Add(directorlist);
                                    movielist.Add(movieitem);
                                }
                                item.Add(movielist);
                                list.Add(item);
                            }
                            document.Add(list);
                        }
                    }
                }
            }
        }
예제 #3
0
        public virtual void AddListOnShortPage1()
        {
            String      outFileName      = destinationFolder + "addListOnShortPage1.pdf";
            String      cmpFileName      = sourceFolder + "cmp_addListOnShortPage1.pdf";
            PdfDocument pdfDoc           = new PdfDocument(new PdfWriter(outFileName));
            Document    doc              = new Document(pdfDoc, new PageSize(500, 60));
            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);
            doc.Add(list);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
예제 #4
0
        /* (non-Javadoc)
         * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List)
         */
        public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent)
        {
            IList <IElement> l       = new List <IElement>(1);
            ListItem         li      = new ListItem();
            float            maxSize = -1;

            foreach (IElement e in currentContent)
            {
                li.Add(e);
                //finding max leading among list item elements
                foreach (Chunk chunk in e.Chunks)
                {
                    // here we use 4f/3 multiplied leading value to simulate leading which is used with default font size
                    float currFontSize = chunk.Font.GetCalculatedLeading(4f / 3);
                    if (maxSize < currFontSize)
                    {
                        maxSize = currFontSize;
                    }
                }
            }
            if (li.Leading < maxSize)
            {
                li.Leading = maxSize;
            }
            if (li.Trim())
            {
                l.Add(li); // css applying is handled in the OrderedUnorderedList Class.
            }
            return(l);
        }
예제 #5
0
            public void EatText(string cleanPara, List <IElement> elements)
            {
                if (string.IsNullOrEmpty(cleanPara))
                {
                    return;
                }

                CreateChunk(CurrentChunkFontStyle);
                currentChunk.Append(cleanPara);

                if (currentAnchor != null)
                {
                    currentAnchor.Add(currentChunk);
                }
                else if (currentListItem != null)
                {
                    currentListItem.Add(currentChunk);
                }
                else if (currentParagraph != null)
                {
                    currentParagraph.Add(currentChunk);
                }
                else
                {
                    CreateParagraph(ParaStyle.Body, elements);
                    currentParagraph.Add(currentChunk);
                }
            }
예제 #6
0
        public virtual void ListTest01()
        {
            String          outPdf       = destinationFolder + "pdfA1b_listTest01.pdf";
            String          cmpPdf       = cmpFolder + "cmp_pdfA1b_listTest01.pdf";
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument pdfDocument = new PdfADocument(new PdfWriter(outPdf), PdfAConformanceLevel.PDF_A_1B, outputIntent
                                                        );
            Document doc = new Document(pdfDocument);

            pdfDocument.SetTagged();
            PdfFont textfont = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", PdfEncodings.WINANSI, true);

            textfont.SetSubset(true);
            List     list     = new List();
            ListItem listItem = new ListItem();

            listItem.Add(new Paragraph().Add("foobar"));
            list.Add(listItem);
            listItem.SetFont(textfont);
            doc.Add(list);
            doc.Close();
            String result = new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_");

            if (result != null)
            {
                NUnit.Framework.Assert.Fail(result);
            }
        }
예제 #7
0
        /// <summary>Adds an unlabeled list item.</summary>
        /// <param name="item">the item</param>
        private void AddUnlabeledListItem(IBlockElement item)
        {
            ListItem li = new ListItem();

            li.Add(item);
            li.SetProperty(Property.LIST_SYMBOL, null);
            list.Add(li);
        }
예제 #8
0
 /// <summary>Processes a child.</summary>
 /// <param name="propertyContainer">the property container</param>
 /// <returns>true, if successful</returns>
 private bool ProcessChild(IPropertyContainer propertyContainer)
 {
     inlineHelper.FlushHangingLeaves(listItem);
     if (propertyContainer is Image)
     {
         listItem.Add((Image)propertyContainer);
         return(true);
     }
     else
     {
         if (propertyContainer is IBlockElement)
         {
             listItem.Add((IBlockElement)propertyContainer);
             return(true);
         }
     }
     return(false);
 }
예제 #9
0
 public BudgetItemViewModel()
 {
     if (DesignMode.DesignModeEnabled)
     {
         ListItem.Add(new OneSpendItem {
             Date = new DateDataModel(DateTime.Now), Name = "Comment 1", Sum = 4687, idClass = 0
         });
     }
 }
예제 #10
0
 public void UpdateList(int id)
 {
     SelectedCategoryId = id;
     ListItem.Clear();
     foreach (var el in Model.Spends.Where(o => o.idClass == id))
     {
         ListItem.Add(el);
     }
 }
예제 #11
0
        public IBlockElement CreateBlock()
        {
            List list = new List((iText.Layout.Properties.ListNumberingType)((int)ListType));

            SetFont(Font, list);
            foreach (var item in Content)
            {
                ListItem li = new ListItem();
                foreach (var s in item)
                {
                    if (s is IPDFBlockElement)
                    {
                        li.Add((s as IPDFBlockElement).CreateBlock());
                    }
                    else
                    if (s is IPDFLeafElement)
                    {
                        var image = ((IPDFLeafElement)s).CreateLeaf();
                        if (image is Image)
                        {
                            li.Add((Image)image);
                        }
                        else if (image is AreaBreak)
                        {
                            li.Add((AreaBreak)image);
                        }
                        else
                        {
                            throw new System.Exception("不支持的类型:" + item.GetType().FullName);
                        }
                    }
                    else
                    {
                        throw new System.Exception("不支持的类型:" + item.GetType().FullName);
                    }
                }
                list.Add(li);
            }

            return(list);
        }
예제 #12
0
        /* (non-Javadoc)
         * @see com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, java.util.List)
         */
        public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent)
        {
            IList <IElement> l  = new List <IElement>(1);
            ListItem         li = new ListItem();

            foreach (IElement e in currentContent)
            {
                li.Add(e);
            }
            l.Add(li); // css applying is handled in the OrderedUnorderedList Class.
            return(l);
        }
예제 #13
0
        public virtual void AddListOnShortPage2()
        {
            String      outFileName = destinationFolder + "addListOnShortPage2.pdf";
            String      cmpFileName = sourceFolder + "cmp_addListOnShortPage2.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName)).SetTagged();
            Document    doc         = new Document(pdfDoc, new PageSize(500, 130));
            List        list        = new List(ListNumberingType.DECIMAL);
            ListItem    item        = new ListItem();

            item.Add(new Paragraph("Red"));
            item.Add(new Paragraph("Is"));
            item.Add(new Paragraph("The"));
            item.Add(new Paragraph("Color"));
            item.Add(new Image(ImageDataFactory.Create(sourceFolder + "red.png")));
            List nestedList = new List(ListNumberingType.ENGLISH_UPPER);

            nestedList.Add("Hello");
            nestedList.Add("World");
            item.Add(nestedList);
            for (int i = 0; i < 3; i++)
            {
                list.Add(item);
            }
            doc.Add(list);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
예제 #14
0
 public void AddToCart(ShoppingCartItem item)
 {
     if (ListItem.Where(x => x.ProductName.Equals(item.ProductName)).Any())
     {
         var myItem = ListItem.Single(x => x.ProductName.Equals(item.ProductName));
         myItem.Quanlity += item.Quanlity;
         myItem.Total    += item.Quanlity * Convert.ToDecimal(item.Price);
     }
     else
     {
         ListItem.Add(item);
     }
 }
예제 #15
0
        public virtual void DivInListItemTest01()
        {
            String      outFileName = destinationFolder + "divInListItemTest01.pdf";
            String      cmpFileName = sourceFolder + "cmp_divInListItemTest01.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDocument);
            ListItem    item        = new ListItem();

            item.Add(new Div().Add(new Paragraph("text")));
            document.Add(new List().Add(item));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
예제 #16
0
        // ---------------------------------------------------------------------------

        /**
         * Creates the PDF.
         * @return the bytes of a PDF file.
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (Document document = new Document())
                {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();
                    document.Add(new Paragraph(
                                     "This is a list of Kubrick movies available in DVD stores."
                                     ));
                    IEnumerable <Movie> movies = PojoFactory.GetMovies(1)
                                                 .Concat(PojoFactory.GetMovies(4))
                    ;
                    List   list     = new List();
                    string RESOURCE = Utility.ResourcePosters;
                    foreach (Movie movie in movies)
                    {
                        PdfAnnotation annot = PdfAnnotation.CreateFileAttachment(
                            writer, null,
                            movie.GetMovieTitle(false), null,
                            Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
                            string.Format("{0}.jpg", movie.Imdb)
                            );
                        ListItem item = new ListItem(movie.GetMovieTitle(false));
                        item.Add("\u00a0\u00a0");
                        Chunk chunk = new Chunk("\u00a0\u00a0\u00a0\u00a0");
                        chunk.SetAnnotation(annot);
                        item.Add(chunk);
                        list.Add(item);
                    }
                    document.Add(list);
                }
                return(ms.ToArray());
            }
        }
예제 #17
0
 void vc_CurrentStateChanged(object sender, VisualStateChangedEventArgs e)
 {
     if (IsDragItem)
     {
         return;
     }
     if (e.NewState.Name == "CompressionTop" && firstItem == null)
     {
         //put your code for loading new items here
         CurrItem.Add();
         list.UpdateLayout();
         firstItem = FindVisualChild <ListBoxItem>(list);
         TransformUtil.setScaleX(firstItem, 0.9);
         firstItem.Height = 10;
         TransformUtil.setTranslateX(firstItem, 20.0);
     }
 }
예제 #18
0
        /**
         * Fills a java.util.List with all elements found in currentContent. Places elements that are not a {@link ListItem} or {@link com.itextpdf.text.List} in a new ListItem object.
         *
         * @param currentContent
         * @return java.util.List with only {@link ListItem}s or {@link com.itextpdf.text.List}s in it.
         */
        private IList <IElement> PopulateList(IList <IElement> currentContent)
        {
            IList <IElement> listElements = new List <IElement>();

            foreach (IElement e in currentContent)
            {
                if (e is ListItem || e is List)
                {
                    listElements.Add(e);
                }
                else
                {
                    ListItem listItem = new ListItem();
                    listItem.Add(e);
                    listElements.Add(listItem);
                }
            }
            return(listElements);
        }
예제 #19
0
        public void GetData()
        {
            try
            {
                Connection.Open();

                var strSql = $"SELECT * FROM {TableName.Name}";
                var cmd    = new NpgsqlCommand(strSql, Connection);
                var read   = cmd.ExecuteReader();


                while (read.Read())
                {
                    Object ob = Constructor.Invoke(null);

                    foreach (var item in TableName.GetProperties())
                    {
                        var d = read[item.Name];

                        if (d is System.DBNull)
                        {
                            item.SetValue(ob, null);
                        }

                        else
                        {
                            item.SetValue(ob, d);
                        }
                    }

                    ListItem.Add((T)ob);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Не удалось прочитать данные из таблицы\nОписание: " + e.Message);
            }
            finally
            {
                Connection.Close();
            }
        }
예제 #20
0
        public void UpdateItem(CartItemViewModel cartItem)
        {
            bool isFound = false;

            foreach (var item in ListItem)
            {
                if (item.Id == cartItem.Id)
                {
                    isFound        = true;
                    item.Quantity += cartItem.Quantity;
                }
            }
            if (!isFound)
            {
                ListItem.Add(cartItem);
            }

            Total    += (double)cartItem.GetPriceAfterDiscount() * cartItem.Quantity;
            Quantity += cartItem.Quantity;
        }
예제 #21
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                Image img = Image.GetInstance(IMG_BOX);
                document.Add(img);
                List           list = new List(List.UNORDERED, 20);
                PdfDestination dest = new PdfDestination(PdfDestination.FIT);
                dest.AddFirst(new PdfNumber(1));
                IEnumerable <Movie> box = PojoFactory.GetMovies(1)
                                          .Concat(PojoFactory.GetMovies(4))
                ;
                foreach (Movie movie in box)
                {
                    if (movie.Year > 1960)
                    {
                        PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(
                            writer, null,
                            String.Format("kubrick_{0}.pdf", movie.Imdb),
                            CreateMoviePage(movie)
                            );
                        fs.AddDescription(movie.Title, false);
                        writer.AddFileAttachment(fs);
                        ListItem            item   = new ListItem(movie.MovieTitle);
                        PdfTargetDictionary target = new PdfTargetDictionary(true);
                        target.EmbeddedFileName = movie.Title;
                        PdfAction action = PdfAction.GotoEmbedded(null, target, dest, true);
                        Chunk     chunk  = new Chunk(" (see info)");
                        chunk.SetAction(action);
                        item.Add(chunk);
                        list.Add(item);
                    }
                }
                document.Add(list);
            }
        }
예제 #22
0
파일: VMadd.cs 프로젝트: GaMoEt1/KTPMUD_11
 void UpdateListItem(string AdminName, string tableName, string connectionString)
 {
     ListItem.Clear();
     using (var command = new MySqlCommand())
     {
         var connection = new MySqlConnection(connectionString);
         connection.Open();
         command.Connection  = connection;
         command.CommandText = $@"select * from {tableName} where userAdmin=@userAdmin";
         command.Parameters.AddWithValue("@userAdmin", AdminName);
         var result = command.ExecuteReader();
         if (result.HasRows)
         {
             while (result.Read())
             {
                 ListItem.Add(new Itemz(result));
             }
             result.Close();
         }
         connection.Close();
     }
 }
예제 #23
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                var SQL =
                    @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
FROM film_country c, film_movie_country mc
WHERE c.id = mc.country_id
GROUP BY mc.country_id, country ORDER BY c DESC";
                // Create a new list
                List list = new List(List.ORDERED);
                list.Autoindent   = false;
                list.SymbolIndent = 36;
                // loop over the countries
                using (var c = AdoDB.Provider.CreateConnection()) {
                    c.ConnectionString = AdoDB.CS;
                    using (DbCommand cmd = c.CreateCommand()) {
                        cmd.CommandText = SQL;
                        c.Open();
                        using (var r = cmd.ExecuteReader()) {
                            while (r.Read())
                            {
                                // create a list item for the country
                                ListItem item = new ListItem(
                                    string.Format("{0}: {1} movies",
                                                  r["country"].ToString(), r["c"].ToString()
                                                  )
                                    );
                                item.ListSymbol = new Chunk(r["country_id"].ToString());
                                // Create a list for the movies produced in the current country
                                List movielist = new List(List.ORDERED, List.ALPHABETICAL);
                                movielist.Alignindent = false;

                                foreach (Movie movie in
                                         PojoFactory.GetMovies(r["country_id"].ToString())
                                         )
                                {
                                    ListItem movieitem    = new ListItem(movie.MovieTitle);
                                    List     directorlist = new List(List.ORDERED);
                                    directorlist.PreSymbol  = "Director ";
                                    directorlist.PostSymbol = ": ";
                                    foreach (Director director in movie.Directors)
                                    {
                                        directorlist.Add(String.Format("{0}, {1}",
                                                                       director.Name, director.GivenName
                                                                       ));
                                    }


                                    movieitem.Add(directorlist);
                                    movielist.Add(movieitem);
                                }
                                item.Add(movielist);
                                list.Add(item);
                            }
                            document.Add(list);
                        }
                    }
                }
            }
        }
예제 #24
0
        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"));
        }
예제 #25
0
        public virtual void CreatePdf(String dest)
        {
            //Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            // Initialize document
            PageSize pagesize = PageSize.A6.Rotate();
            Document document = new Document(pdf, pagesize);
            //Set column parameters
            float offSet       = 36;
            float gutter       = 23;
            float columnWidth  = (pagesize.GetWidth() - offSet * 2) / 2 - gutter;
            float columnHeight = pagesize.GetHeight() - offSet * 2;

            //Define column areas
            Rectangle[] columns = new Rectangle[] { new Rectangle(offSet, offSet, columnWidth, columnHeight), new Rectangle
                                                        (offSet + columnWidth + gutter, offSet, columnWidth, columnHeight) };
            document.SetRenderer(new ColumnDocumentRenderer(document, columns));
            List list   = new List();
            List list1  = new List(ListNumberingType.DECIMAL);
            List listEL = new List(ListNumberingType.ENGLISH_LOWER);

            listEL.Add("Dr. Jekyll");
            listEL.Add("Mr. Hyde");
            ListItem liEL = new ListItem();

            liEL.Add(listEL);
            list1.Add(liEL);
            List listEU = new List(ListNumberingType.ENGLISH_UPPER);

            listEU.Add("Dr. Jekyll");
            listEU.Add("Mr. Hyde");
            ListItem liEU = new ListItem();

            liEU.Add(listEU);
            list1.Add(liEU);
            ListItem li1 = new ListItem();

            li1.Add(list1);
            list.Add(li1);
            ListItem li     = new ListItem();
            List     listGL = new List(ListNumberingType.GREEK_LOWER);

            listGL.Add("Dr. Jekyll");
            listGL.Add("Mr. Hyde");
            li.Add(listGL);
            List listGU = new List(ListNumberingType.GREEK_UPPER);

            listGU.Add("Dr. Jekyll");
            listGU.Add("Mr. Hyde");
            li.Add(listGU);
            List listRL = new List(ListNumberingType.ROMAN_LOWER);

            listRL.Add("Dr. Jekyll");
            listRL.Add("Mr. Hyde");
            li.Add(listRL);
            List listRU = new List(ListNumberingType.ROMAN_UPPER);

            listRU.Add("Dr. Jekyll");
            listRU.Add("Mr. Hyde");
            li.Add(listRU);
            list.Add(li);
            List listZ1 = new List(ListNumberingType.ZAPF_DINGBATS_1);

            listZ1.Add("Dr. Jekyll");
            listZ1.Add("Mr. Hyde");
            ListItem liZ1 = new ListItem();

            liZ1.Add(listZ1);
            List listZ2 = new List(ListNumberingType.ZAPF_DINGBATS_2);

            listZ2.Add("Dr. Jekyll");
            listZ2.Add("Mr. Hyde");
            ListItem liZ2 = new ListItem();

            liZ2.Add(listZ2);
            List listZ3 = new List(ListNumberingType.ZAPF_DINGBATS_3);

            listZ3.Add("Dr. Jekyll");
            listZ3.Add("Mr. Hyde");
            ListItem liZ3 = new ListItem();

            liZ3.Add(listZ3);
            List listZ4 = new List(ListNumberingType.ZAPF_DINGBATS_4);

            listZ4.Add("Dr. Jekyll");
            listZ4.Add("Mr. Hyde");
            ListItem liZ4 = new ListItem();

            liZ4.Add(listZ4);
            listZ3.Add(liZ4);
            listZ2.Add(liZ3);
            listZ1.Add(liZ2);
            list.Add(liZ1);
            document.Add(list);
            //Close document
            document.Close();
        }
예제 #26
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();


                // step 4
                PdfCollection       collection = new PdfCollection(PdfCollection.HIDDEN);
                PdfCollectionSchema schema     = _collectionSchema();
                collection.Schema = schema;
                PdfCollectionSort sort = new PdfCollectionSort(KEYS);
                collection.Sort   = sort;
                writer.Collection = collection;

                PdfCollectionItem    collectionitem = new PdfCollectionItem(schema);
                PdfFileSpecification fs             = PdfFileSpecification.FileEmbedded(
                    writer, IMG_KUBRICK, "kubrick.jpg", null
                    );
                fs.AddDescription("Stanley Kubrick", false);
                collectionitem.AddItem(TYPE_FIELD, "JPEG");
                fs.AddCollectionItem(collectionitem);
                writer.AddFileAttachment(fs);

                Image img = Image.GetInstance(IMG_BOX);
                document.Add(img);
                List           list = new List(List.UNORDERED, 20);
                PdfDestination dest = new PdfDestination(PdfDestination.FIT);
                dest.AddFirst(new PdfNumber(1));
                PdfTargetDictionary intermediate;
                PdfTargetDictionary target;
                Chunk     chunk;
                ListItem  item;
                PdfAction action = null;

                IEnumerable <Movie> box = PojoFactory.GetMovies(1)
                                          .Concat(PojoFactory.GetMovies(4))
                ;
                StringBuilder sb = new StringBuilder();
                foreach (Movie movie in box)
                {
                    if (movie.Year > 1960)
                    {
                        sb.AppendLine(String.Format(
                                          "{0};{1};{2}", movie.MovieTitle, movie.Year, movie.Duration
                                          ));
                        item = new ListItem(movie.MovieTitle);
                        if (!"0278736".Equals(movie.Imdb))
                        {
                            target = new PdfTargetDictionary(true);
                            target.EmbeddedFileName          = movie.Title;
                            intermediate                     = new PdfTargetDictionary(true);
                            intermediate.FileAttachmentPage  = 1;
                            intermediate.FileAttachmentIndex = 1;
                            intermediate.AdditionalPath      = target;
                            action = PdfAction.GotoEmbedded(null, intermediate, dest, true);
                            chunk  = new Chunk(" (see info)");
                            chunk.SetAction(action);
                            item.Add(chunk);
                        }
                        list.Add(item);
                    }
                }
                document.Add(list);

                fs = PdfFileSpecification.FileEmbedded(
                    writer, null, "kubrick.txt",
                    Encoding.UTF8.GetBytes(sb.ToString())
                    );
                fs.AddDescription("Kubrick box: the movies", false);
                collectionitem.AddItem(TYPE_FIELD, "TXT");
                fs.AddCollectionItem(collectionitem);
                writer.AddFileAttachment(fs);

                PdfPTable table = new PdfPTable(1);
                table.SpacingAfter = 10;
                PdfPCell cell = new PdfPCell(new Phrase("All movies by Kubrick"));
                cell.Border = PdfPCell.NO_BORDER;
                fs          = PdfFileSpecification.FileEmbedded(
                    writer, null, KubrickMovies.FILENAME,
                    Utility.PdfBytes(new KubrickMovies())
                    //new KubrickMovies().createPdf()
                    );
                collectionitem.AddItem(TYPE_FIELD, "PDF");
                fs.AddCollectionItem(collectionitem);
                target = new PdfTargetDictionary(true);
                target.FileAttachmentPagename = "movies";
                target.FileAttachmentName     = "The movies of Stanley Kubrick";
                cell.CellEvent = new PdfActionEvent(
                    writer, PdfAction.GotoEmbedded(null, target, dest, true)
                    );
                cell.CellEvent = new FileAttachmentEvent(
                    writer, fs, "The movies of Stanley Kubrick"
                    );
                cell.CellEvent = new LocalDestinationEvent(writer, "movies");
                table.AddCell(cell);
                writer.AddFileAttachment(fs);

                cell        = new PdfPCell(new Phrase("Kubrick DVDs"));
                cell.Border = PdfPCell.NO_BORDER;
                fs          = PdfFileSpecification.FileEmbedded(
                    writer, null,
                    KubrickDvds.RESULT, new KubrickDvds().CreatePdf()
                    );
                collectionitem.AddItem(TYPE_FIELD, "PDF");
                fs.AddCollectionItem(collectionitem);
                cell.CellEvent = new FileAttachmentEvent(writer, fs, "Kubrick DVDs");
                table.AddCell(cell);
                writer.AddFileAttachment(fs);

                cell        = new PdfPCell(new Phrase("Kubrick documentary"));
                cell.Border = PdfPCell.NO_BORDER;
                fs          = PdfFileSpecification.FileEmbedded(
                    writer, null,
                    KubrickDocumentary.RESULT, new KubrickDocumentary().CreatePdf()
                    );
                collectionitem.AddItem(TYPE_FIELD, "PDF");
                fs.AddCollectionItem(collectionitem);
                cell.CellEvent = new FileAttachmentEvent(
                    writer, fs, "Kubrick Documentary"
                    );
                table.AddCell(cell);
                writer.AddFileAttachment(fs);

                document.NewPage();
                document.Add(table);
            }
        }
예제 #27
0
        private static List GetList(int[] space, ListLine.ListLineControl value, ref int now)
        {
            List list = new List();

            list.SetListSymbol("       ");
            for (int i = 0; now < space.Length; now++, i++)
            {
                if (i == 0 || space[now] == space[now - 1])
                {
                    ListItem  item   = new ListItem();
                    Paragraph header = new Paragraph();
                    header.Add((value.Controls[now * 2 + 1] as Label).Text);
                    SimpleLines.SimpleLinesControl simpleLines = value.Controls[now * 2] as SimpleLines.SimpleLinesControl;
                    int   y     = 5;
                    Style style = new Style();
                    for (int a = 0; a < simpleLines.Controls.Count; a++)
                    {
                        if (y < simpleLines.Controls[a].Location.Y)
                        {
                            y = simpleLines.Controls[a].Location.Y;
                            header.Add("\r\n");
                        }
                        if (simpleLines.Controls[a].GetType() == typeof(SimpleInLineText.SimpleInLineTextControl))
                        {
                            SimpleInLineText.SimpleInLineTextControl control = simpleLines.Controls[a] as SimpleInLineText.SimpleInLineTextControl;
                            CreateText(control, header);
                        }
                        else
                        {
                            if (simpleLines.Controls[a].GetType() == typeof(Link.LinkControl))
                            {
                                Link.LinkControl control = simpleLines.Controls[a] as Link.LinkControl;
                                CreateLink(item, control, header, false);
                            }
                            else
                            {
                                if (simpleLines.Controls[a].GetType() == typeof(ImageText.ImageTextControl))
                                {
                                    CreateImage(item, simpleLines.Controls[a] as ImageText.ImageTextControl, false, ref header, false, true);
                                }
                                else
                                {
                                    if (simpleLines.Controls[a].GetType() == typeof(Label))
                                    {
                                        CreateCode(simpleLines.Controls[a] as Label, header);
                                    }
                                }
                            }
                        }
                    }
                    item.Add(header);
                    list.Add(item);
                }
                else
                {
                    if (space[now] > space[now - 1])
                    {
                        int      memory = now;
                        ListItem item   = new ListItem();
                        item.Add(GetList(space, value, ref now));
                        if (space[now + 1] == space[memory - 1])
                        {
                            i = -1;
                        }
                        list.Add(item);
                    }
                    else
                    {
                        now--;
                        return(list);
                    }
                }
            }
            return(list);
        }
예제 #28
0
        public Chap0302()
        {
            Console.WriteLine("Chapter 3 example 2: Lists");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter.GetInstance(document, new FileStream("Chap0302.pdf", FileMode.Create));

                // step 3: we Open the document
                document.Open();

                // step 4:

                List list = new List(true, 20);
                list.Add(new ListItem("First line"));
                list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
                list.Add(new ListItem("Third line"));
                document.Add(list);

                document.Add(new Paragraph("some books I really like:"));
                ListItem listItem;
                list     = new List(true, 15);
                listItem = new ListItem("When Harlie was one", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by David Gerrold", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)));
                list.Add(listItem);
                listItem = new ListItem("The World according to Garp", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by John Irving", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)));
                list.Add(listItem);
                listItem = new ListItem("Decamerone", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by Giovanni Boccaccio", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)));
                list.Add(listItem);
                document.Add(list);

                Paragraph paragraph = new Paragraph("some movies I really like:");
                list = new List(false, 10);
                list.Add("Wild At Heart");
                list.Add("Casablanca");
                list.Add("When Harry met Sally");
                list.Add("True Romance");
                list.Add("Le mari de la coiffeuse");
                paragraph.Add(list);
                document.Add(paragraph);

                document.Add(new Paragraph("Some authors I really like:"));
                list            = new List(false, 20);
                list.ListSymbol = new Chunk("\u2022", FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.BOLD));
                listItem        = new ListItem("Isaac Asimov");
                list.Add(listItem);
                List sublist;
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("The Foundation Trilogy");
                sublist.Add("The Complete Robot");
                sublist.Add("Caves of Steel");
                sublist.Add("The Naked Sun");
                list.Add(sublist);
                listItem = new ListItem("John Irving");
                list.Add(listItem);
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("The World according to Garp");
                sublist.Add("Hotel New Hampshire");
                sublist.Add("A prayer for Owen Meany");
                sublist.Add("Widow for a year");
                list.Add(sublist);
                listItem = new ListItem("Kurt Vonnegut");
                list.Add(listItem);
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("Slaughterhouse 5");
                sublist.Add("Welcome to the Monkey House");
                sublist.Add("The great pianola");
                sublist.Add("Galapagos");
                list.Add(sublist);
                document.Add(list);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
예제 #29
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF with information about the movies
         * @param    filename the name of the PDF file that will be created.
         */
        public byte[] CreatePdf(int compression)
        {
            using (MemoryStream ms = new MemoryStream()) {
                // step 1
                using (Document document = new Document()) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    switch (compression)
                    {
                    case -1:
                        Document.Compress = false;
                        break;

                    case 0:
                        writer.CompressionLevel = 0;
                        break;

                    case 2:
                        writer.CompressionLevel = 9;
                        break;

                    case 3:
                        writer.SetFullCompression();
                        break;
                    }
                    // step 3
                    document.Open();
                    // step 4
                    // Create database connection and statement
                    var SQL =
                        @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c 
FROM film_country c, film_movie_country mc 
  WHERE c.id = mc.country_id
GROUP BY mc.country_id, country ORDER BY c DESC";
                    // Create a new list
                    List list             = new List(List.ORDERED);
                    DbProviderFactory dbp = AdoDB.Provider;
                    using (var c = dbp.CreateConnection()) {
                        c.ConnectionString = AdoDB.CS;
                        using (DbCommand cmd = c.CreateCommand()) {
                            cmd.CommandText = SQL;
                            c.Open();
                            using (var r = cmd.ExecuteReader()) {
                                while (r.Read())
                                {
                                    // create a list item for the country
                                    ListItem item = new ListItem(
                                        String.Format("{0}: {1} movies", r["country"], r["c"]),
                                        FilmFonts.BOLDITALIC
                                        );
                                    // create a movie list for each country
                                    List movielist = new List(List.ORDERED, List.ALPHABETICAL);
                                    movielist.Lowercase = List.LOWERCASE;
                                    foreach (Movie movie in
                                             PojoFactory.GetMovies(r["country_id"].ToString()))
                                    {
                                        ListItem movieitem    = new ListItem(movie.MovieTitle);
                                        List     directorlist = new List(List.UNORDERED);
                                        foreach (Director director in movie.Directors)
                                        {
                                            directorlist.Add(String.Format(
                                                                 "{0}, {1}", director.Name, director.GivenName
                                                                 ));
                                        }
                                        movieitem.Add(directorlist);
                                        movielist.Add(movieitem);
                                    }
                                    item.Add(movielist);
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    document.Add(list);
                }
                Document.Compress = true;
                return(ms.ToArray());
            }
        }
예제 #30
0
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         Director director;
         using (var c = AdoDB.Provider.CreateConnection())
         {
             c.ConnectionString = AdoDB.CS;
             using (DbCommand cmd = c.CreateCommand())
             {
                 cmd.CommandText = SQL;
                 c.Open();
                 using (var r = cmd.ExecuteReader())
                 {
                     while (r.Read())
                     {
                         // create a paragraph for the director
                         director = PojoFactory.GetDirector(r);
                         Paragraph p = new Paragraph(
                             PojoToElementFactory.GetDirectorPhrase(director));
                         // add a dotted line separator
                         p.Add(new Chunk(new DottedLineSeparator()));
                         // adds the number of movies of this director
                         p.Add(string.Format("movies: {0}", Convert.ToInt32(r["c"])));
                         document.Add(p);
                         // Creates a list
                         List list = new List(List.ORDERED);
                         list.IndentationLeft  = 36;
                         list.IndentationRight = 36;
                         // Gets the movies of the current director
                         var      director_id = Convert.ToInt32(r["id"]);
                         ListItem movieitem;
                         // LINQ allows us to on sort any movie object property inline;
                         // let's sort by Movie.Year, Movie.Title
                         var by_year = from m in PojoFactory.GetMovies(director_id)
                                       orderby m.Year, m.Title
                         select m;
                         // loops over the movies
                         foreach (Movie movie in by_year)
                         {
                             // creates a list item with a movie title
                             movieitem = new ListItem(movie.MovieTitle);
                             // adds a vertical position mark as a separator
                             movieitem.Add(new Chunk(new VerticalPositionMark()));
                             var yr = movie.Year;
                             // adds the year the movie was produced
                             movieitem.Add(new Chunk(yr.ToString()));
                             // add an arrow to the right if the movie dates from 2000 or later
                             if (yr > 1999)
                             {
                                 movieitem.Add(PositionedArrow.RIGHT);
                             }
                             // add the list item to the list
                             list.Add(movieitem);
                         }
                         // add the list to the document
                         document.Add(list);
                     }
                 }
             }
         }
     }
 }