예제 #1
1
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);

            gfx.Restore(state);
        }
예제 #2
0
        public void DrawImages(XGraphics gfx, int number, string type = "QR")
        {
            string path = "";

            if (type == "QR")
            {
                BeginBox(gfx, number, $"{place}");
                path = $"qr{ticketNumber}";
            }
            else if (type == "штрих")
            {
                path = "bar";
                BeginBox(gfx, number, "Штрих код");
            }
            XImage image = XImage.FromFile(Paths.CODES_FOLDER + $"{path}.png");
            double x     = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2;

            gfx.DrawImage(image, x, 0);
            EndBox(gfx);
        }
예제 #3
0
        /// <summary>
        /// Draws a form XObject (a page from an external PDF file).
        /// </summary>
        void DrawFormXObject(XGraphics gfx, int number)
        {
            //this.backColor = XColors.LightSalmon;
            BeginBox(gfx, number, "DrawImage (Form XObject)");

            XImage image = XImage.FromFile(pdfSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.35);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width  = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);

            EndBox(gfx);
        }
예제 #4
0
        /// <summary>
        /// Create PDF from Image
        /// </summary>
        /// <param name="outputDocument"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        private static PdfDocument ConcatenatePDFWithImage(PdfDocument outputDocument, byte[] buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentException("No data provided", "buffer");
            }

            using (var stream = new MemoryStream(buffer))
            {
                // Create an empty page
                // Get an XGraphics object for drawing
                XGraphics gfx = XGraphics.FromPdfPage(outputDocument.AddPage());

                Image image = Image.FromStream(stream);

                XImage img = XImage.FromGdiPlusImage(image);
                gfx.DrawImage(img, 0, 0);
            }
            return(outputDocument);
        }
예제 #5
0
        void DrawImageSheared(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawImage (sheared)");

            XImage image = XImage.FromFile(jpegSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(-0.7, 0.7);
            gfx.ShearTransform(-0.4, -0.3);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width  = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, 0, width, height);

            EndBox(gfx);
        }
예제 #6
0
        private void DrawQrCode(User user, XGraphics gfx)
        {
            using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
            {
                QRCodeData qrCodeData = qrGenerator.CreateQrCode(
                    _endpointConfig.AdminPanelDetailsCandidatate(user.Id.ToString()),
                    QRCodeGenerator.ECCLevel.Q);
                using (QRCode qrCode = new QRCode(qrCodeData))
                    using (var tempStream = new MemoryStream())
                    {
                        Bitmap qrCodeImage = qrCode.GetGraphic(20);

                        qrCodeImage.Save(tempStream, ImageFormat.Png);
                        tempStream.Seek(0, SeekOrigin.Begin);
                        XImage image = XImage.FromStream(() => tempStream);

                        gfx.DrawImage(image, 100, 250, 100, 100);
                    }
            }
        }
예제 #7
0
        public void Save(string outFile, List <ImageProp> list)
        {
            _document = Open(_fileName);
            for (int i = 0; i < _document.PageCount; i++)
            {
                XGraphics gfx = XGraphics.FromPdfPage(_document.Pages[i]);

                int page = i + 1;
                foreach (var item in list.Where(item => item.Page == page))
                {
                    gfx.DrawImage(item.Bitmap, new Rectangle(
                                      (int)Math.Round(item.Left * 0.75),
                                      (int)Math.Round(item.Top * 0.75),
                                      (int)Math.Round(item.Width * 0.75),
                                      (int)Math.Round(item.Height * 0.75))
                                  );
                }
            }
            _document.Save(outFile);
        }
예제 #8
0
        private void DrawImage(XGraphics gfx, int number, string imageSamplePath)
        {
            //BeginBox(gfx, number, "DrawImage (original)");
            using (XImage image = XImage.FromFile(imageSamplePath))
            {
                try
                {
                    // Left position in point
                    double x = 10; //(250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2;
                    gfx.DrawImage(image, x, nextY);
                    //update next Y coordinate
                    nextY += image.PointHeight + 20;
                }
                catch (Exception exp)
                {
                }
            }

            //EndBox(gfx);
        }
