Example #1
0
        protected void Imprimir(cls_Viaje_DAL viaje)
        {
            Document document = new Document();
            Section  section  = document.AddSection();

            section.AddImage("/assets/images/top.jpg");
            section.AddParagraph("");

            section.AddParagraph("DATOS DEL VIAJERO", "Bold");
            section.AddParagraph("");
            section.AddParagraph("NOMBRE COMPLETO: " + viaje.Nombre + " " + viaje.Apellido);
            section.AddParagraph("ASIENTO: " + viaje.Asiento + "CLASE: " + viaje.Clase + " Economica");
            section.AddParagraph("");
            section.AddParagraph("");

            section.AddParagraph("DATOS DEL VIAJE", "Bold");
            section.AddParagraph("");
            section.AddParagraph("ORIGEN: " + viaje.Origen + "           DESTINO: " + viaje.Destino);
            section.AddParagraph("SALIDA: " + viaje.Salida + "           REGRESO: " + viaje.Regreso);

            section.AddParagraph("");
            section.AddImage("/assets/images/top.jpg");

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            string filename = "../../users/marich/desktop/HelloWorld.pdf";

            pdfRenderer.PdfDocument.Save(filename);
        }
Example #2
0
        public ActionResult TestMigraDoc1()
        {
            Document document = new Document();

            Style style = document.Styles["Normal"];

            style.Font.Name = "Cordia New";
            style.Font.Size = 16;

            document.Info.Author   = "PalangPanya";
            document.Info.Subject  = "Member Information";
            document.Info.Keywords = "PalangPanya";

            Section section = document.AddSection();

            Paragraph paragraph = section.AddParagraph();

            paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50);

            paragraph.AddFormattedText("Hello,ไทย World!", TextFormat.Bold);
            paragraph.AddFormattedText("ทดสอบการใช้ภาษา", TextFormat.Italic);

            var logoPath = Path.Combine(_env.WebRootPath, "images");

            logoPath = Path.Combine(logoPath, "logo_t.png");
            Image imgLogo = section.AddImage(logoPath);

            imgLogo.Height          = "2cm";
            imgLogo.LockAspectRatio = true;

            var memberPicPath = Path.Combine(_env.WebRootPath, "images_member");

            memberPicPath = Path.Combine(memberPicPath, "_2_1365148227.jpg");
            //memberPicPath = Path.Combine(memberPicPath, "_677138-topic-ix-1.jpg");
            Image imgMember = section.AddImage(memberPicPath);

            imgMember.Height             = "5cm";
            imgMember.LockAspectRatio    = true;
            imgMember.RelativeVertical   = RelativeVertical.Line;
            imgMember.RelativeHorizontal = RelativeHorizontal.Margin;
            imgMember.Top              = ShapePosition.Top;
            imgMember.Left             = ShapePosition.Right;
            imgMember.WrapFormat.Style = WrapStyle.Through;


            document.UseCmykColor = true;
            const bool             unicode     = true;
            const PdfFontEmbedding embedding   = PdfFontEmbedding.Always;
            PdfDocumentRenderer    pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            //const string filename = "HelloWorld.pdf";
            //pdfRenderer.PdfDocument.Save(filename);
            MemoryStream m = new MemoryStream();

            pdfRenderer.PdfDocument.Save(m, false);
            return(new FileStreamResult(m, "application/pdf"));
        }
