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();
                }
            }
        }
Exemple #2
0
        static Table tableStyle(Appearance appearance, PageSize pageSize, Document pdoc)
        {
            float[] dim = appearance.getDimensions();

            Table table = new Table(dim, true);

            table.UseAllAvailableWidth().SetDocument(pdoc);

            if (appearance.getImgNumber() == 1)
            {
                table.SetHeight(UnitValue.CreatePointValue(pageSize.GetHeight()));
            }
            else
            {
                table.SetHeight(UnitValue.CreatePointValue(pageSize.GetHeight() - 17f));
            }

            for (int i = 0; i < appearance.getHeightRatio() + 1; i++)
            {
                for (int j = 0; j < appearance.getDimensions().Length; j++)
                {
                    Cell cell = new Cell();
                    if (appearance.getImgNumber() == 1)
                    {
                        cell.SetHeight(table.GetHeight().GetValue() / appearance.getHeightRatio());
                    }
                    else
                    {
                        cell.SetHeight(table.GetHeight().GetValue() / appearance.getHeightRatio() - 4.666f);
                    }

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

            return(table);
        }
Exemple #3
0
        private void SavePDF_Click(object sender, EventArgs e)
        {
            string   pdfName;
            PageSize pageSize = new PageSize(567f, 567f);

            pdfName = textBoxPDFName.Text;
            if (!(textBoxPDFName.Text.EndsWith(".pdf")))
            {
                pdfName += ".pdf";
            }

            AppearanceType appearanceType = AppearanceType.Portrait;


            string exportFile = Path.Combine(textBoxOutputPath.Text, pdfName);

            Format format = formats.ElementAt(0);


            switch (comboBoxPages.Text)
            {
            case "3": imgNumber = 3;  break;

            case "4": imgNumber = 4;  break;

            case "6": imgNumber = 6;  break;
            }

            switch (comboBoxAppearance.Text)
            {
            case "Portrait": appearanceType = AppearanceType.Portrait;      break;

            case "Landscape": appearanceType = AppearanceType.Landscape;    break;

            case "Magic Appearance": appearanceType = AppearanceType.Magic; break;
            }

            switch (comboBoxFormat.Text)
            {
            case "20x20 (cm)":
                pageSize   = new PageSize(583.999f, 583.999f);
                format     = formats.ElementAt(0);
                appearance = new Appearance(appearanceType, formats.ElementAt(0), imgNumber); break;

            case "21x30 (cm)":
                pageSize   = new PageSize(611.999f, 867.666f);
                format     = formats.ElementAt(1);
                appearance = new Appearance(appearanceType, formats.ElementAt(1), imgNumber); break;

            case "21x15 (cm)":
                pageSize   = new PageSize(611.999f, 441.999f);
                format     = formats.ElementAt(2);
                appearance = new Appearance(appearanceType, formats.ElementAt(2), imgNumber); break;
            }

            if (checkBoxAppearance.Checked)
            {
                PDFMaker.createDocument(listImages, appearance, pageSize, exportFile, format);
            }
            else
            {
                PDFMaker.createDocument(listImages, appearance, pageSize, exportFile, format, true);
            }


            List <ImageSelection> imagesToDelete = new List <ImageSelection>();

            foreach (ImageSelection garbage in listBoxImageFile.Items)
            {
                imagesToDelete.Add(garbage);
            }

            foreach (ImageSelection imageToDelete in imagesToDelete)
            {
                listBoxImageFile.Items.Remove(imageToDelete);

                foreach (ImageSelection image in listImages)
                {
                    if (image.ToString() == imageToDelete.ToString())
                    {
                        listImages.Remove(image);
                        break;
                    }
                }
            }
            labelNrImages.Text      = "Images :      " + listImages.Count;
            labelFullPages.Text     = "Full Pages : " + (listImages.Count / imgNumber).ToString();
            PDFMaker.setOrientation = false;
        }
Exemple #4
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();
                }
            }
        }
