示例#1
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            // Create a new instance of PdfDocument class.
            PdfDocument document = new PdfDocument();

            // Add a new page to the newly created document.
            PdfPage page = document.Pages.Add();

            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);

            PdfGraphics g = page.Graphics;

            g.DrawString("JPEG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 40));

            //Load JPEG image to stream.
            Stream jpgImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Xamarin_JPEG.jpg");

            //Load the JPEG image
            PdfImage jpgImage = new PdfBitmap(jpgImageStream);

            //Draw the JPEG image
            g.DrawImage(jpgImage, new Syncfusion.Drawing.RectangleF(0, 70, 515, 215));

            g.DrawString("PNG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 355));

            //Load PNG image to stream.
            Stream pngImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Xamarin_PNG.png");

            //Load the PNG image
            PdfImage pngImage = new PdfBitmap(pngImageStream);

            //Draw the PNG image
            g.DrawImage(pngImage, new Syncfusion.Drawing.RectangleF(0, 365, 199, 300));

            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            document.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            document.Close(true);

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("ImageInsertion.pdf", "application/pdf", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("ImageInsertion.pdf", "application/pdf", stream);
            }
        }
        public ActionResult ImageInsertion(string Browser)
        {
            string dataPath = _hostingEnvironment.WebRootPath + @"/PDF/";

            // Create a new instance of PdfDocument class.
            PdfDocument document = new PdfDocument();

            // Add a new page to the newly created document.
            PdfPage page = document.Pages.Add();

            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);

            PdfGraphics g = page.Graphics;

            g.DrawString("JPEG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 40));

            //Load JPEG image to stream.
            FileStream jpgImageStream = new FileStream(dataPath + "Xamarin_JPEG.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Load the JPEG image
            PdfImage jpgImage = new PdfBitmap(jpgImageStream);

            //Draw the JPEG image
            g.DrawImage(jpgImage, new Syncfusion.Drawing.RectangleF(0, 70, 515, 215));

            g.DrawString("PNG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 355));

            //Load PNG image to stream.
            FileStream pngImageStream = new FileStream(dataPath + "Xamarin_PNG.png", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Load the PNG image
            PdfImage pngImage = new PdfBitmap(pngImageStream);

            g.DrawImage(pngImage, new Syncfusion.Drawing.RectangleF(0, 365, 199, 300));

            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            document.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            document.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "ImageInsertion.pdf";
            return(fileStreamResult);
        }
示例#3
0
 public byte[] ImageToPDF(Stream file)
 {
     _logger.LogDebug($"Start convert image files");
     byte[] buff;
     try
     {
         using (MemoryStream memoryStream = new MemoryStream())
             using (PdfDocument document = new PdfDocument())
             {
                 PdfPage     page        = document.Pages.Add();
                 PdfGraphics pdfGraphics = page.Graphics;
                 PdfBitmap   image       = new PdfBitmap(file);
                 pdfGraphics.DrawImage(image, 0, 0);
                 document.Save(memoryStream);
                 memoryStream.Position = 0;
                 buff = memoryStream.ToArray();
                 _logger.LogDebug("FileInfoPDFService.ImageToPDF....OK");
                 return(buff);
             }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(null);
 }
示例#4
0
 public byte[] TiffToPDF(Stream file)
 {
     _logger.LogDebug($"Start convert tiff file");
     byte[] buff;
     try
     {
         using (MemoryStream memoryStream = new MemoryStream())
             using (PdfDocument document = new PdfDocument())
             {
                 document.PageSettings.Margins.All = 0;
                 PdfTiffImage tiffImage  = new PdfTiffImage(file);
                 int          frameCount = tiffImage.FrameCount;
                 for (int i = 0; i < frameCount; i++)
                 {
                     PdfPage     page     = document.Pages.Add();
                     PdfGraphics graphics = page.Graphics;
                     tiffImage.ActiveFrame = i;
                     graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
                 }
                 document.Save(memoryStream);
                 memoryStream.Position = 0;
                 buff = memoryStream.ToArray();
                 _logger.LogDebug("FileInfoPDFService.TiffToPDF....OK");
                 return(buff);
             }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(null);
 }
示例#5
0
        public void SaveToPDF(string fileName)
        {
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
                (int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight,
                96d, 96d, PixelFormats.Pbgra32);

            GraphCanvas.Measure(new Size((int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight));
            GraphCanvas.Arrange(new Rect(new Size((int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight)));

            renderBitmap.Render(GraphCanvas);


            using (PdfDocument document = new PdfDocument())
            {
                PdfPage     page     = document.Pages.Add();
                PdfGraphics graphics = page.Graphics;

                using (var ms = new MemoryStream())
                {
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                    encoder.Save(ms);
                    PdfBitmap image = new PdfBitmap(ms);
                    graphics.DrawImage(image, 0, 0);

                    document.Save(fileName);
                }
            }
        }
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Stream            docStream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Essential_Studio.pdf");
            PdfLoadedDocument ldoc      = new PdfLoadedDocument(docStream);

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f);

            foreach (PdfPageBase lPage in ldoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.SetTransparency(0.25f);
                g.RotateTransform(-40);
                g.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));

                if (imagewatermark.IsChecked.Value)
                {
                    Stream   imagestream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif");
                    PdfImage image       = new PdfBitmap(imagestream);
                    g.Restore(state);
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    imagestream.Dispose();
                }
            }
            MemoryStream stream = new MemoryStream();
            await ldoc.SaveAsync(stream);

            ldoc.Close(true);
            Save(stream, "StampDocument.pdf");

            docStream.Dispose();
        }
示例#7
0
        public void AddImage(string imagePath, int x, int y, int w, int h)
        {
            Stream   pngImageStream = UTILS.ImageToStream(imagePath);
            PdfImage pngImage       = new PdfBitmap(pngImageStream);

            m_grapics.DrawImage(pngImage, x, y, w, h);
        }
示例#8
0
        async void ValidateSignatureAndUpload()
        {
            Dialog.ShowLoading("");

            if (Contract.SignImageSource != null)
            {
                PdfDocument duplicate = (PdfDocument)Contract.Document.Clone();


                var addPage = duplicate.Pages.Add();

                var width = addPage.GetClientSize().Width;

                PdfGraphics graphics = addPage.Graphics;

                PdfBitmap image = new PdfBitmap(new MemoryStream(contract.SignImageSource));

                graphics.DrawImage(image, new RectangleF(20, 40, width / 2, 60));


                MemoryStream m = new MemoryStream();

                duplicate.Save(m);

                var document = await StoreManager.DocumentStore.GetItemByContractId(Contract.Id, "saleContract");

                if (document == null)
                {
                    var documentItem = new Document()
                    {
                        Path = Contract.Id + '/' + "saleContract.pdf", Name = contract.Id + ".pdf", InternalName = "saleContract", ReferenceKind = "contract", ReferenceId = contract.Id, MimeType = "application/pdf"
                    };

                    var uploaded = await StoreManager.DocumentStore.InsertImage(m.ToArray(), documentItem);
                }
                else
                {
                    await PclStorage.SaveFileLocal(m.ToArray(), document.Id);

                    document.ToUpload = true;

                    await StoreManager.DocumentStore.UpdateAsync(document);

                    await StoreManager.DocumentStore.OfflineUploadSync();
                }

                Contract.ToSend = true;

                var isSent = await StoreManager.ContractStore.UpdateAsync(Contract);

                if (isSent)
                {
                    await CoreMethods.DisplayAlert(AppResources.Alert, AppResources.EmailSent, AppResources.Ok);

                    BackButton.Execute(null);
                }
            }

            Dialog.HideLoading();
        }
        static void DrawImage(PdfGraphics graphics, PdfRectangle rect, double x, double y)
        {
            Bitmap image = new Bitmap("..\\..\\AddressFormField.png");

            double aspectRatio = image.Width / image.Height;

            double scaleX = image.Width / rect.Width;
            double scaleY = image.Height / rect.Height;

            double width;
            double height;

            if (scaleX < scaleY)
            {
                width  = rect.Width;
                height = width / aspectRatio;
            }

            else
            {
                height = rect.Height;
                width  = height * aspectRatio;
            }

            RectangleF imageRect = new RectangleF((float)x, (float)(y - height), (float)width, (float)height);

            graphics.DrawImage(image, imageRect);
        }
        private void Draw(PdfGraphics g, PdfObjects.Image image)
        {
            using (var stream = new FileStream(image.ImagePath, FileMode.Open))
            {
                using (var bitmap = new PdfBitmap(stream))
                {
                    float x      = (float)image.Layout.X;
                    float y      = (float)image.Layout.Y;
                    float width  = (float)image.Layout.Width;
                    float height = (float)image.Layout.Height;

                    if (image.PreserveRatio)
                    {
                        height = bitmap.Height * (width / bitmap.Width);

                        // If we went the wrong way
                        if (height > image.Layout.Height)
                        {
                            height = (float)image.Layout.Height;
                            width  = bitmap.Width * (height / bitmap.Height);
                        }
                    }

                    g.DrawImage(bitmap, new PointF(x, y), new SizeF(width, height));
                }
            }
        }
        public async Task <IActionResult> RenderPDF()
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();
            //Add a page to the document.
            PdfPage page = doc.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            //Load the image as stream.
            FileStream imageStream = new FileStream("test.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            //Draw the image
            graphics.DrawImage(image, 0, 0);
            //Save the PDF document to stream
            MemoryStream stream = new MemoryStream();

            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Output.pdf";

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(File(stream, contentType, fileName));
        }
示例#12
0
        void IPainter.PaintImage(IndexedImage image, Point atPoint)
        {
            var bitmap = ToBitmap(image);
            var xImage = XImage.FromGdiPlusImage(bitmap);

            PdfGraphics.DrawImage(xImage, new System.Drawing.Point(atPoint.X + Shift.Width, atPoint.Y + Shift.Height));
        }
示例#13
0
        public void DrawImage(Bitmap image, string noi_luu)
        {
            using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
            {
                documentProcessor.LoadDocument(fileName);
                DevExpress.Pdf.PdfPage page = documentProcessor.Document.Pages[pdfViewer1.CurrentPageNumber - 1];
                using (PdfGraphics graphics = documentProcessor.CreateGraphics())
                {
                    float width  = (float)Math.Abs(startPosition.Point.X - endPosition.Point.X);
                    float height = (float)Math.Abs(startPosition.Point.Y - endPosition.Point.Y);

                    PdfRectangle cropbox = page.CropBox;
                    //  MessageBox.Show(cropbox.Height.ToString());
                    float Y = (float)(cropbox.Height - startPosition.Point.Y);

                    RectangleF rec = new RectangleF((float)startPosition.Point.X, Y, width, height);
                    //  RectangleF test = new RectangleF(10, 30, width, height);

                    graphics.DrawImage(image, rec);
                    graphics.AddToPageForeground(page, 72, 72);
                }


                documentProcessor.SaveDocument(noi_luu);
                LoadPDFFile(noi_luu);
            }
        }
示例#14
0
        private void crearCredencial(Persona persona)
        {
            using (PdfDocument document = new PdfDocument())
            {
                //Agrego una pagina al doc
                PdfPage page = document.Pages.Add();

                //Se generan los graficos para el PDF
                PdfGraphics graphics = page.Graphics;

                //Defino la fuente
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

                //Escribo las credenciales
                graphics.DrawString("CREDENCIAL DE EMPLEADO", font, PdfBrushes.Black, new PointF(150, 5));
                graphics.DrawString(persona.Cuil.ToString(), font, PdfBrushes.Black, new PointF(150, 30));
                graphics.DrawString("Nombre: " + persona.Nombre, font, PdfBrushes.Black, new PointF(150, 55));
                graphics.DrawString("Apellido: " + persona.Apellido, font, PdfBrushes.Black, new PointF(150, 80));
                graphics.DrawString(persona.Cargo.Area.Nombre + " - " + persona.Cargo.Nombre, font, PdfBrushes.Black, new PointF(150, 105));

                //Genero y escribo el QR
                Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
                PdfBitmap image = new PdfBitmap(qrcode.Draw(persona.Cuil.ToString(), 60));
                graphics.DrawImage(image, 0, 0);

                //Guardo el PDF
                document.Save("C://SiADi-Credenciales/Credencial " + persona.Apellido + " " + persona.Nombre + ".pdf");
                MessageBox.Show("Credencial guardada en: \nC://SiADi-Credenciales/Credencial " + persona.Apellido + " " + persona.Nombre + ".pdf", "SiADi", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private static async Task CreatePDFAsync()
        {
            PdfDocument document = new PdfDocument();
            //Add a page to the document.
            PdfPage page = document.Pages.Add();
            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;
            //Set the standard font.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            //Draw the text.
            graphics.DrawString("This is a grid", font, PdfBrushes.Black, new PointF(10, 10));

            var pdfBitmap1 = await GetPdfBitmap("watch");

            graphics.DrawImage(pdfBitmap1, 10, 60, 120, 120);

            //Creates the PdfGrid
            PdfGrid pdfGrid = new PdfGrid();

            //Adds the columns
            pdfGrid.Columns.Add();
            pdfGrid.Columns.Add();

            pdfGrid.Columns[0].Width = 50;

            //Adding grid cell style
            PdfGridCellStyle rowStyle = new PdfGridCellStyle();
            //Creating Border
            PdfBorders border = new PdfBorders();

            border.All = PdfPens.Blue;
            //setting border to the style
            rowStyle.Borders = border;

            //Adds the row and value to the cell
            for (int i = 0; i < 10; i++)
            {
                PdfGridRow pdfGridRow = pdfGrid.Rows.Add();

                pdfGrid.Rows[i].Height = 80;

                pdfGridRow.Cells[1].Value = "asdf asdf";

                //pdfGridRow.Cells[0].Style = rowStyle;
                pdfGridRow.Cells[1].Style = rowStyle;

                //Applies the image
                pdfGrid.Rows[i].Cells[0].Style.BackgroundImage = pdfBitmap1;
                pdfGrid.Rows[i].Cells[0].Value = "";
            }

            //Draws the Grid
            pdfGrid.Draw(page, new PointF(10, 200));

            await SaveFile(document);
        }
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream DigitalSignaturePDF(string RadioButtonList2, string NewPDF, string Cryptographic, string Digest_Algorithm)
        {
            MemoryStream stream_Empty = new MemoryStream();

            //Read the PFX file
            FileStream pfxFile = new FileStream(ResolveApplicationPath("PDF.pfx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            PdfDocument    doc       = new PdfDocument();
            PdfPage        page      = doc.Pages.Add();
            PdfSolidBrush  brush     = new PdfSolidBrush(Color.Black);
            PdfPen         pen       = new PdfPen(brush, 0.2f);
            PdfFont        font      = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
            PdfCertificate pdfCert   = new PdfCertificate(pfxFile, "password123");
            PdfSignature   signature = new PdfSignature(page, pdfCert, "Signature");
            FileStream     jpgFile   = new FileStream(ResolveApplicationPath("logo.png"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfBitmap      bmp       = new PdfBitmap(jpgFile);

            signature.Bounds       = new RectangleF(new PointF(5, 5), page.GetClientSize());
            signature.ContactInfo  = "*****@*****.**";
            signature.LocationInfo = "Honolulu, Hawaii";
            signature.Reason       = "I am author of this document.";
            SetCryptographicStandard(Cryptographic, signature);
            SetDigest_Algorithm(Digest_Algorithm, signature);
            if (RadioButtonList2 == "Standard")
            {
                signature.Certificated = true;
            }
            else
            {
                signature.Certificated = false;
            }
            PdfGraphics graphics = signature.Appearence.Normal.Graphics;

            string validto   = "Valid To: " + signature.Certificate.ValidTo.ToString();
            string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();

            graphics.DrawImage(bmp, 0, 0);

            doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
            doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);

            doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
            doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);

            // Save the pdf document to the Stream.
            MemoryStream stream = new MemoryStream();

            doc.Save(stream);

            //Close document
            doc.Close();

            stream.Position = 0;
            return(stream);

            return(stream_Empty);
        }
示例#17
0
        private async System.Threading.Tasks.Task PdfButtonClicked(object sender, EventArgs e)
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            //Add a page to the document
            PdfPage page = document.Pages.Add();

            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;

            //Set the standard font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

            //Draw the text
            graphics.DrawString("Zähler Art: " + zaehlerArt, font, PdfBrushes.Black, new PointF(0, 20));
            graphics.DrawString("Zähler Stände: " + ZählerStand.Text, font, PdfBrushes.Black, new PointF(0, 50));
            graphics.DrawString("Zähler Nummer: " + zaehlernummer, font, PdfBrushes.Black, new PointF(0, 85));
            if (theImage != null)
            {
                Stream imageStream = theImage.GetStream();

                PdfBitmap imageForPdf = new PdfBitmap(imageStream);

                graphics.DrawImage(imageForPdf, 0, 150, 200, 200);
            }

            Stream signatureStream = await signatureView.GetImageStreamAsync(SignatureImageFormat.Jpeg);

            PdfBitmap imageForsignature = new PdfBitmap(signatureStream);

            graphics.DrawImage(imageForsignature, 250, 150, 200, 200);

            //Save the document to the stream
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //Close the document
            document.Close(true);

            //Save the stream as a file in the device and invoke it for viewing
            DependencyService.Get <ISave>().SaveAndView("Output.pdf", "application / pdf", stream);
        }
示例#18
0
        /// <summary>
        /// Create a simple PDF document
        /// </summary>
        /// <returns>Return the created PDF document as stream</returns>
        public MemoryStream ImageInsertionPDF()
        {
            //Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Add a new page to the newly created document.
            PdfPage page = document.Pages.Add();

            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);

            PdfGraphics g = page.Graphics;

            g.DrawString("JPEG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 40));

            //Load JPEG image to stream.
            FileStream jpgImageStream = new FileStream(ResolveApplicationPath("xamarin-jpeg.jpg"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Load the JPEG image
            PdfImage jpgImage = new PdfBitmap(jpgImageStream);

            //Draw the JPEG image
            g.DrawImage(jpgImage, new Syncfusion.Drawing.RectangleF(0, 70, 515, 215));

            g.DrawString("PNG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 355));

            //Load PNG image to stream.
            FileStream pngImageStream = new FileStream(ResolveApplicationImagePath("xamarin-png.png"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Load the PNG image
            PdfImage pngImage = new PdfBitmap(pngImageStream);

            g.DrawImage(pngImage, new Syncfusion.Drawing.RectangleF(0, 365, 199, 300));

            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            document.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            document.Close(true);
            return(stream);
        }
示例#19
0
        //Transfer image
        async void OnTransferImageClicked(object sender, EventArgs e)
        {
            //scroll to the top of the page
            await ChildScrollView.ScrollToAsync(0, 0, false).ConfigureAwait(false);

            child = (Child)BindingContext;
            //Create a new PDF document
            PdfDocument document = new PdfDocument();
            //Add page to the PDF document
            PdfPage page = document.Pages.Add();
            //Create graphics instance
            PdfGraphics graphics    = page.Graphics;
            Stream      imageStream = null;

            //Captures the XAML page as image and returns the image in memory stream
            imageStream = new MemoryStream(DependencyService.Get <IScreenshotService>().Capture());

            //Load the image in PdfBitmap
            PdfBitmap image = new PdfBitmap(imageStream);


            //scroll to the second page
            await ChildScrollView.ScrollToAsync(0, 940, false).ConfigureAwait(true);


            //Add page to the PDF document
            PdfPage page2 = document.Pages.Add();
            //Create graphics instance
            PdfGraphics graphics2 = page2.Graphics;

            imageStream = new MemoryStream(DependencyService.Get <IScreenshotService>().Capture());
            PdfBitmap image2 = new PdfBitmap(imageStream);


            //Set layout property to make the element break across the pages

            PdfLayoutFormat format = new PdfLayoutFormat();

            format.Break = PdfLayoutBreakType.FitPage;

            format.Layout = PdfLayoutType.Paginate;

            //Draw the image to the page
            graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
            graphics2.DrawImage(image2, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);


            //Save the document into memory stream
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            stream.Position = 0;
            //Save the stream as a file in the device and invoke it for viewing
            DependencyService.Get <ISave>().Save("TuitionFees.pdf", "application/pdf", stream);
        }
        private void GeneratePDF_Click(object sender, RoutedEventArgs e)
        {
            //Create a new PDF document.
            PdfDocument document = new PdfDocument();
            //Add page to the PDF document.
            PdfPage page = document.Pages.Add();
            //Create font with size and style.
            PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
            //Create PDF graphics for the page.
            PdfGraphics graphics = page.Graphics;

            //Draw text to PDF page with font and location.
            graphics.DrawString("JPEG Image", font, PdfBrushes.Blue, new PointF(0, 40));
            //Get the image file stream from assembly.
            Stream jpgImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Xamarin_JPEG.jpg");
            //Create new image from stream.
            PdfImage jpgImage = new PdfBitmap(jpgImageStream);

            //Draw the JPEG image
            graphics.DrawImage(jpgImage, new RectangleF(0, 70, 515, 215));
            //Draw text to PDF page with font and location.
            graphics.DrawString("PNG Image", font, PdfBrushes.Blue, new PointF(0, 355));
            //Get the image file stream from assembly.
            Stream pngImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Xamarin_PNG.png");
            //Create new image from stream.
            PdfImage pngImage = new PdfBitmap(pngImageStream);

            //Draw the PNG image
            graphics.DrawImage(pngImage, new RectangleF(0, 375, 199, 300));

            //Creating the stream object.
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the document into stream.
                document.Save(stream);
                document.Close();

                stream.Position = 0;

                //Save the output stream as a file using file picker.
                PdfUtil.Save("ImageInsertion.pdf", stream);
            }
        }
示例#21
0
        private void btnImport_Click(object sender, System.EventArgs e)
        {
            PdfLoadedDocument lDoc = new PdfLoadedDocument(txtUrl.Tag.ToString());
            PdfFont           font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f);

            foreach (PdfPageBase lPage in lDoc.Pages)
            {
                PdfGraphics      g     = lPage.Graphics;
                PdfGraphicsState state = g.Save();
                g.SetTransparency(0.25f);
                g.RotateTransform(-40);
                g.DrawString(txtStamp.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450));
                g.Restore(state);

                if (chbWatermark.Checked)
                {
                    g.Save();
#if NETCORE
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#else
                    PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif");
#endif
                    g.SetTransparency(0.25f);
                    g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height);
                    g.Restore();
                }
            }


            lDoc.Save("Sample.pdf");

            //Message box confirmation to view the created PDF document.
            if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the PDF file using the default Application.[Acrobat Reader]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
        }
示例#22
0
        public IActionResult generatePDF()
        {
            PdfDocument doc = new PdfDocument();
            //Add a page.
            PdfPage page = doc.Pages.Add();
            //Create a PdfGrid.
            PdfGrid     pdfGrid  = new PdfGrid();
            PdfGraphics graphics = page.Graphics;
            //Load the image as stream.
            FileStream imageStream = new FileStream("wwwroot/images/logo2.png", FileMode.Open, FileAccess.Read);
            PdfBitmap  image       = new PdfBitmap(imageStream);

            graphics.DrawImage(image, 0, 0);
            PdfGridCellStyle headerStyle = new PdfGridCellStyle();

            headerStyle.Borders.All     = new PdfPen(new PdfColor(126, 151, 173));
            headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173));
            headerStyle.TextBrush       = PdfBrushes.White;
            headerStyle.Font            = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular);
            //Add values to list
            //List<object> data = new List<object>();
            var list_all = _context.Shop_items.ToList();
            //Object row1 = new { ID = "E01", Name = "Clay" };
            //Object row2 = new { ID = "E02", Name = "Thomas" };
            //Object row3 = new { ID = "E03", Name = "Andrew" };
            //Object row4 = new { ID = "E04", Name = "Paul" };
            //Object row5 = new { ID = "E05", Name = "Gray" };
            //data.Add(row1);
            //data.Add(row2);
            //data.Add(row3);
            //data.Add(row4);
            //data.Add(row5);
            //Add list to IEnumerable
            IEnumerable <object> dataTable = list_all;

            //Assign data source.
            pdfGrid.DataSource = dataTable;
            //Draw grid to the page of PDF document.
            pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10));
            //Save the PDF document to stream
            MemoryStream stream = new MemoryStream();

            doc.Save(stream);
            //If the position is not set to '0' then the PDF will be empty.
            stream.Position = 0;
            //Close the document.
            doc.Close(true);
            //Defining the ContentType for pdf file.
            string contentType = "application/pdf";
            //Define the file name.
            string fileName = "Output.pdf";

            //Creates a FileContentResult object by using the file contents, content type, and file name.
            return(File(stream, contentType, fileName));
        }
示例#23
0
        public static void AssinarDocumento()
        {
            var    arquivoEnt = $"d:\\temp\\modelo.pdf";
            var    pdf        = DSHelper.ReadContent(arquivoEnt);
            var    arquivo    = $"d:\\temp\\modeloOut.pdf";
            float  x;
            float  y;
            Stream pfxStream = File.OpenRead("MRV ENGENHARIA E PARTICIPAÇÕES S.A..pfx");
            //Creates a certificate instance from PFX file with private key.
            PdfCertificate pdfCert = new PdfCertificate(pfxStream, "zzzzz");

            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdf);

            var lista = new Dictionary <int, List <Syncfusion.Drawing.RectangleF> >();

            loadedDocument.FindText("Assinado:", out lista);

            foreach (var item in lista)
            {
                x = item.Value[0].X + 100;
                y = item.Value[0].Y;
                var page = loadedDocument.Pages[item.Key] as PdfLoadedPage;

                //aplica logo da assinatura em todas as paginas
                if (page != null)
                {
                    Stream      seloStream     = File.OpenRead("SeloMrv.jpg");
                    PdfBitmap   signatureImage = new PdfBitmap(seloStream);
                    PdfGraphics gfx            = page.Graphics;
                    gfx.DrawImage(signatureImage, x, y, 90, 80);
                }

                //Applica o certificado somente na ultima pagina
                if (item.Value == lista[lista.Keys.Count - 1])
                {
                    //Creates a signature field.
                    PdfSignatureField signatureField = new PdfSignatureField(page, "AssinaturaMRV");
                    signatureField.Bounds    = new Syncfusion.Drawing.RectangleF(x, item.Value[0].Y, 50, 50);
                    signatureField.Signature = new PdfSignature(page, "MRV Engenharia");
                    //Adds certificate to the signature field.
                    signatureField.Signature.Certificate = pdfCert;
                    signatureField.Signature.Reason      = "Assinado pela MRV Engenharia";

                    //Adds the field.
                    loadedDocument.Form.Fields.Add(signatureField);
                }
            }
            //Saves the certified PDF document.
            using (FileStream fileOut = new FileStream(arquivo, FileMode.Create))
            {
                loadedDocument.Save(fileOut);
                loadedDocument.Close(true);
            }
            //return arquivo;
        }
示例#24
0
        /// <summary>
        /// Genera el Header en el documento especificado
        /// </summary>
        /// <param name="document">Documento PDF</param>
        /// <param name="title">Titulo del reporte</param>
        /// <returns>Documento PDF modificado</returns>
        internal static PdfDocument GenerateHeader(PdfDocument document, string title)
        {
            foreach (PdfPage page in document.Pages)
            {
                PdfGraphics graphics = page.Graphics;

                // Logo

                PdfImage image = new PdfBitmap("Logo.png");

                float PageWidth  = (float)Helper.MM2PX(60);
                float PageHeight = (float)Helper.MM2PX(30);
                float myWidth    = image.Width;
                float myHeight   = image.Height;

                float shrinkFactor;

                if (myWidth > PageWidth)
                {
                    shrinkFactor = myWidth / PageWidth;
                    myWidth      = PageWidth;
                    myHeight     = myHeight / shrinkFactor;
                }

                if (myHeight > PageHeight)
                {
                    shrinkFactor = myHeight / PageHeight;
                    myHeight     = PageHeight;
                    myWidth      = myWidth / shrinkFactor;
                }

                float XPosition = ((float)Helper.MM2PX(80) - myWidth) / 2;
                float YPosition = ((float)Helper.MM2PX(40) - myHeight) / 2;

                graphics.DrawImage(image, XPosition, YPosition, myWidth, myHeight);

                // Titulo.
                graphics.DrawRectangle(
                    new PdfPen(new PdfColor(0, 0, 0), 0.5F),
                    new RectangleF((float)Helper.MM2PX(10), (float)Helper.MM2PX(40), (float)Helper.MM2PX(60), (float)Helper.MM2PX(12)));
                graphics.DrawRectangle(
                    new PdfPen(new PdfColor(0, 0, 0), 0.5F),
                    new RectangleF((float)Helper.MM2PX(11), (float)Helper.MM2PX(41), (float)Helper.MM2PX(58), (float)Helper.MM2PX(10)));
                graphics.DrawString(
                    title,
                    new PdfTrueTypeFont("Ubuntu-Regular.ttf", 21),
                    PdfBrushes.Black,
                    new RectangleF((float)Helper.MM2PX(11), (float)Helper.MM2PX(41), (float)Helper.MM2PX(58), (float)Helper.MM2PX(10)),
                    new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));
            }

            return(document);
        }
示例#25
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.Pages.Add();
            PdfGraphics graphics = page.Graphics;
            PdfBitmap   image    = new PdfBitmap(Server.MapPath("~/Images/Yogesh.jpg"));

            //graphics.DrawImage(image, new PointF(0, 0));
            //graphics.DrawImage(image, 0, 0);
            //graphics.DrawImage(image, new PointF(100, 100), new Size(200, 200));
            graphics.DrawImage(image, 100, 50, 300, 200);
            document.Save("Second.pdf", HttpContext.Current.Response, HttpReadType.Save);
            document.Close();
        }
        public ActionResult GenerateGuide(int id)
        {
            Module module = moduleService.FindById(id, new String[] { "Teacher" });

            using (MemoryStream ms = new MemoryStream())
            {
                FileStream imageStream = new FileStream("./wwwroot/images/logo.png", FileMode.Open,
                                                        FileAccess.Read);

                PdfBitmap image = new PdfBitmap(imageStream);

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

                //Add a page to the document
                PdfPage page = document.Pages.Add();

                //Create PDF graphics for the page
                PdfGraphics graphics = page.Graphics;

                //Set the standard font
                PdfFont headerFont = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
                PdfFont font       = new PdfStandardFont(PdfFontFamily.Helvetica, 13);

                //Header
                graphics.DrawString(String.Format("Academie voor Engineering en ICT"), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
                graphics.DrawString(String.Format("Opleiding Informatica"), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 20));
                graphics.DrawImage(image, 350, 0, 150, 50);

                //Body
                graphics.DrawString(String.Format("Leerwijzer - {0}", module.Name), headerFont, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 100));
                graphics.DrawString(String.Format("Osiris Code - {0}", module.OsirisCode), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 150));

                PdfTextElement textElement = new PdfTextElement(module.Description, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
                textElement.Draw(page, new RectangleF(0, 200, page.GetClientSize().Width, page.GetClientSize().Height));

                //Footer
                graphics.DrawString(String.Format("Verantwoordelijke docent: {0}", module.Teacher.FullName), font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, page.GetClientSize().Height - 50));
                //Saving the PDF to the MemoryStream

                document.Save(ms);

                //Set the position as '0'.
                ms.Position = 0;

                return(File(ms.GetBuffer(), "application/pdf", String.Format("{0}_Leerwijzer_{0}_{1}.pdf", module.OsirisCode, module.Name, DateTime.Now)));
            }
        }
        public async void GeneratePdf(Promotion promotion)
        {
            if (promotion == null)
            {
                throw new ArgumentNullException(nameof(promotion));
            }

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

            //Document settings
            document.PageSettings.Orientation = PdfPageOrientation.Landscape;
            document.PageSettings.Margins.All = 100;
            //Add a page to the document.
            PdfPage page = document.Pages.Add();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            //Set the title font
            PdfFont titleFont = new PdfStandardFont(PdfFontFamily.Helvetica, 25);
            //Set the standard font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15);

            //Draw title
            graphics.DrawString(promotion.Title, titleFont, PdfBrushes.Black, new PointF(0, 0));
            //Draw description
            graphics.DrawString(promotion.Description, font, PdfBrushes.Black, new PointF(0, 25));

            //Load the image as stream.
            Stream    imageStream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("GentApp.Assets.barcode.png");
            PdfBitmap image       = new PdfBitmap(imageStream);

            //Draw the image
            graphics.DrawImage(image, 200, 100);

            //Save the PDF document to stream.
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            //Close the document.
            document.Close(true);
            //Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.
            PdfHelper.Save(stream, promotion.Title + ".pdf");
        }