Example #3
0
        Document CreateDocument()
        {
            // Create a new MigraDoc document
            Document document = new Document();

            // Add a section to the document
            Section section = document.AddSection();

            // Add a paragraph to the section
            Paragraph paragraph = section.AddParagraph();

            // Add some text to the paragraph
            paragraph.AddImage(Application.StartupPath + "\\images\\logo.png");
            paragraph.AddFormattedText("Braze number: " + textBox1.Text + "\n", TextFormat.Bold);
            paragraph.AddFormattedText("Date: " + textBox2.Text + "\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Duration: " + textBox3.Text + "\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Status: " + textBox5.Text + "\n\n", TextFormat.NotBold);
            paragraph.AddFormattedText("Log: " + "\n", TextFormat.Bold);
            int loCount = 0;

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Text.Contains("The large Nitrogen valve is opened."))
                {
                    if (loCount < 2)
                    {
                        paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                    }
                    loCount++;
                    if (loCount == 2)
                    {
                        paragraph.AddFormattedText("...\n", TextFormat.NotBold);
                    }
                }
                else if (listView1.Items[i].Text.Contains("The large Nitrogen valve is closed."))
                {
                    if (loCount < 2)
                    {
                        paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                    }
                }
                else
                {
                    paragraph.AddFormattedText(listView1.Items[i].Text + "\n", TextFormat.NotBold);
                }
            }
            //paragraph.AddImage("../../SomeImage.png");
            //paragraph.AddImage("../../Logo.pdf");
            //section.AddImage("../../Logo.pdf");
            section.AddImage(Application.StartupPath + "\\temp\\testa.png");
            section.AddImage(Application.StartupPath + "\\temp\\testb.png");

            return(document);
        }
