private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Load the document from disk.
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\AddSeamSeals.pdf");

            PdfUnitConvertor convert  = new PdfUnitConvertor();
            PdfPageBase      pageBase = null;

            //Get the segmented seal image.
            Image[] images = GetImage(doc.Pages.Count);
            float   x      = 0;
            float   y      = 0;

            //Draw the picture to the designated location on the PDF page.
            for (int i = 0; i < doc.Pages.Count; i++)
            {
                pageBase = doc.Pages[i];
                x        = pageBase.Size.Width - convert.ConvertToPixels(images[i].Width, PdfGraphicsUnit.Point) + 40;
                y        = pageBase.Size.Height / 2;
                pageBase.Canvas.DrawImage(PdfImage.FromImage(images[i]), new PointF(x, y));
            }

            String result = "AddSeamSeals_out.pdf";

            //Save the Pdf file.
            doc.SaveToFile(result);

            //Launch the Pdf file.
            PDFDocumentViewer(result);
        }
Exemple #2
0
        private void CreateDocument(object s)
        {
            if (chkPdfA == "on")
            {
                //Create a PDF document in PDF_A1B standard
                Pdfdoc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            }
            else
            {
                //Create a PDF document
                Pdfdoc = new PdfDocument();
            }

            //Set page margins
            Pdfdoc.PageSettings.SetMargins(float.Parse(pagemargin));

            //Set page orientation
            if (rdbtnOrientation == "Portrait")
            {
                Pdfdoc.PageSettings.Orientation = PdfPageOrientation.Portrait;
            }
            else
            {
                Pdfdoc.PageSettings.Orientation = PdfPageOrientation.Landscape;
            }

            //Set rotation
            Pdfdoc.PageSettings.Rotate = (PdfPageRotateAngle)Enum.Parse(typeof(PdfPageRotateAngle), rotate);

            PdfPage          page      = null;
            SizeF            pageSize  = SizeF.Empty;
            PdfUnitConvertor convertor = new PdfUnitConvertor();
            float            width     = -1;
            float            height    = -1;


            page = Pdfdoc.Pages.Add();

            pageSize = page.GetClientSize();

            width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);


            //Adding Header
            if (showHeader == "on")
            {
                this.AddHtmlHeader(Pdfdoc, "Syncfusion Essential PDF", " ");
            }

            //Adding Footer
            if (showFooter == "on")
            {
                this.AddHtmlFooter(Pdfdoc, "@Copyright 2008");
            }

            HtmlConverter html = new HtmlConverter();

            // setting Javascript
            html.EnableJavaScript = chkEnableJavaScript == "on" ? true : false;
            //// Setting Pagebreak
            html.AutoDetectPageBreak = activatePageBreak == "on" ? true : false;
            //// set hyperlink
            html.EnableHyperlinks = chkEnableHyperlink == "on" ? true : false;

            if (convertType == "Metafile")
            {
                HtmlToPdfResult result = html.Convert(sourceUrl, Syncfusion.HtmlConverter.ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);

                if (result != null)
                {
                    PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
                    mf.Quality = 100;

                    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
                    format.Break  = PdfLayoutBreakType.FitPage;
                    format.Layout = PdfLayoutType.Paginate;
                    Pdfdoc.PageSettings.Height = result.RenderedImage.Size.Height;
                    format.SplitTextLines      = chkSplitText == "on" ? true : false;
                    format.SplitImages         = splitImage == "on" ? true : false;

                    result.Render(page, format);
                }
                else
                {
                    Response.Write("Warning ! Please check the HTML link");
                }
            }
            else if (convertType == "Bitmap")
            {
                using (System.Drawing.Image img = html.ConvertToImage(sourceUrl, Syncfusion.HtmlConverter.ImageType.Bitmap, (int)width, -1, AspectRatio.KeepWidth))
                {
                    if (img != null)
                    {
                        PdfImage        image  = new PdfBitmap(img);
                        PdfLayoutFormat format = new PdfLayoutFormat();
                        format.Break  = PdfLayoutBreakType.FitPage;
                        format.Layout = PdfLayoutType.Paginate;
                        if (img.Size.Width > pageSize.Width)
                        {
                            //Bitmap
                            image.Draw(page, new RectangleF(0, 0, pageSize.Width, pageSize.Height), format);
                        }
                        else
                        {
                            //Bitmap
                            image.Draw(page, new RectangleF(0, 0, img.Width, img.Height), format);
                        }
                    }
                    else
                    {
                        Response.Write("Warning ! Please check the HTML link");
                    }
                }
            }
        }