Esempio n. 1
0
        public static ExtentSize getSize(this Bitmap image, eImageSize size)
        {
            // ширина изображения 7 или 9 сантиметров
            var    cm     = 360000; //единица измерения EMU   1см = 360000EMU
            double height = ((size == eImageSize.Size_7 ? 7.0 : 9.0) * image.Height) / image.Width;

            var size_out = new ExtentSize()
            {
                CxValue = size == eImageSize.Size_7 ? 2520000L : 3240000L,
                CyValue = (Int64)(height * cm)
            };

            return(size_out);
        }
Esempio n. 2
0
        Paragraph _image_paragraph(Bitmap original, MainDocumentPart mainPart, eImageSize size = eImageSize.Size_7)
        {
            string file = _generateTempFilePath();

            using (FileStream fs = File.Create(file))
            {
                original
                .Resize(eImageSize.Size_7)
                .Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
            }

            ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

            using (FileStream stream = new FileStream(file, FileMode.Open))
            {
                imagePart.FeedData(stream);
            }
            var relationshipId = mainPart.GetIdOfPart(imagePart);
            /////////////----------------
            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphAddition = "00167D1F", RsidParagraphProperties = "00080948", RsidRunAdditionDefault = "00167D1F"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties()
            {
                SpacingBetweenLines = new SpacingBetweenLines()
                {
                    After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto
                },
                Justification = new Justification()
                {
                    Val = JustificationValues.Both
                }
            };
            ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();

            paragraphMarkRunProperties1.Append(new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            });
            paragraphMarkRunProperties1.Append(new FontSize()
            {
                Val = "28"
            });

            paragraphProperties1.Append(paragraphMarkRunProperties1);

            Run run1 = new Run()
            {
                RsidRunProperties = "00167D1F",
                RunProperties     = new RunProperties()
                {
                    NoProof  = new NoProof(),
                    RunFonts = new RunFonts()
                    {
                        Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
                    },
                    FontSize = new FontSize()
                    {
                        Val = "28"
                    }
                }
            };
            /////////////----------------

            var ext = original.getSize(size);

            var element =
                new Drawing(
                    new Wp.Inline(
                        new Wp.Extent()
            {
                Cx = ext.CxValue, Cy = ext.CyValue
            },
                        new Wp.EffectExtent()
            {
                LeftEdge   = 0L,
                TopEdge    = 0L,
                RightEdge  = 0L,
                BottomEdge = 0L
            },
                        new Wp.DocProperties()
            {
                Id   = (UInt32Value)1U,
                Name = "Picture 1"
            },
                        new Wp.NonVisualGraphicFrameDrawingProperties(
                            new A.GraphicFrameLocks()
            {
                NoChangeAspect = true
            }),
                        new A.Graphic(
                            new A.GraphicData(
                                new Pic.Picture(
                                    new Pic.NonVisualPictureProperties(
                                        new Pic.NonVisualDrawingProperties()
            {
                Id   = (UInt32Value)0U,
                Name = "New Bitmap Image.jpg"
            },
                                        new Pic.NonVisualPictureDrawingProperties()),
                                    new Pic.BlipFill(
                                        new A.Blip(
                                            new A.BlipExtensionList(
                                                new A.BlipExtension()
            {
                Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
            })
                                            )
            {
                Embed            = relationshipId,
                CompressionState = A.BlipCompressionValues.Print
            },
                                        new A.Stretch(
                                            new A.FillRectangle())),
                                    new Pic.ShapeProperties(
                                        new A.Transform2D(
                                            new A.Offset()
            {
                X = 0L, Y = 0L
            },
                                            new A.Extents()
            {
                Cx = ext.CxValue, Cy = ext.CyValue
            }
                                            ),
                                        new A.PresetGeometry(
                                            new A.AdjustValueList()
                                            )
            {
                Preset = A.ShapeTypeValues.Rectangle
            }))
                                )
            {
                Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"
            })
                        )
            {
                DistanceFromTop    = (UInt32Value)0U,
                DistanceFromBottom = (UInt32Value)0U,
                DistanceFromLeft   = (UInt32Value)0U,
                DistanceFromRight  = (UInt32Value)0U,
                EditId             = "50D07946"
            });


            run1.Append(element);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);

            File.Delete(file);

            return(paragraph1);
        }