Example #4
0
        /// <summary>
        /// Defines the cover page.
        /// </summary>
        public static void DefineCover(Document document, Project currentProject)
        {
            try {
                Section section = document.AddSection();

                Paragraph paragraph = section.AddParagraph();
                paragraph.Format.SpaceAfter = "3cm";

                Image image = section.AddImage(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\\logo.jpg");
                image.Width = "6cm";

                paragraph = section.AddParagraph("Report generated using Cameratrap Manager\nfor the project:\n" + currentProject.Name);
                paragraph.Format.Font.Size   = 16;
                paragraph.Format.Font.Color  = Colors.DarkRed;
                paragraph.Format.SpaceBefore = "6cm";
                paragraph.Format.SpaceAfter  = "3cm";

                paragraph = section.AddParagraph("Creation date: " + currentProject.StartDate.ToString());
                paragraph = section.AddParagraph("Last modified: " + currentProject.CompletionDate.ToString());

                paragraph = section.AddParagraph("Rendering date: ");
                paragraph.AddDateField();
            } catch (Exception ex) {
                throw ex;
            }
        }
        protected void AddImageToSection([JetBrains.Annotations.NotNull] Section sec, [JetBrains.Annotations.NotNull] FileInfo file, [CanBeNull] string title = "")
        {
            var mytitle = GetGraphTitle(file.Name);

            if (!string.IsNullOrEmpty(title))
            {
                mytitle = title;
            }
            var imgtitle = sec.AddParagraph(mytitle);

            imgtitle.Format.Font.Size    = 12;
            imgtitle.Format.KeepWithNext = true;
            imgtitle.Format.SpaceAfter   = "0.5cm";
            imgtitle.Format.SpaceBefore  = "0.5cm";
            imgtitle.Format.Font.Color   = Colors.Blue;
            Logger.Debug("Adding Image to pdf:" + file.FullName);
            var img  = sec.AddImage(file.FullName);
            var size = GetDimensions(file.FullName);

            if (size.Height > size.Width)
            {
                img.Height = "10cm";
            }
            else
            {
                img.Width = "16cm";
            }
        }
        private void AddHeader(Section sec)
        {
            Image image = new Image();

            image      = sec.AddImage(Tools.GetHeaderWithoutText());
            image.Left = ShapePosition.Center;
        }
Example #7
0
        /// <summary>
        /// Adds an image to the page. Only PNG images are supported out of the box.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="pageContent"></param>
        /// <param name="pageWidth"></param>
        /// <param name="style"></param>
        private static void AddImage(Section section, PageContentElement pageContent, Unit pageWidth, Style style)
        {
            Unit originalImageWidthInches;

            // work around to get image dimensions
            using (System.Drawing.Image userImage = System.Drawing.Image.FromFile(pageContent.ImagePath))
            {
                // get image width in inches
                var imageInches = userImage.Width / userImage.VerticalResolution;
                originalImageWidthInches = new Unit(imageInches, UnitType.Inch);
            }

            // add image
            Image image = section.AddImage(pageContent.ImagePath);

            // Calculate Image size:
            // if actual image size is larger than PageWidth - margins, set image width as page width - margins
            Unit actualPageContentWidth = new Unit((pageWidth.Inch - section.PageSetup.LeftMargin.Inch - section.PageSetup.RightMargin.Inch), UnitType.Inch);

            if (originalImageWidthInches > actualPageContentWidth)
            {
                image.Width = actualPageContentWidth;
            }
            image.LockAspectRatio = true;
            image.Left            = pageContent.ImageAlignment.ConvertEnum <ShapePosition>();
        }
Example #8
0
        protected static void AddImageToSection([NotNull] Section sec, [NotNull] ResultFileEntry rfe)
        {
            var mytitle  = rfe.FileTitle;
            var imgtitle = sec.AddParagraph(mytitle);

            imgtitle.Format.Font.Size    = 12;
            imgtitle.Format.KeepWithNext = true;
            imgtitle.Format.SpaceAfter   = "0.5cm";
            imgtitle.Format.SpaceBefore  = "0.5cm";
            imgtitle.Format.Font.Color   = Colors.Blue;
            var img  = sec.AddImage(rfe.FullFilename);
            var size = GetDimensions(rfe.FullFilename);

            if (size.Height > 5000)
            {
                img.Height = "20cm";
            }
            else if (size.Height > size.Width)
            {
                img.Height = "10cm";
            }
            else
            {
                img.Width = "16cm";
            }
        }
Example #9
0
        private static void SetImage(Section section)
        {
            var image = section.AddImage(StatementPhoto);

            image.Width  = "2.03cm";
            image.Height = "0.62cm";
            image.Left   = ShapePosition.Center;
        }
Example #10
0
        public void AddImage(string filePath)
        {
            var image = _section.AddImage(filePath);

            image.Height = _doc.DefaultPageSetup.PageHeight;
            image.Width  = _doc.DefaultPageSetup.PageWidth;
            _section.AddPageBreak();
        }
Example #11
0
        /// <summary>Creates the graph page.</summary>
        /// <param name="section">The section to write to.</param>
        /// <param name="graphPage">The graph and table to convert to html.</param>
        private void CreateGraphPage(Section section, GraphPage graphPage)
        {
            int numGraphsToPrint = graphPage.graphs.FindAll(g => g.IncludeInDocumentation).Count;

            if (numGraphsToPrint > 0)
            {
                int numColumns = 2;
                int numRows    = (numGraphsToPrint + 1) / numColumns;

                // Export graph to bitmap file.
                Bitmap image = new Bitmap(1800, numRows * 600);
                using (Graphics gfx = Graphics.FromImage(image))
                    using (SolidBrush brush = new SolidBrush(System.Drawing.Color.White))
                    {
                        gfx.FillRectangle(brush, 0, 0, image.Width, image.Height);
                    }
                GraphPresenter graphPresenter = new GraphPresenter();
                explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                GraphView graphView = new GraphView();
                graphView.BackColor        = OxyPlot.OxyColors.White;
                graphView.ForegroundColour = OxyPlot.OxyColors.Black;
                graphView.FontSize         = 22;
                graphView.MarkerSize       = MarkerSizeType.Normal;
                graphView.Width            = image.Width / numColumns;
                graphView.Height           = image.Height / numRows;
                graphView.LeftRightPadding = 0;

                int col = 0;
                int row = 0;
                for (int i = 0; i < graphPage.graphs.Count; i++)
                {
                    if (graphPage.graphs[i].IncludeInDocumentation)
                    {
                        graphPresenter.Attach(graphPage.graphs[i], graphView, explorerPresenter);
                        Rectangle r = new Rectangle(col * graphView.Width, row * graphView.Height,
                                                    graphView.Width, graphView.Height);
                        graphView.Export(ref image, r, false);
                        graphPresenter.Detach();
                        col++;
                        if (col >= numColumns)
                        {
                            col = 0;
                            row++;
                        }
                    }
                }

                string basePngFileName = Apsim.FullPath(graphPage.graphs[0].Parent) + "." +
                                         graphPage.name + ".png";
                basePngFileName = basePngFileName.TrimStart('.');
                string pngFileName = Path.Combine(WorkingDirectory, basePngFileName);
                image.Save(pngFileName, System.Drawing.Imaging.ImageFormat.Png);

                MigraDoc.DocumentObjectModel.Shapes.Image sectionImage = section.AddImage(pngFileName);
                sectionImage.LockAspectRatio = true;
                sectionImage.Width           = "19cm";
            }
        }
        public void AddPage(string filePath)
        {
            var page = pdfSection.AddImage(filePath);

            page.Width  = resultPdfDocument.DefaultPageSetup.PageWidth;
            page.Height = resultPdfDocument.DefaultPageSetup.PageHeight;

            pdfSection.AddPageBreak();
        }
Example #13
0
        public void AddImage(string filePath)
        {
            var image = _currentSection.AddImage(filePath);

            image.Height = _currentDocument.DefaultPageSetup.PageHeight;
            image.Width  = _currentDocument.DefaultPageSetup.PageWidth;
            _currentSection.AddPageBreak();
            Images.Add(filePath);
        }
Example #14
0
        private void LeftSide(IPdfStyling pdfStyling, Section section)
        {
            Image bottle = section.AddImage(@"D:\DEVELOPMENT\GIT\OPTEN Solutions\tests\Opten.Web.Infrastructure.Pdf.Test\Images\drink_winterbowle.jpg");

            bottle.LockAspectRatio  = true;
            bottle.Height           = pdfStyling.MaxHeightInPoints - (pdfStyling.Margin[0] * 2);
            bottle.Top              = pdfStyling.Margin[0] - Unit.FromCentimeter(0.3); //TODO: Why 0.3?
            bottle.Left             = pdfStyling.Margin[0] * 2;
            bottle.RelativeVertical = RelativeVertical.Margin;
        }
        private void AddImageToDocument(string file)
        {
            var image = section.AddImage(file);

            image.Height      = document.DefaultPageSetup.PageHeight;
            image.Width       = document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.75;
            image.ScaleWidth  = 0.75;

            section.AddPageBreak();
        }
Example #16
0
        private void AddImage(string file)
        {
            Image image = _section.AddImage(file);

            image.Height      = _document.DefaultPageSetup.PageHeight;
            image.Width       = _document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.7;
            image.ScaleWidth  = 0.7;

            _section.AddPageBreak();
        }
        public void AddImage(string path)
        {
            Image image = _documentSection.AddImage(path);

            image.Height      = _document.DefaultPageSetup.PageHeight;
            image.Width       = _document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.7;
            image.ScaleWidth  = 0.7;

            _documentSection.AddPageBreak();
        }
Example #18
0
        public void CreateDocument(string fileName, bool fillShapes)
        {
            var doc = new Document();

            Section section = doc.AddSection();

            var mainImagePath = Path.Combine(TempFolder, "mainDiagram.png");

            SavePictureAsImage(mainImagePath, fillShapes);

            var image = section.AddImage(mainImagePath);

            foreach (var siteImagePath in CreateSiteImages(fillShapes))
            {
                var siteImage = section.AddImage(siteImagePath);
            }

            RtfDocumentRenderer rtfRender = new RtfDocumentRenderer();

            rtfRender.Render(doc, fileName, TempFolder);
        }
Example #19
0
        /// <summary>Creates the graph page.</summary>
        /// <param name="section">The section to write to.</param>
        /// <param name="graphPage">The graph and table to convert to html.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void CreateGraphPage(Section section, GraphPage graphPage, string workingDirectory)
        {
            int numGraphsToPrint = graphPage.graphs.FindAll(g => g.IncludeInDocumentation).Count;

            if (numGraphsToPrint > 0)
            {
                int numColumns = 2;
                int numRows    = (numGraphsToPrint + 1) / numColumns;

                // Export graph to bitmap file.
                Bitmap image = new Bitmap(1800, numRows * 600);
                using (Graphics gfx = Graphics.FromImage(image))
                    using (SolidBrush brush = new SolidBrush(System.Drawing.Color.White))
                    {
                        gfx.FillRectangle(brush, 0, 0, image.Width, image.Height);
                    }
                GraphPresenter graphPresenter = new GraphPresenter();
                GraphView      graphView      = new GraphView();
                graphView.BackColor        = System.Drawing.Color.White;
                graphView.FontSize         = 22;
                graphView.MarkerSize       = 8;
                graphView.Width            = image.Width / numColumns;
                graphView.Height           = image.Height / numRows;
                graphView.LeftRightPadding = 0;

                int col = 0;
                int row = 0;
                for (int i = 0; i < graphPage.graphs.Count; i++)
                {
                    if (graphPage.graphs[i].IncludeInDocumentation)
                    {
                        graphPresenter.Attach(graphPage.graphs[i], graphView, ExplorerPresenter);
                        Rectangle r = new Rectangle(col * graphView.Width, row * graphView.Height,
                                                    graphView.Width, graphView.Height);
                        graphView.Export(image, r, false);
                        graphPresenter.Detach();
                        col++;
                        if (col >= numColumns)
                        {
                            col = 0;
                            row++;
                        }
                    }
                }

                string PNGFileName = Path.Combine(workingDirectory, graphPage.name + ".png");
                image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);

                MigraDoc.DocumentObjectModel.Shapes.Image sectionImage = section.AddImage(PNGFileName);
                sectionImage.LockAspectRatio = true;
                sectionImage.Width           = "19cm";
            }
        }
