Ejemplo n.º 1
0
 /// <summary>
 /// Creates an instance of a Species Information Document Pdf file object. This object can then be used when exporting a Species Information Document to pdf or Rtf files.
 /// </summary>
 /// <param name="document">An instance of Species Information Document</param>
 public SpeciesInformationDocumentWriter(SpeciesInformationDocument document)
 {
     _document = document;
     _pdfFile  = createPdfDocument(_document);
 }
 /// <summary>
 /// Creates an instance of a Species Information Document Rtf reader. This object can then update the properties of the species information document based on the content of a specified rtf-file.
 /// </summary>
 /// <param name="document">An instance of Species Information Document</param>
 public SpeciesInformationDocumentRtfReader(SpeciesInformationDocument document)
 {
     _document = document;
     _textBox  = new RichTextBox();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This method creates the document layout for this pdf file
        /// </summary>
        /// <param name="document">A species information document object holding all the information that should be included in the pdf file</param>
        /// <returns>A formated pdf document</returns>
        private Document createPdfDocument(SpeciesInformationDocument document)
        {
            Document pdfFile = new Document();

            pdfFile.Info.Title   = "Arfaktablad om " + document.Taxon.GetScientificNameAndAuthorAndCommonName() + " [DyntaxaTaxonId: " + document.Taxon.Id + "]";
            pdfFile.Info.Subject = "Arfaktablad med beskrivning, utbredningsuppgifter, ekologi, hot och naturvårdsåtgärder, litteratur";
            pdfFile.Info.Author  = document.AuthorAndYear;

            // Get the predefined style Normal.
            Style style = pdfFile.Styles["Normal"];

            // Because all styles are derived from Normal, the next line changes the
            // font of the whole document. Or, more exactly, it changes the font of
            // all styles and paragraphs that do not redefine the font.
            style.Font.Name = "Times New Roman";
            style.Font.Size = Unit.FromPoint(11.5);

            Section section = pdfFile.AddSection();

            //Header1
            Paragraph scientificName = section.AddParagraph(document.ScientificName);

            scientificName.Format.Font.Name = "Arial";
            scientificName.Format.Font.Bold = true;
            scientificName.Format.Font.Size = Unit.FromPoint(16);
            scientificName.Format.Alignment = ParagraphAlignment.Center;

            //Header2
            if (document.CommonName.IsNotEmpty())
            {
                Paragraph commonName = section.AddParagraph(document.CommonName);
                commonName.Format.Font.Name = "Arial";
                commonName.Format.Font.Size = Unit.FromPoint(16);
                commonName.Format.Alignment = ParagraphAlignment.Center;
            }

            //Redlist information
            Table redlistInformationBox = section.AddTable();

            redlistInformationBox.Borders.Width = 0;
            //redlistInformationBox.Borders.Bottom.Width = Unit.FromPoint(0.25);

            Column columnOrganismGroup = redlistInformationBox.AddColumn(Unit.FromCentimeter(8));

            columnOrganismGroup.Format.Alignment = ParagraphAlignment.Left;
            Column columnRedlistInformation = redlistInformationBox.AddColumn(Unit.FromCentimeter(8));

            columnRedlistInformation.Format.Alignment = ParagraphAlignment.Right;
            Row       row  = redlistInformationBox.AddRow();
            Cell      cell = row.Cells[0];
            Paragraph organismGroupName = cell.AddParagraph(document.OrganismGroup);

            organismGroupName.Format.Font.Name = "Arial";
            organismGroupName.Format.Font.Size = Unit.FromPoint(11.5);
            cell = row.Cells[1];
            Paragraph redlistInformationText = cell.AddParagraph();
            Font      fontBig       = new Font("Arial", Unit.FromPoint(11.5));
            Font      fontSmall     = new Font("Arial", Unit.FromPoint(9.5));
            Font      fontCriterion = new Font("Arial", Unit.FromPoint(9));

            if (document.RedlistCategoryName.IsNotEmpty())
            {
                redlistInformationText.AddFormattedText(document.RedlistCategoryName.Substring(0, 1).ToUpper(), fontBig);
                redlistInformationText.AddFormattedText(document.RedlistCategoryName.Substring(1).ToUpper(), fontSmall);
                redlistInformationText.AddFormattedText(" (", fontBig);
                fontBig.Bold = true;
                redlistInformationText.AddFormattedText(document.RedlistCategoryShortString, fontBig);
                fontBig.Bold = false;
                redlistInformationText.AddFormattedText(")", fontBig);
                if (document.RedlistCriteria != "")
                {
                    redlistInformationText.AddLineBreak();
                    redlistInformationText.AddFormattedText(document.RedlistCriteria, fontCriterion);
                }
            }

            List <ParagraphItem> paragraphItems = null;

            section.AddParagraph(LINE);

            //Taxonomic information
            Paragraph taxonomicInformation = section.AddParagraph();

            taxonomicInformation.Format.Alignment = ParagraphAlignment.Justify;
            taxonomicInformation.Format.Font.Size = Unit.FromPoint(10);
            paragraphItems = GetParagraphItems(document.AutomaticTaxonomicParagraph, document.ItalicStringsInText);
            foreach (ParagraphItem item in paragraphItems)
            {
                if (item.Italic)
                {
                    taxonomicInformation.AddFormattedText(item.Text, TextFormat.Italic);
                }
                else
                {
                    taxonomicInformation.AddText(item.Text);
                }
            }

            //Main document paragraphs
            Paragraph paragraph;

            if (_document.DescriptionParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Beskrivning. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.DescriptionParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            if (_document.DistributionParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Utbredning och status. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.DistributionParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            if (_document.EcologyParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Ekologi. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.EcologyParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            if (_document.ThreatsParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Hot. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.ThreatsParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            if (_document.MeasuresParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Åtgärder. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.MeasuresParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            if (_document.ExtraParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.Format.Alignment   = ParagraphAlignment.Justify;
                paragraph.AddFormattedText("Övrigt. ", TextFormat.Bold);
                paragraphItems = GetParagraphItems(document.ExtraParagraph, document.ItalicStringsInText);
                foreach (ParagraphItem item in paragraphItems)
                {
                    if (item.Italic)
                    {
                        paragraph.AddFormattedText(item.Text, TextFormat.Italic);
                    }
                    else
                    {
                        paragraph.AddText(item.Text);
                    }
                }
            }

            //Reference list
            if (_document.ReferenceParagraph.IsNotEmpty())
            {
                paragraph = section.AddParagraph();
                paragraph.Format.SpaceBefore = "5mm";
                paragraph.AddFormattedText("Litteratur", TextFormat.Bold);

                string[] references = _document.ReferenceParagraph.Split('\n');

                foreach (string reference in references)
                {
                    Paragraph referenceParagraph = section.AddParagraph();
                    referenceParagraph.Format.LeftIndent      = "1cm";
                    referenceParagraph.Format.FirstLineIndent = "-1cm";
                    referenceParagraph.Format.Alignment       = ParagraphAlignment.Justify;
                    referenceParagraph.Format.Font.Size       = Unit.FromPoint(10);
                    paragraphItems = GetParagraphItems(reference, document.ItalicStringsInReferences);
                    foreach (ParagraphItem item in paragraphItems)
                    {
                        if (item.Italic)
                        {
                            referenceParagraph.AddFormattedText(item.Text, TextFormat.Italic);
                        }
                        else
                        {
                            referenceParagraph.AddText(item.Text);
                        }
                    }
                }
            }

            paragraph = section.AddParagraph(LINE);
            paragraph.Format.SpaceBefore = "4mm";

            //Author information
            Table authorInformationBox = section.AddTable();

            //authorInformationBox.Format.SpaceBefore = "5mm";
            authorInformationBox.Borders.Width = 0;
            //authorInformationBox.Borders.Top.Width = Unit.FromPoint(0.25);
            Column columnAuthor = authorInformationBox.AddColumn(Unit.FromCentimeter(16));

            columnAuthor.Format.Alignment = ParagraphAlignment.Justify;
            row  = authorInformationBox.AddRow();
            cell = row.Cells[0];
            Paragraph authorParagraph = cell.AddParagraph();

            authorParagraph.AddText(getUpdateInformation());

            return(pdfFile);
        }