private void ExposeCatalog(Document document, SimpleColumnText columnText, CatalogProps catProps)
        {
            StringList index = catProps.Index;

            if (index == null)
            {
                return;
            }

            Chunk chunk = new Chunk(catProps.Title, fSubchapFont);

            chunk.SetLocalDestination(catProps.Sign);

            if (CatalogNewPages)
            {
                document.Add(new Paragraph(chunk));
                document.Add(new Paragraph(Chunk.NEWLINE));
            }
            else
            {
                columnText.AddElement(new Paragraph(chunk)
                {
                    Alignment = 1
                });
                columnText.AddElement(new Paragraph(Chunk.NEWLINE));
            }

            index.Sort();
            int num = index.Count;

            for (int i = 0; i < num; i++)
            {
                Paragraph ps = new Paragraph(new Chunk(index[i], fSymFont));
                ps.SpacingBefore = 0f;
                ps.SpacingAfter  = 20f;
                //ps.Alignment = 1;
                ps.Add(Chunk.NEWLINE);
                columnText.AddElement(ps);

                StringList persons = (StringList)index.GetObject(i);

                persons.Sort();
                int num2 = persons.Count;
                for (int k = 0; k < num2; k++)
                {
                    GEDCOMIndividualRecord iRec = (GEDCOMIndividualRecord)persons.GetObject(k);

                    chunk = new Chunk(persons[k], fTextFont);
                    chunk.SetLocalGoto(iRec.XRef);
                    Paragraph p = new Paragraph(chunk);
                    columnText.AddElement(p);
                }

                columnText.AddElement(new Paragraph(Chunk.NEWLINE)
                {
                    SpacingAfter = 10f
                });
            }
        }