Example #20
0
 private static void AddImage(Section section, System.Drawing.Bitmap img)
 {
     if (img != null)
     {
         string imageFilename = Path.GetTempFileName();
         img.Save(imageFilename);
         Image image = section.AddImage(imageFilename);
         image.Width           = "6cm";
         image.LockAspectRatio = true;
         File.Delete(imageFilename);
     }
 }
Example #21
0
 void PageHeader()
 {
     section                  = this.document.AddSection();
     image                    = section.AddImage("Support/logo.jpg");
     image.Height             = "2.5cm";
     image.LockAspectRatio    = true;
     image.RelativeVertical   = RelativeVertical.Line;
     image.RelativeHorizontal = RelativeHorizontal.Margin;
     image.Top                = ShapePosition.Top;
     image.Left               = ShapePosition.Center;
     image.WrapFormat.Style   = WrapStyle.Through;
 }
Example #22
0
 /// <summary>Writes PDF for specified auto-doc commands.</summary>
 /// <param name="section">The writer to write to.</param>
 /// <param name="tags">The autodoc tags.</param>
 /// <param name="workingDirectory">The working directory.</param>
 private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
 {
     foreach (AutoDocumentation.ITag tag in tags)
     {
         if (tag is AutoDocumentation.Heading)
         {
             AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
             if (heading.headingLevel > 0 && heading.headingLevel < 4)
             {
                 Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                 if (heading.headingLevel == 1)
                 {
                     para.Format.OutlineLevel = OutlineLevel.Level1;
                 }
                 else if (heading.headingLevel == 2)
                 {
                     para.Format.OutlineLevel = OutlineLevel.Level2;
                 }
                 else if (heading.headingLevel == 3)
                 {
                     para.Format.OutlineLevel = OutlineLevel.Level3;
                 }
                 else if (heading.headingLevel == 4)
                 {
                     para.Format.OutlineLevel = OutlineLevel.Level4;
                 }
             }
         }
         else if (tag is AutoDocumentation.Paragraph)
         {
             AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
         }
         else if (tag is AutoDocumentation.GraphAndTable)
         {
             CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
         }
         else if (tag is Graph)
         {
             GraphPresenter graphPresenter = new GraphPresenter();
             GraphView      graphView      = new GraphView();
             graphView.BackColor = System.Drawing.Color.White;
             graphPresenter.Attach(tag, graphView, ExplorerPresenter);
             string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
             section.AddImage(PNGFileName);
             string caption = (tag as Graph).Caption;
             if (caption != null)
             {
                 section.AddParagraph(caption);
             }
             graphPresenter.Detach();
         }
     }
 }