예제 #9
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            int width  = panel1.Size.Width;
            int height = panel1.Size.Height;

            saveFileDialog1.FileName = "Baptism - " + nameOfBaptized.Text;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // --------------------FINDING FILEPATH---------------------- //
                filepath = saveFileDialog1.FileName;

                Bitmap bm = new Bitmap(width, height);
                panel1.DrawToBitmap(bm, new Rectangle(0, 0, width, height));


                string tempFolder = Path.GetTempPath();
                bm.Save(tempFolder + "//tempRep.bmp", ImageFormat.Bmp);


                // --------------------DOCUMENT---------------------- //

                PdfDocument doc  = new PdfDocument();
                PdfPage     page = new PdfPage();
                page.Height      = height;
                page.Width       = width;
                page.Orientation = PageOrientation.Portrait;
                doc.Pages.Add(page);

                // --------------------DRAWING PDF---------------------- //
                XGraphics xgr   = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage    saved = XImage.FromFile(tempFolder + "//tempRep.bmp");
                xgr.DrawImage(saved, 0, 0, width, height);

                doc.Save(filepath);
                doc.Close();
                saved.Dispose();

                this.Close();
            }
        }
예제 #10
0
        private void butExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog()
            {
                Filter           = "PDF (*.pdf)|*.pdf",
                FilterIndex      = 1,
                RestoreDirectory = true,
            };

            if (ODBuild.IsWeb())
            {
                sd.FileName = ODFileUtils.CombinePaths(Path.GetTempPath(), "chart_export.pdf");
            }
            else
            {
                if (sd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            using (PdfDocument pdfDoc = new PdfDocument()) {
                //save the chart into the memoryStream as a BitMap
                try {
                    PdfPage page = new PdfPage();
                    pdfDoc.Pages.Add(page);
                    page.Orientation = checkLandscape.Checked ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;
                    using (XGraphics xGraphics = XGraphics.FromPdfPage(page)) {
                        xGraphics.DrawImage(_bmpSheet, 0, 0, page.Width, page.Height);
                    }
                    pdfDoc.Save(sd.FileName);
                    if (ODBuild.IsWeb())
                    {
                        ThinfinityUtils.ExportForDownload(sd.FileName);
                    }
                    MessageBox.Show(Lans.g(this, "Chart saved."));
                }
                catch (Exception ex) {
                    MessageBox.Show("Chart not saved." + "\r\n" + ex.Source + "\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }
        }
예제 #11
0
        private PointF createPage(PdfDocument document, ref PdfPage page, ref XGraphics gfx)
        {
            // Create a font
            XFont font = new XFont("Verdana", FontSizeOverlay, XFontStyle.Regular);
            XSize textSize;
            String text;

            page = document.AddPage();
            page.Orientation = Orientation;
            gfx = XGraphics.FromPdfPage(page);

            if (document.PageCount == 1)
            {
                text = File.ReadAllText(versionFileName(ProjectPath));
                versionText = getVersionEntryValue(text, "version");
            }

            textSize = gfx.MeasureString(versionText, font);
            // Draw the version text
            gfx.DrawString(versionText, font, XBrushes.Black,
                    new XRect(page.Width - BorderWidthRight - textSize.Width, (BorderWidthTop - font.Height) / 2, page.Width, page.Height),
                    XStringFormats.TopLeft);


            // GC Wicard Icon
            MemoryStream memoryStream = new MemoryStream();
            Properties.Resources.circle_border_128.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
            gfx.DrawImage(XImage.FromStream(memoryStream), 5, 5, BorderWidthTop - 5, BorderWidthTop - 5);

            // Draw GC Wizard Text
            // Create a font
            font = new XFont("Verdana", FontSizeName / 2, XFontStyle.Regular);
            text = "GC Wizard";
            textSize = gfx.MeasureString(text, font);

            gfx.DrawString("GC Wizard", font, XBrushes.Black,
                new XRect(BorderWidthTop + 3, (BorderWidthTop - font.Height) / 2, page.Width, page.Height),
                XStringFormats.TopLeft);

            return new PointF(BorderWidthLeft, BorderWidthTop);
        }
예제 #12
0
        public static void AddImageToPDF()
        {
            // Create a new PDF document.
            PdfDocument document = new PdfDocument();

            // Create an empty page in this document.
            PdfPage page = document.AddPage();

            // Obtain an XGraphics object to render to
            XGraphics g = XGraphics.FromPdfPage(page);

            // Load a local image file
            XImage importImg = XImage.FromFile("image.jpg");

            // Insert an image to pdf page, position and size can be modified
            g.DrawImage(importImg, 50, 50, 200, 200);

            // Save and show the document
            document.Save("AddImage.pdf");
            Process.Start("AddImage.pdf");
        }
예제 #13
0
        public static bool Batch2PDF(NBatchInfo batch, string pdffname)
        {
            PdfDocument pdfDocument = new PdfDocument();

            pdfDocument.Info.Title   = batch.BatchNO;
            pdfDocument.Info.Author  = batch.Author;
            pdfDocument.Info.Subject = batch.Title;
            foreach (NFileInfo current in batch.FileInfos)
            {
                bool flag = FileHelper.IsImageExt(current.LocalPath);
                if (flag)
                {
                    PdfPage   page      = pdfDocument.AddPage();
                    XGraphics xGraphics = XGraphics.FromPdfPage(page);
                    XImage    xImage    = XImage.FromFile(current.LocalPath);
                    xGraphics.DrawImage(xImage, 0.0, 0.0, xImage.Width, xImage.Height);
                }
            }
            pdfDocument.Save(pdffname);
            return(true);
        }
예제 #14
0
        public void create(Image img, string title, Double widthInches, Double heightInches)
        {
            PdfDocument document = new PdfDocument();

            document.Info.Title = title;

            PdfPage page = document.AddPage();

            page.Orientation = PageOrientation.Landscape;
            page.Height      = XUnit.FromInch(heightInches);
            page.Width       = XUnit.FromInch(widthInches);
            using (XGraphics gfx = XGraphics.FromPdfPage(page))
            {
                gfx.DrawImage(img, new Point(0, 0));
            }

            const string filename = "HelloWorld2.pdf";

            document.Save(filename);
            Process.Start(filename);
        }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pdfPath">pdf的地址</param>
 /// <param name="pdfImg">图片的地址</param>
 public void CreatePDF(string pdfPath, string pdfImg)
 {
     //测试路径
     System.Drawing.Image image4 = System.Drawing.Image.FromFile(pdfImg);
     using (PdfSharp.Pdf.PdfDocument pdf = new PdfSharp.Pdf.PdfDocument())
     {
         PdfSharp.Pdf.PdfPage ss = new PdfSharp.Pdf.PdfPage(pdf);
         double w = image4.Width * 0.75;
         double h = image4.Height * 0.75;
         ss.Width  = new XUnit(w);
         ss.Height = new XUnit(h);
         pdf.AddPage(ss);
         PdfSharp.Pdf.PdfPage page = pdf.Pages[0];
         XGraphics            gfx  = XGraphics.FromPdfPage(page);
         // Draw background
         gfx.DrawImage(PdfSharp.Drawing.XImage.FromFile(pdfImg), 0, 0);
         pdf.Save(pdfPath);
         pdf.Close();
     }
     image4.Dispose();
 }
예제 #16
0
        private void button6_Click(object sender, EventArgs e)
        {
            //SetColorTextBg(Color.FromArgb(255, 255, 255));
            //CaptureScreen();
            //printDoc.DefaultPageSettings.PrinterSettings.PrinterName = "Microsoft Print to PDF";
            //printDoc.DefaultPageSettings.PrinterSettings.PrintToFile = true;
            //printDoc.DefaultPageSettings.PrinterSettings.PrintFileName = lblFolderPath.Text;
            //printDoc.Print();

            SetColorTextBg(Color.FromArgb(255, 255, 255));
            CaptureScreen();
            try
            {
                PdfDocument pdfDocument = null;
                pdfDocument = new PdfDocument();

                Bitmap   pageBitmap   = new Bitmap(827, 1259);
                Graphics pageGraphics = Graphics.FromImage(pageBitmap);

                pageGraphics.DrawImage(memoryImage1, 70, 110);
                pageGraphics.DrawImage(memoryImage2, 70, 888);

                PdfPage pdfPage = new PdfPage();

                pdfPage.Width  = XUnit.FromPoint(595.27184);
                pdfPage.Height = XUnit.FromPoint(931.88446);

                pdfDocument.AddPage(pdfPage);
                XImage    xImage    = XImage.FromGdiPlusImage(pageBitmap);
                XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage);
                xGraphics.DrawImage(xImage, 0, 0);
                pdfDocument.Save(lblFolderPath.Text);

                MessageBox.Show("The file '" + docName + ".pdf" + "' has been made.", "Note");
            }
            catch
            {
                MessageBox.Show("The file '" + docName + ".pdf" + "' can not be overwritten because it is open.Please close the file and try again.", "Note");
            }
        }
예제 #17
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //if(newLabelPosition.Y <= 0) newLabelPosition.Y = DiplomaBackground.Margin.Top + DiplomaBackground.Height - ParticipantNameLabel.ActualHeight;

            //double posY = (newLabelPosition.Y + (ParticipantNameLabel.ActualHeight / 2) - DiplomaBackground.Margin.Top) / DiplomaBackground.Height;
            //double posX = (newLabelPosition.X - DiplomaBackground.Margin.Left) / DiplomaBackground.Width;


            double posY = (ParticipantNameLabel.Margin.Top + (ParticipantNameLabel.ActualHeight / 2) - DiplomaBackground.Margin.Top) / DiplomaBackground.Height;


            Globals.database.selectFromDatabase();

            while (Globals.database.rdr.Read())
            {
                string firstName = Globals.database.rdr.GetString(0);
                string lastName  = Globals.database.rdr.GetString(1);
                string email     = Globals.database.rdr.GetString(2);

                PdfDocument document = new PdfDocument();
                PdfPage     page     = document.AddPage();
                XGraphics   graph    = XGraphics.FromPdfPage(page);
                document.Options.NoCompression = true;
                document.Options.ColorMode     = PdfColorMode.Cmyk;
                document.Version = 14;
                page.Size        = PdfSharp.PageSize.A4;

                XPdfForm pageFromExternalFile = XPdfForm.FromFile(pathToBackground);
                graph.DrawImage(pageFromExternalFile, new XRect(0, 0, pageFromExternalFile.PointWidth, pageFromExternalFile.PointHeight));

                // dodanie tekstu w PDFie
                XFont font = new XFont("Roboto Condensed Light", 40, XFontStyle.Bold);
                graph.DrawString(firstName + " " + lastName, font, XBrushes.Black, page.Width.Point / 2, page.Height.Point * posY, XStringFormats.Center);


                string fileName = pathToGeneratedPDF + "\\" + firstName + lastName + ".pdf";
                document.Save(fileName);
            }
            Globals.database.rdr.Close();
        }
예제 #18
0
        public FileResult ExportToPDF(Guid id)
        {
            const string facename = "Cambria";

            PdfDocument document = new PdfDocument();

            PdfSharpCore.Pdf.PdfPage page = document.AddPage();

            document.Info.Title    = "Student Information";
            document.Info.Author   = "Ankitkumar Singh";
            document.Info.Subject  = "Student Card";
            document.Info.Keywords = "student-card";

            XGraphics gfx  = XGraphics.FromPdfPage(page);
            XFont     font = new XFont(facename, 20, XFontStyle.BoldItalic);

            Student studentDetails = _studentRepository.GetStudent(id);

            XFont fontRegular = new XFont(facename, 14, XFontStyle.Regular);
            XFont fontBold    = new XFont(facename, 14, XFontStyle.Bold);

            gfx.DrawString("Student Card", font, XBrushes.Black, new XRect(0, 40, page.Width, page.Height), XStringFormats.TopCenter);
            gfx.DrawString("Student Id : " + studentDetails.Id, fontRegular, XBrushes.Black, 200, 140);
            gfx.DrawString("Name : " + studentDetails.FirstName + " " + studentDetails.LastName, fontBold, XBrushes.Black, 200, 165);
            gfx.DrawString("Contact : " + studentDetails.Contact, fontBold, XBrushes.Black, 200, 190);
            gfx.DrawString("Subject Id : " + studentDetails.PhdSubjectId, fontBold, XBrushes.Black, 200, 215);
            gfx.DrawString("Subject Name : " + studentDetails.phdSubject.Name, fontBold, XBrushes.Black, 200, 240);

            XImage image = XImage.FromFile("D:\\Ankitkumar-Singh\\Asp-Core-Mvc\\test finally done\\Asp-Core-Test\\Asp-Core-Test\\wwwroot\\images\\qrcode.png");

            gfx.DrawImage(image, 20, 120, 150, 150);

            const string filename = "UserIdentityCard.pdf";

            document.Save(filename);
            string ReportURL = "UserIdentityCard.pdf";

            byte[] FileBytes = System.IO.File.ReadAllBytes(ReportURL);
            return(File(FileBytes, "application/pdf"));
        }
예제 #19
0
        public void Draw(XGraphics gfx)
        {
            TransformsProvider tp = new TransformsProvider(gfx);

            if (this._rect != XRect.Empty)
            {
                XRect rect = tp.FromCmsToPts(this._rect);
                //Margen de seguridad del 5%
                rect.Inflate(-((5 * rect.Width) / 100), -((5 * rect.Height) / 100));
                try
                {
                    System.IO.Stream imgStream = this.GetType().Assembly.GetManifestResourceStream(this._rscName);
                    Image            img       = Image.FromStream(imgStream);
                    gfx.DrawImage(XImage.FromGdiPlusImage(img), rect);
                    imgStream.Close();
                }
                catch
                {
                    //Do nothing
                }
            }
        }
예제 #20
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string source     = (e.Argument as string[])[0];
                string destinaton = (e.Argument as string[])[1];

                PdfDocument doc = new PdfDocument();
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage    img = XImage.FromFile(source);
                MessageBox.Show("s: " + source);
                xgr.DrawImage(img, 0, 0);
                MessageBox.Show("d: " + destinaton);
                doc.Save(destinaton);
                doc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #21
0
        private void bt_pdf_Click(object sender, EventArgs e)
        {
            MySqlDataAdapter donnee = new MySqlDataAdapter();
            MySqlConnection  conn   = new MySqlConnection(_connectionString);

            conn.Open();
            string          sql = "select * from participant where Email = '" + cb_mail.Text + "'";
            MySqlCommand    cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();

            rdr.Read();
            string          prenom      = rdr.GetString(3);
            string          nom         = rdr.GetString(2);
            string          departement = rdr.GetString(4);
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(cb_mail.Text, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);
            Bitmap          qrCodeImage = qrCode.GetGraphic(5);
            XImage          qrXimage    = qrCodeImage;
            PdfDocument     document    = new PdfDocument();

            document.Info.Title = prenom + cb_mail.Text;
            PdfPage   page  = document.AddPage();
            XGraphics gfx   = XGraphics.FromPdfPage(page);
            XFont     font  = new XFont("Code 128", 60, XFontStyle.Regular);
            XFont     font2 = new XFont("LEMONMILK-Bold", 60, XFontStyle.Regular);

            gfx.DrawImage(qrXimage, 240, 300);
            gfx.DrawString(nom + " " + prenom, font2, XBrushes.Black,
                           new XRect(0, -350, page.Width, page.Height),
                           XStringFormats.Center);
            gfx.DrawString(departement, font2, XBrushes.Black,
                           new XRect(0, -150, page.Width, page.Height),
                           XStringFormats.Center);
            string filename = prenom + nom + "badge.pdf";

            document.Save(filename);
            Process.Start(filename);
        }
        public void WriteToPDF(UIElement element, string filename, string selectedPath)
        {
            var rect   = new Rect(element.RenderSize);
            var visual = new DrawingVisual();

            using (var dc = visual.RenderOpen())
            {
                dc.DrawRectangle(new VisualBrush(element), null, rect);
            }

            var bitmap = new RenderTargetBitmap(
                (int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Default);

            bitmap.Render(visual);

            var encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bitmap));

            using (var file = File.OpenWrite(filename))
            {
                encoder.Save(file);
                file.Close();
            }

            PdfDocument doc = new PdfDocument();

            PdfPage oPage = new PdfPage();

            doc.Pages.Add(oPage);
            //oPage.Rotate = 90;
            XGraphics xgr = XGraphics.FromPdfPage(oPage);
            XImage    img = XImage.FromFile(@filename);

            xgr.DrawImage(img, -6, -15, 980, 780);

            doc.Save(@selectedPath);
            doc.Close();
        }
예제 #23
0
        static public void hallo(double pageWidthMM, double pageHeightMM, string pdfFileName, string fileNameTemplate, int numberOfPages, bool rotateit)
        {
            double pageWidthPoint  = pageWidthMM * mmToPoint;
            double pageHeightPoint = pageHeightMM * mmToPoint;

            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            document.Info.Title = "ebook";

            for (int n = 0; n < numberOfPages; n++)
            {
                try {
                    // Create an empty page
                    PdfPage page = document.AddPage();
                    page.Width  = new XUnit(pageWidthPoint, XGraphicsUnit.Point);  //das ist intern points
                    page.Height = new XUnit(pageHeightPoint, XGraphicsUnit.Point); //das ist intern points

                    XGraphics gfx = XGraphics.FromPdfPage(page);

                    var bitmap1 = Image.FromFile(fileNameTemplate.Replace("{0}", n.ToString()));
                    if (rotateit)
                    {
                        bitmap1.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    }
                    XImage image = XImage.FromGdiPlusImage(bitmap1);
                    gfx.DrawImage(image, 0, 0, pageWidthPoint, pageHeightPoint);
                    bitmap1.Dispose();
                    image.Dispose();
                    gfx.Dispose();
                    System.Diagnostics.Debug.WriteLine("page: " + n);
                } catch (Exception e)
                {
                    var s = e.StackTrace;
                }
            }

            document.Save(pdfFileName);
        }
        private void DrawFrontPage()
        {
            FileSystemHelper.ValidateFileExists(_logoFilePath);
            XImage    logo              = XImage.FromFile(_logoFilePath);
            int       resizedLogoWidth  = Convert.ToInt32(logo.PixelWidth * 0.75);
            int       resizedLogoHeight = Convert.ToInt32(logo.PixelHeight * 0.75);
            Rectangle imageArea         = new Rectangle(_position.X, _position.Y, resizedLogoWidth, resizedLogoHeight);

            _currentGraphics.DrawImage(logo, imageArea);
            _position.X = MARGIN_LENGTH;
            _position.Y = resizedLogoHeight + TOP_MARGIN;

            _currentGraphics.DrawString("TekSpeech Pro", _productNameFont, XBrushes.SteelBlue, new PointF(300, _position.Y - (resizedLogoHeight / 2)));

            _currentGraphics.DrawString(_title, _headingFont, XBrushes.SteelBlue, new PointF(220, _position.Y));
            _position.Y += (_headingFont.Height * 2);

            DrawpProjectInfo();
            DrawSearchCriteria();
            DrawSummary();
            DrawLogFileDates();
        }
예제 #25
0
 private void DrawImage(XGraphics gfx, double x, double y, Bitmap imageR, PdfPage pdfPageData)
 {
     using (XImage image = imageR)
     {
         XRect rectangle = new XRect();
         if (image.PointHeight + y > pdfPageData.Height || image.PointWidth + x > pdfPageData.Width)
         {
             rectangle = new XRect(x, y, pdfPageData.Width - x, pdfPageData.Height - y);
         }
         else
         {
             rectangle = new XRect(x, y, image.PointWidth + x, image.PointHeight + y);
         }
         try
         {
             gfx.DrawImage(image, rectangle);
         }
         catch (Exception exp)
         {
         }
     }
 }
예제 #26
0
파일: FPdf.cs 프로젝트: paulonz/PdfManager
        private void ExecuteApplyImage()
        {
            if (cbApplyBgImage.Checked)
            {
                LoadDocuments();

                if (PdfDocuments != null && PdfDocuments.Any())
                {
                    foreach (KeyValuePair <string, PdfDocument> item in PdfDocuments)
                    {
                        if (item.Value.PageCount > 0)
                        {
                            XGraphicsPdfPageOptions position = cbApplyFrontImage.Checked ? XGraphicsPdfPageOptions.Append : XGraphicsPdfPageOptions.Prepend;
                            PdfPage   page  = item.Value.Pages[0];
                            XGraphics gfx   = XGraphics.FromPdfPage(page, position);
                            XImage    image = XImage.FromFile(txtBgImage.Text);
                            gfx.DrawImage(image, 0, 0, page.Width.Point, page.Height.Point);
                        }
                    }
                }
            }
        }
예제 #27
0
        /// <summary>
        /// Draw the texture image in the given graphics at the given location.
        /// </summary>
        public void DrawRectangle(XGraphics g, double x, double y, double width, double height)
        {
            var prevState = g.Save();

            g.IntersectClip(new XRect(x, y, width, height));

            double rx = _translateTransformLocation.X;
            double w = _image.PixelWidth, h = _image.PixelHeight;

            while (rx < x + width)
            {
                double ry = _translateTransformLocation.Y;
                while (ry < y + height)
                {
                    g.DrawImage(_image, rx, ry, w, h);
                    ry += h;
                }
                rx += w;
            }

            g.Restore(prevState);
        }
예제 #28
0
        static void DrawImageRotated(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawImage (rotated)");

            XImage image = XImage.FromFile(jpegSamplePath);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.7);
            gfx.RotateTransform(-25);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            //XMatrix matrix = new XMatrix();  //XMatrix.Identity;

            double width  = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, (dx - width) / 2, 0, width, height);

            EndBox(gfx);
        }
 internal void SaveImageAsPdf(string imageFileName, string pdfFileName, int width = 600, bool deleteImage = false)
 {
     using (var document = new PdfDocument())
     {
         PdfPage page = document.AddPage();
         using (XImage img = XImage.FromFile(imageFileName))
         {
             // Calculate new height to keep image ratio
             var height = (int)(((double)width / (double)img.PixelWidth) * img.PixelHeight);
             // Change PDF Page size to match image
             page.Width  = width;
             page.Height = height;
             XGraphics gfx = XGraphics.FromPdfPage(page);
             gfx.DrawImage(img, 0, 0, width, height);
         }
         document.Save(pdfFileName);
     }
     if (deleteImage)
     {
         File.Delete(imageFileName);
     }
 }
