Example #1
0
        static Table tableStyle(Appearance appearance, PageSize pageSize, Document pdoc)
        {
            float[] dim = appearance.getDimensions();

            Table table = new Table(dim, true);

            table.UseAllAvailableWidth().SetDocument(pdoc);

            table.SetHeight(UnitValue.CreatePointValue(pageSize.GetHeight() - 28.333f));

            for (int i = 0; i < appearance.getHeightRatio() + 1; i++)
            {
                for (int j = 0; j < appearance.getDimensions().Length; j++)
                {
                    Cell cell = new Cell();

                    cell.SetHeight(table.GetHeight().GetValue() / appearance.getHeightRatio() - 4.666f);

                    cellStyle(ref cell);
                    table.AddCell(cell);
                }
            }

            return(table);
        }
Example #2
0
        public static void createDocument(List <ImageSelection> listImages, Appearance appearance, PageSize pageSize, string exportFile)
        {
            checkSameDocuments(ref exportFile);

            using (PdfWriter writer = new PdfWriter(exportFile))
            {
                using (PdfDocument pdf = new PdfDocument(writer))
                {
                    Document pdoc = new Document(pdf, pageSize);

                    pdoc.SetMargins(14.1665f, 14.1665f, 14.1665f, 14.1665f);



                    Table table = tableStyle(appearance, pageSize, pdoc);



                    for (int k = 0, i = 0, j = 0; k < listImages.Count; k++, j++)
                    {
                        if (j == appearance.getDimensions().Length)
                        {
                            j = 0; i++;
                        }
                        if (i == appearance.getHeightRatio())
                        {
                            pdoc.Add(table);
                            table = tableStyle(appearance, pageSize, pdoc);

                            pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                            j = i = 0;
                        }

                        Image img = new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(k).getPath()));

                        imgStyle(ref img, listImages.ElementAt(k));


                        table.GetCell(i, j).Add(img);
                    }
                    pdoc.Add(table);


                    pdoc.Close();
                }
            }
        }
Example #3
0
        public static void createDocument(List <ImageSelection> listImages, Appearance appearance, PageSize pageSize, string exportFile, Format format)
        {
            checkSameDocuments(ref exportFile);

            using (PdfWriter writer = new PdfWriter(exportFile))
            {
                using (PdfDocument pdf = new PdfDocument(writer))
                {
                    Document pdoc = new Document(pdf, pageSize);
                    pdoc.SetMargins(8.5f, 8.5f, 8.5f, 8.5f);
                    Appearance coverAppearance = new Appearance(appearance.getAppearanceType(), format, 1);

                    Table table = tableStyle(coverAppearance, pageSize, pdoc);
                    table = tableStyle(coverAppearance, pageSize, pdoc);
                    Image imgc = null;
                    try
                    {
                        imgc = new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(0).getPath()));
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                        MessageBox.Show("There's no image selected !", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        pdoc = null;
                        //pdf = null;
                        pdf.AddNewPage();
                        pdf.Close();
                        writer.Close();
                        File.Delete(exportFile);

                        return;
                    }

                    imgStyle(ref imgc, listImages.ElementAt(0));

                    table.GetCell(0, 0).Add(imgc);
                    pdoc.Add(table);



                    table = tableStyle(appearance, pageSize, pdoc);
                    pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));

                    for (int k = 1, i = 0, j = 0; k < listImages.Count - 1; k++, j++)
                    {
                        if (j == appearance.getDimensions().Length)
                        {
                            j = 0; i++;
                        }
                        if (i == appearance.getHeightRatio())
                        {
                            pdoc.Add(table);
                            table = tableStyle(appearance, pageSize, pdoc);

                            pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                            j = i = 0;
                        }

                        Image img = new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(k).getPath()));

                        imgStyle(ref img, listImages.ElementAt(k));
                        Console.WriteLine(listImages.ElementAt(k).format);


                        table.GetCell(i, j).Add(img);
                    }
                    pdoc.Add(table);

                    pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));


                    table = tableStyle(coverAppearance, pageSize, pdoc);
                    imgc  = new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(listImages.Count - 1).getPath()));
                    imgStyle(ref imgc, listImages.ElementAt(listImages.Count - 1));
                    table.GetCell(0, 0).Add(imgc);
                    pdoc.Add(table);


                    pdoc.Close();
                }
            }
        }