Example #23
0
        private void AddFileToDoc(string file)
        {
            _section.AddPageBreak();
            var img = _section.AddImage(file);

            img.Top                = 0;
            img.Left               = 0;
            img.Height             = _document.DefaultPageSetup.PageHeight;
            img.Width              = _document.DefaultPageSetup.PageWidth;
            img.RelativeHorizontal = RelativeHorizontal.Page;
            img.RelativeVertical   = RelativeVertical.Page;
            _usedFiles.Add(file);
        }
Example #24
0
        /// <summary>
        /// Document cover definition
        /// </summary>
        /// <param name="document">Document - pdf document</param>
        private static void DefineCover(Document document)
        {
            Section   section   = document.AddSection();
            Paragraph paragraph = section.AddParagraph();

            paragraph.Format.SpaceAfter = "3cm";
            paragraph.Format.Alignment  = ParagraphAlignment.Center;
            String imageFile = ApplicationFolder + "\\napiszprogram.bmp";

            if (!File.Exists(imageFile))
            {
                Properties.Resources.napiszprogram.Save(imageFile);
            }
            Image image = section.AddImage(imageFile);

            image.Width           = "4cm";
            image.LockAspectRatio = true;
            //image.Top = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
            image.Left = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Center;
            image.RelativeHorizontal = MigraDoc.DocumentObjectModel.Shapes.RelativeHorizontal.Margin;
            //image.RelativeVertical = MigraDoc.DocumentObjectModel.Shapes.RelativeVertical.Margin;



            paragraph = section.AddParagraph(document.Info.Title);
            paragraph.Format.Font.Size   = 24;
            paragraph.Format.Font.Color  = Colors.LightBlue;
            paragraph.Format.SpaceBefore = "1cm";
            paragraph.Format.SpaceAfter  = "1cm";

            paragraph = section.AddParagraph(document.Info.Subject);
            paragraph.Format.Font.Size   = 16;
            paragraph.Format.Font.Color  = Colors.LightBlue;
            paragraph.Format.SpaceBefore = "1cm";
            paragraph.Format.SpaceAfter  = "1cm";

            paragraph = section.AddParagraph(document.Info.Author);
            paragraph.Format.Font.Size   = 14;
            paragraph.Format.Font.Color  = Colors.LightBlue;
            paragraph.Format.SpaceBefore = "1cm";
            paragraph.Format.SpaceAfter  = "1cm";

            paragraph = section.AddParagraph("Data utworzenia: " + DateTime.Now.ToString());
            paragraph.Format.Font.Size   = 12;
            paragraph.Format.Font.Color  = Colors.LightBlue;
            paragraph.Format.SpaceBefore = "3cm";
            paragraph.Format.SpaceAfter  = "1cm";
        }
        /// <summary>
        /// Describes how an image should be added to a page section.
        /// </summary>
        /// <param name="section"></param>
        /// <param name="imageDef"></param>
        /// <param name="pageWidth"></param>
        private static void AddImage(Section section, ImageDefinition imageDef, Unit pageWidth)
        {
            Unit originalImageWidthInches;

            // work around to get image dimensions

            using (System.Drawing.Image userImage = System.Drawing.Image.FromFile(imageDef.ImagePath))
            {
                // get image width in inches
                var imageInches = userImage.Width / userImage.VerticalResolution;
                originalImageWidthInches = new Unit(imageInches, UnitType.Inch);
            }

            // add image
            Image image = section.AddImage(imageDef.ImagePath);

            // Calculate Image size:
            // if actual image size is larger than PageWidth - margins, set image width as page width - margins
            Unit actualPageContentWidth = new Unit((pageWidth.Inch - section.PageSetup.LeftMargin.Inch - section.PageSetup.RightMargin.Inch), UnitType.Inch);

            if (imageDef.ImageWidthInCm > 0 && imageDef.ImageWidthInCm < actualPageContentWidth.Centimeter)
            {
                image.Width = new Unit(imageDef.ImageWidthInCm, UnitType.Centimeter);
            }
            else if (originalImageWidthInches > actualPageContentWidth)
            {
                image.Width = actualPageContentWidth;
            }

            if (imageDef.LockAspectRatio)
            {
                image.LockAspectRatio = imageDef.LockAspectRatio;
            }
            else if (imageDef.ImageHeightInCm > 0)
            {
                image.Height = new Unit(imageDef.ImageHeightInCm, UnitType.Centimeter);
            }

            if (imageDef.Alignment == HorizontalAlignmentEnum.Center || imageDef.Alignment == HorizontalAlignmentEnum.Justify)
            {
                image.Left = ShapePosition.Center;
            }
            else
            {
                image.Left = imageDef.Alignment.ConvertEnum <ShapePosition>();
            }
        }