Example #2
0
        public override void BeginMulticolumns(int columnCount, float columnSpacing)
        {
            fMulticolumns = true;
            fColumns      = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, columnCount, columnSpacing);
            float pageWidth = fDocument.PageSize.Width - fDocument.LeftMargin - fDocument.RightMargin;

            fColumnWidth = (pageWidth - (columnSpacing * (columnCount - 1))) / columnCount;
        }
        /*private void AddParagraph(Chunk chunk, int alignment = Element.ALIGN_LEFT)
         * {
         *  fDocument.Add(new Paragraph(chunk) { Alignment = alignment });
         * }*/

        protected override void InternalGenerate()
        {
            try
            {
                PrepareData();

                fDocument.AddTitle("FamilyBook");
                fDocument.AddSubject("FamilyBook");
                fDocument.AddAuthor("");
                fDocument.AddCreator(GKData.APP_TITLE);
                fDocument.Open();

                BaseFont baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Times.ttf"), "CP1251", BaseFont.EMBEDDED);
                fTitleFont   = new itFont(baseFont, 30f, Font.BOLD);
                fChapFont    = new itFont(baseFont, 16f, Font.BOLD, BaseColor.BLACK);
                fSubchapFont = new itFont(baseFont, 14f, Font.BOLD, BaseColor.BLACK);
                fLinkFont    = new itFont(baseFont, 8f, Font.UNDERLINE, BaseColor.BLUE);
                fTextFont    = new itFont(baseFont, 8f, Font.NORMAL, BaseColor.BLACK);
                fBoldFont    = new itFont(baseFont, 8f, Font.BOLD, BaseColor.BLACK);
                fSymFont     = new itFont(baseFont, 12f, Font.BOLD, BaseColor.BLACK);

                baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Calibri.ttf"), "CP1251", BaseFont.EMBEDDED);
                //Font page_font = new Font(base_font, 9f, Font.NORMAL);

                fPdfWriter.PageEvent = new PDFWriterEvents(baseFont, LangMan.LS(LSID.LSID_Page) + ": ");

                float halfpage = (fDocument.Top - fDocument.Bottom - (fTitleFont.Size) * 4) / 2f;
                fDocument.Add(new Paragraph(Chunk.NEWLINE)
                {
                    SpacingAfter = halfpage
                });
                fDocument.Add(new Paragraph(LangMan.LS(LSID.LSID_FamilyBook), fTitleFont)
                {
                    Alignment = Element.ALIGN_CENTER
                });
                fDocument.NewPage();

                Chunk chapChunk = new Chunk(LangMan.LS(LSID.LSID_TableOfContents), fChapFont);
                fDocument.Add(new Paragraph(chapChunk));
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                chapChunk = new Chunk("1. " + LangMan.LS(LSID.LSID_PersonalRecords), fLinkFont);
                chapChunk.SetLocalGoto("IndividualRecords");
                fDocument.Add(new Paragraph(chapChunk));

                chapChunk = new Chunk("2. " + LangMan.LS(LSID.LSID_Indexes), fLinkFont);
                chapChunk.SetLocalGoto("Catalogs");
                fDocument.Add(new Paragraph(chapChunk));

                // debug

                /*Rectangle pgSize = fDocument.PageSize;
                 *              fDocument.Add(new Paragraph(Chunk.NEWLINE));
                 *              chap_chunk = new Chunk(pgSize.Height.ToString() + " / " + pgSize.Width.ToString(), fChapFont);
                 *              fDocument.Add(new Paragraph(chap_chunk) { Alignment = 1 });*/

                int catNum = 0;
                for (BookCatalog cat = BookCatalog.Catalog_First; cat <= BookCatalog.Catalog_Last; cat++)
                {
                    CatalogProps catProps = BookCatalogs[(int)cat];

                    if (!SkipEmptyCatalogs || catProps.Index.Count > 0)
                    {
                        catNum++;
                        string title = "2." + catNum.ToString() + ". " + catProps.Title;

                        chapChunk = new Chunk(title, fLinkFont);
                        chapChunk.SetLocalGoto(catProps.Sign);
                        fDocument.Add(new Paragraph(chapChunk)
                        {
                            IndentationLeft = 1f
                        });
                    }
                }

                fDocument.NewPage();

                chapChunk = new Chunk(LangMan.LS(LSID.LSID_PersonalRecords), fChapFont);
                chapChunk.SetLocalDestination("IndividualRecords");
                fDocument.Add(new Paragraph(chapChunk)
                {
                    Alignment = 1, SpacingAfter = 20f
                });
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                SimpleColumnText columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                float            pageWidth  = fDocument.PageSize.Width - fDocument.LeftMargin - fDocument.RightMargin;
                float            colWidth   = (pageWidth - (10f * 2)) / 3;

                char sym = '!';
                int  num = mainIndex.Count;
                for (int i = 0; i < num; i++)
                {
                    string text = mainIndex[i];
                    GEDCOMIndividualRecord iRec = mainIndex.GetObject(i) as GEDCOMIndividualRecord;

                    char isym = text[0];
                    if ((isym >= 'A' && isym <= 'Z') || (isym >= 'А' && isym <= 'Я'))
                    {
                        if (sym != isym)
                        {
                            Paragraph ps = new Paragraph(new Chunk(isym, fSymFont));
                            ps.Alignment = 1;
                            columnText.AddElement(ps);
                            columnText.AddElement(new Paragraph(Chunk.NEWLINE));
                            sym = isym;
                        }
                    }

                    ExposePerson(columnText, iRec, text, colWidth);

                    columnText.AddElement(new Paragraph(Chunk.NEWLINE));
                }

                fDocument.NewPage();

                chapChunk = new Chunk(LangMan.LS(LSID.LSID_Indexes), fChapFont);
                chapChunk.SetLocalDestination("Catalogs");
                fDocument.Add(new Paragraph(chapChunk)
                {
                    Alignment = 1
                });
                fDocument.Add(new Paragraph(Chunk.NEWLINE));

                //SimpleColumnText columnText;
                if (!CatalogNewPages)
                {
                    columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                }

                for (BookCatalog cat = BookCatalog.Catalog_First; cat <= BookCatalog.Catalog_Last; cat++)
                {
                    CatalogProps catProps = BookCatalogs[(int)cat];

                    if (!SkipEmptyCatalogs || catProps.Index.Count > 0)
                    {
                        if (CatalogNewPages)
                        {
                            fDocument.NewPage();
                            columnText = new SimpleColumnText(fDocument, fPdfWriter.DirectContent, 3, 10f);
                        }

                        ExposeCatalog(fDocument, columnText, catProps);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("FamilyBookExporter.InternalGenerate(): " + ex.Message);
                throw;
            }
        }