예제 #30
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            captureScreen();
            string date = label2.Text;
            string name = label5.Text;
            // Create new pdf document and page
            PdfDocument doc   = new PdfDocument();
            PdfPage     oPage = new PdfPage();

            // Add the page to the pdf document and add the captured image to it
            doc.Pages.Add(oPage);
            XGraphics xgr = XGraphics.FromPdfPage(oPage);
            XImage    img = XImage.FromFile(@"C:\Users\Public\Documents\test.png");

            xgr.DrawImage(img, 0, 0);

            if (System.IO.Directory.Exists(@"C:\Users\Public\Documents\Appointments"))
            {
                doc.Save(@"C:\Users\Public\Documents\Prescripts\Prescript '" + date + "'" + name + ".pdf");
            }
            else
            {
                MessageBox.Show("File not found");
            }


            doc.Close();


            // I used the Dispose() function to be able to
            // save the same form again, in case some values have changed.
            // When I didn't use the function, a GDI+ error occurred.
            img.Dispose();
            timer1.Stop();

            button1.Visible = true;
            button2.Visible = true;
        }
        private void CreatePDF(Queue <QImage> images)
        {
            if (images.Count == 0)
            {
                return;
            }

            this.SendStatus("Creating pdf documents");

            PdfDocument document = new PdfDocument();

            foreach (var img in images)
            {
                if (!img.IsSeparator)
                {
                    PdfPage page = document.AddPage();

                    XGraphics gfx   = XGraphics.FromPdfPage(page);
                    XImage    image = XImage.FromGdiPlusImage(img.Image);

                    double resize = img.Image.Width / 500d;
                    gfx.DrawImage(image, 50, 50, 500, img.Image.Height / resize);
                }
            }

            string docName = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-fff") + ".pdf";

            if (!this.SendDocument(document, docName))
            {
                document.Save(Path.Combine(ConfigurationManager.AppSettings["DropFolder"], docName));
            }

            // We can dispose images in previous loop but it is safier to do it once document is saved.
            foreach (var img in images)
            {
                this.DoneImage(img);
            }
        }