Example #26
0
        public void AddImage(string filePath)
        {
            var img = _currentSection.AddImage(filePath);

            img.RelativeHorizontal = RelativeHorizontal.Page;
            img.RelativeVertical   = RelativeVertical.Page;

            img.Top  = 0;
            img.Left = 0;

            img.Height = _currentDocument.DefaultPageSetup.PageHeight;
            img.Width  = _currentDocument.DefaultPageSetup.PageWidth;

            _currentSection.AddPageBreak();

            Images.Add(filePath);
        }
Example #27
0
        /// Defines the cover page.  DONE
        static void DefineCover(Document document)
        {
            Section section = document.AddSection();

            Paragraph paragraph = section.AddParagraph("Cover Sheet", "Hidden");

            paragraph.Format.OutlineLevel = OutlineLevel.Level1;

            paragraph.Format.SpaceAfter = "3cm";

            // adding the LOGO
            Image image = section.AddImage("NorcoLogo.png");

            image.Width = "10cm";
            image.Left  = ShapePosition.Center;

            // report title
            paragraph = section.AddParagraph("Battery Resistance Testing Report");
            paragraph.Format.Alignment      = ParagraphAlignment.Center;
            paragraph.Format.Font.Size      = 30;
            paragraph.Format.Font.Color     = Colors.Black;
            paragraph.Format.Font.Bold      = true;
            paragraph.Format.Font.Underline = Underline.Single;
            paragraph.Format.SpaceBefore    = "3cm";
            paragraph.Format.SpaceAfter     = "1cm";

            // test location
            paragraph = section.AddParagraph(currentResult.location);
            paragraph.Format.Alignment   = ParagraphAlignment.Center;
            paragraph.Format.Font.Size   = 22;
            paragraph.Format.Font.Color  = Colors.Black;
            paragraph.Format.SpaceBefore = "3cm";
            paragraph.Format.SpaceAfter  = "1cm";

            // test battery system
            paragraph = section.AddParagraph(currentResult.batteryName);
            paragraph.Format.Alignment  = ParagraphAlignment.Center;
            paragraph.Format.Font.Size  = 22;
            paragraph.Format.Font.Color = Colors.Black;
            //paragraph.Format.SpaceBefore = "3cm";
            paragraph.Format.SpaceAfter = "5cm";
            paragraph = section.AddParagraph("Report Generated on : ");
            paragraph.AddDateField();
        }