Exemple #5
0
        public static void createDocument(List <ImageSelection> listImages, Appearance appearance, PageSize pageSize, string exportFile, Format format, bool value)
        {
            checkSameDocuments(ref exportFile);

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



                    List <ImageSelection> currentImgsList = new List <ImageSelection>();
                    List <Image>          imgs            = new List <Image>();
                    List <Image>          currentImgs     = new List <Image>();

                    for (int i = 0; i < listImages.Count; i++)
                    {
                        imgs.Add(new Image(iText.IO.Image.ImageDataFactory.Create(listImages.ElementAt(i).getPath())));
                        imgs.ElementAt(i).SetHorizontalAlignment(HorizontalAlignment.CENTER);
                        imgs.ElementAt(i).SetAutoScale(true);


                        imgStyle(imgs.ElementAt(i), listImages.ElementAt(i));
                    }
                    setOrientation = true;


                    /// First page
                    Table table = null;
                    try
                    {
                        imgs.ElementAt(0).SetAutoScale(true);

                        table = tableStyle(coverAppearance, pageSize, pdoc);


                        table.GetCell(0, 0).SetMargins(0f, 0f, 0f, 0f);
                        table.GetCell(0, 0).SetPaddings(0f, 0f, 0f, 0f);


                        table.SetMargins(0f, 0f, 0f, 0f);
                        table.SetPaddings(0f, 0f, 0f, 0f);
                        //table.GetCell(0, 0).SetBorder(BorderStyle.FixedSingle);
                        table.GetCell(0, 0).SetVerticalAlignment(VerticalAlignment.MIDDLE);
                        table.GetCell(0, 0).Add(imgs.ElementAt(0));

                        pdoc.Add(table);

                        if (imgs.Count > 2)
                        {
                            pdoc.SetMargins(8.5f, 8.5f, 8.5f, 8.5f);
                        }
                        pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                    }
                    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;
                    }



                    for (int k = 1, p = 0; k < listImages.Count - 1; k++)
                    {
                        currentImgsList.Add(listImages.ElementAt(k));
                        currentImgs.Add(imgs.ElementAt(k));
                        if (k % appearance.getImgNumber() == 0)
                        {
                            currentAppearance = new Appearance(appearance.getAppearanceType(), format, appearance.getImgNumber(), getLandscape(currentImgsList), getPortrait(currentImgsList));
                            Console.WriteLine(currentAppearance.specialCond);
                            switch (currentAppearance.specialCond)
                            {
                            case "21x15_4P0L": table = Custom.customTable1(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x15_3P1L": table = Custom.customTable2(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x15_2P2L": table = Custom.customTable3(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x15_1P3L": table = Custom.customTable3(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x15_0P4L": table = Custom.customTable3(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;


                            case "20x20_1P2L": table = Custom.customTable4(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_2P1L": table = Custom.customTable5(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_0P3L": table = Custom.customTable6(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_3P0L": table = Custom.customTable7(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_4_1P3L": table = Custom.customTable8(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_4_2P2L": table = Custom.customTable9(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_4_0P4L": table = Custom.customTable10(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_4_3P1L": table = Custom.customTable11(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "20x20_4_4P0L": table = Custom.customTable12(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;


                            case "21x30_4_1P3L": table = Custom.customTable13(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_4_2P2L": table = Custom.customTable14(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_4_3P1L": table = Custom.customTable15(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_4_0P4L": table = Custom.customTable16(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_4_4P0L": table = Custom.customTable17(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_5P1L": table = Custom.customTable18(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_1P5L": table = Custom.customTable19(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_2P4L": table = Custom.customTable20(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_3P3L": table = Custom.customTable21(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_4P2L": table = Custom.customTable22(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_0P6L": table = Custom.customTable23(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;

                            case "21x30_6_6P0L": table = Custom.customTable24(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs); break;
                            }
                            Console.WriteLine("Portraits: " + getPortrait(currentImgsList) + "Landscapes: " + getLandscape(currentImgsList));
                            currentImgsList.Clear();
                            currentImgs.Clear();



                            p++;
                            if (((listImages.Count - 2) / appearance.getImgNumber() == p) && ((listImages.Count - 2) % appearance.getImgNumber() == 0))
                            {
                                pdoc.SetMargins(0f, 0f, 0f, 0f);
                            }

                            pdoc.Add(table);
                            pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                        }
                    }
                    if (currentImgsList.Count > 0)
                    {
                        currentAppearance = new Appearance("reminder", appearance.getImgNumber());
                        table             = Custom.customTable3(currentAppearance, pageSize, pdoc, currentImgsList, currentImgs);
                        currentImgsList.Clear();
                        currentImgs.Clear();

                        pdoc.Add(table);

                        pdoc.SetMargins(0f, 0f, 0f, 0f);
                        pdoc.Add(new AreaBreak(iText.Layout.Properties.AreaBreakType.NEXT_PAGE));
                    }


                    imgs.ElementAt(imgs.Count - 1).SetAutoScale(true);


                    table = tableStyle(coverAppearance, pageSize, pdoc);


                    table.GetCell(0, 0).SetMargins(0f, 0f, 0f, 0f);
                    table.GetCell(0, 0).SetPaddings(0f, 0f, 0f, 0f);


                    table.SetMargins(0f, 0f, 0f, 0f);
                    table.SetPaddings(0f, 0f, 0f, 0f);
                    //table.GetCell(0, 0).SetBorder(BorderStyle.FixedSingle);
                    table.GetCell(0, 0).SetVerticalAlignment(VerticalAlignment.MIDDLE);
                    table.GetCell(0, 0).Add(imgs.ElementAt(imgs.Count - 1));

                    pdoc.Add(table);


                    pdoc.Close();
                }
            }
        }