示例#28
0
        private void InsertChart(PdfPage questionlistPage, PdfLayoutResult afterResult, PdfDocument document, PdfTextElement textelement, PdfGraphics graphics, RapportVragenlijstVM answerlist)
        {
            try
            {
                //Chart
                CreateChart(questionlistPage, afterResult, textelement, answerlist);

                string    path  = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\chart.png";
                PdfBitmap image = new PdfBitmap(path);
                graphics.DrawImage(image, new RectangleF(6, afterResult.Bounds.Bottom + 100, 500, 80));

                //PdfBitmap image = new PdfBitmap(File.Open("chart.png"));
                //image.Draw(page, 10, result.Bounds.Bottom + 60);
            }
            catch (Exception e)
            {
                MessageBox.Show("Er ging iets fout bij het genereren van de diagram.", "Waarschuwing");
            }
        }
示例#29
0
        /// <summary>
        /// Draws header to the document.
        /// </summary>
        private PdfPageTemplateElement AddHeader(float width, string title, string description)
        {
            RectangleF rect = new RectangleF(0, 0, width, 50);
            //Create a new instance of PdfPageTemplateElement class.
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect);
            PdfGraphics            g      = header.Graphics;

            //Draw the image in the Header.
            SizeF imageSize = new SizeF(110f, 27f);
            //Locating the logo on the right corner.
            PointF   imageLocation = new PointF(width - imageSize.Width - 20, (int)(rect.Height / 4));
            PdfImage img           = new PdfBitmap(@"../../Resources/syncfusion_logo.gif");

            g.DrawImage(img, imageLocation, imageSize);

            //Draw title.
            PdfFont       font  = new PdfTrueTypeFont(new Font("Helvetica", 16, FontStyle.Bold), true);
            PdfSolidBrush brush = new PdfSolidBrush(Color.FromArgb(44, 71, 120));
            float         x     = (width / 2) - (font.MeasureString(title).Width) / 2;

            g.DrawString(title, font, brush, new RectangleF(x, (rect.Height / 4) + 3, font.MeasureString(title).Width, font.Height));

            //Draw description
            brush = new PdfSolidBrush(Color.Gray);
            font  = new PdfTrueTypeFont(new Font("Helvetica", 6, FontStyle.Bold), true);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom);

            g.DrawString(description, font, brush, new RectangleF(0, 0, header.Width, header.Height - 8), format);

            //Draw some lines in the header
            PdfPen pen = new PdfPen(Color.DarkBlue, 0.7f);

            g.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(Color.DarkBlue, 2f);
            g.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            g.DrawLine(pen, 0, header.Height, header.Width, header.Height);

            return(header);
        }
示例#30
0
        static void Main(string[] args)
        {
            // Create a new PDF document
            PdfDocument doc = new PdfDocument();
            //Add a page to the document
            PdfPage page = doc.Pages.Add();
            //Get page size to draw image which fits the page
            SizeF pageSize = page.GetClientSize();
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            //Load the image from the disk
            PdfBitmap image = new PdfBitmap("F:\visualbasic images.s1.jpg");

            //Draw the image
            graphics.DrawImage(image, new RectangleF(0, 0, pageSize.Width, pageSize.Height));
            //Save the document
            doc.Save("OutputImage.pdf");
            //Close the document
            doc.Close(true);
            //This will open the PDF file so, the result will be seen in default PDF viewer
            Process.Start("OutputImage.pdf");
        }