Example #28
0
    /// <summary>
    /// Defines the cover page.
    /// </summary>
    public static void DefineCover(Document document)
    {
      Section section = document.AddSection();

      Paragraph paragraph = section.AddParagraph();
      paragraph.Format.SpaceAfter = "3cm";

      Image image = section.AddImage("../../images/Logo landscape.png");
      image.Width = "10cm";

      paragraph = section.AddParagraph("A sample document that demonstrates the\ncapabilities of MigraDoc");
      paragraph.Format.Font.Size = 16;
      paragraph.Format.Font.Color = Colors.DarkRed;
      paragraph.Format.SpaceBefore = "8cm";
      paragraph.Format.SpaceAfter = "3cm";

      paragraph = section.AddParagraph("Rendering date: ");
      paragraph.AddDateField();
    }
Example #29
0
        /// <summary>Creates the graph page.</summary>
        /// <param name="section">The section to write to.</param>
        /// <param name="graphPage">The graph and table to convert to html.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void CreateGraphPage(Section section, GraphPage graphPage, string workingDirectory)
        {
            int numColumns = 2;
            int numRows    = 3;

            // Export graph to bitmap file.
            Bitmap image = new Bitmap(700, 850);

            GraphPresenter graphPresenter = new GraphPresenter();
            GraphView      graphView      = new GraphView();

            graphView.BackColor  = System.Drawing.Color.White;
            graphView.FontSize   = 10;
            graphView.MarkerSize = 4;
            graphView.Width      = image.Width / numColumns;
            graphView.Height     = image.Height / numRows;

            int col = 0;
            int row = 0;

            for (int i = 0; i < graphPage.graphs.Count; i++)
            {
                if (graphPage.graphs[i].IncludeInDocumentation)
                {
                    graphPresenter.Attach(graphPage.graphs[i], graphView, ExplorerPresenter);
                    Rectangle r = new Rectangle(col * graphView.Width, row * graphView.Height,
                                                graphView.Width, graphView.Height);
                    graphView.Export(image, r, false);
                    graphPresenter.Detach();
                    col++;
                    if (col >= numColumns)
                    {
                        col = 0;
                        row++;
                    }
                }
            }

            string PNGFileName = Path.Combine(workingDirectory, graphPage.name + ".png");

            image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
            section.AddImage(PNGFileName);
        }
Example #30
0
        public static void printPicture(Picture p)
        {
            Document doc      = new Document();
            Section  section1 = doc.AddSection();

            MigraDoc.DocumentObjectModel.Shapes.Image image = section1.AddImage(Conversion.MigrDocFilenameFromBase64(p.Image));
            image.Width           = "16cm";
            image.LockAspectRatio = true;
            Paragraph paragraph1 = section1.AddParagraph();

            paragraph1.AddFormattedText("Photographer: ", TextFormat.Bold);
            if (p.Photographer != null)
            {
                paragraph1.AddText(p.Photographer.ToString() + "\n\n");
            }
            else
            {
                paragraph1.AddText("-" + "\n\n");
            }
            Paragraph paragraph2 = section1.AddParagraph();

            paragraph2.AddFormattedText("EXIF Properties:\n", TextFormat.Bold);
            paragraph2.AddText(PrintableExifProperties(p));
            paragraph2.AddFormattedText("IPTC Properties:\n", TextFormat.Bold);
            paragraph2.AddText(PrintableIptcProperties(p));
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);

            pdfRenderer.Document = doc;
            pdfRenderer.RenderDocument();

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.CheckFileExists = false;
            var result = dialog.ShowDialog();

            if (result == false)
            {
                return;
            }
            pdfRenderer.PdfDocument.Save(dialog.FileName);
        }