示例#1
0
    internal PdfNewDocument method_10(List <Image> A_0)
    {
        if (A_0 == null)
        {
            return(null);
        }
        int count = A_0.Count;
        int num2  = (count > 90) ? 3 : ((count > 60) ? 5 : ((count > 30) ? 10 : count));

        this.pdfNewDocument_0 = this.method_12();
        for (int i = 0; i < count; i++)
        {
            using (Image image = A_0[i])
            {
                PdfNewPage page = this.method_14(new SizeF(image.Width * 0.75f, image.Height * 0.75f)).get_Pages().Add();
                this.pdfPageBase_0 = page;
                using (PdfMetafile metafile = PdfImage.FromImage(image))
                {
                    metafile.set_Quality((long)this.int_0);
                    metafile.ᜀ(page, new RectangleF(PointF.Empty, page.get_Size()), true, this.method_1().EmbeddedFontNameList, this.method_1().IsEmbeddedAllFonts);
                    metafile.Dispose();
                }
                image.Dispose();
            }
            if ((i % num2) == 0)
            {
                GC.Collect();
            }
        }
        return(this.pdfNewDocument_0);
    }
        private void ButtonToPDF_Click(object sender, RoutedEventArgs e)
        {
            string filename_pdf = TempFile.GenerateTempFilename("pdf");

            using (PdfDocument doc = new PdfDocument())
            {
                PdfPage page   = doc.Pages.Add();
                SizeF   bounds = page.GetClientSize();

                string filename_rtf = SaveToRTF();
                string text         = File.ReadAllText(filename_rtf);

                PdfMetafile             metafile = (PdfMetafile)PdfImage.FromRtf(text, bounds.Width, PdfImageType.Metafile);
                PdfMetafileLayoutFormat format   = new PdfMetafileLayoutFormat();

                // Allow the text to flow multiple pages without any breaks.
                format.SplitTextLines = true;
                format.SplitImages    = true;

                // Draw the image.
                metafile.Draw(page, 0, 0, format);

                doc.Save(filename_pdf);
            }

            Process.Start(filename_pdf);
        }
示例#3
0
        static void Main(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                Console.WriteLine("Usage:\n\tEmfToPdf <input.emf> [output.pdf]\n");
                return;
            }

            var inputEmfFilePath = args[0];
            var outputFilepath   = args.Length == 2 ? args[1] : Path.ChangeExtension(inputEmfFilePath, ".pdf");

            using (var pdfDocument = new PdfDocument())
            {
#if true
                var page = pdfDocument.Pages.Add();
#else
                var section = pdfDocument.Sections.Add();
                section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;
                var page = section.Pages.Add();
#endif
                var graphics = page.Graphics;

                var format = new PdfMetafileLayoutFormat
                {
                    SplitImages    = true,
                    SplitTextLines = true,
                };

                var metafile = new PdfMetafile(inputEmfFilePath);
                metafile.Draw(page, PointF.Empty, format);

                pdfDocument.Save(outputFilepath);
            }
        }
示例#4
0
    private PdfNewDocument method_26(Class195 A_0)
    {
        this.method_15(A_0);
        int count = A_0.method_0().Count;
        int num3  = (count > 90) ? 3 : ((count > 60) ? 5 : ((count > 30) ? 10 : count));

        this.pdfNewDocument_0 = this.method_12();
        for (int i = 0; i < count; i++)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                A_0.method_57(i, 1, ImageType.Metafile, stream, false, false, true);
                PdfNewPage page = this.method_13(this.method_0()[i]).get_Pages().Add();
                this.pdfPageBase_0 = page;
                using (PdfMetafile metafile = PdfImage.FromImage(A_0.method_34().method_0()[i].method_0()))
                {
                    metafile.set_Quality((long)this.int_0);
                    metafile.ᜀ(page, new RectangleF(PointF.Empty, page.get_Size()), true, this.method_1().EmbeddedFontNameList, this.method_1().IsEmbeddedAllFonts, this.method_2());
                }
                this.method_18(A_0.method_34().method_0()[i].method_2());
                A_0.method_34().method_0()[i].method_0().Dispose();
                A_0.method_34().method_0()[i].method_1(null);
            }
            if ((i % num3) == 0)
            {
                GC.Collect();
            }
        }
        this.method_27(A_0, count, false);
        if (!this.method_1().CreateWordBookmarks)
        {
            this.method_27(A_0, count, true);
        }
        else if (A_0.method_11().Count > 0)
        {
            PdfBookmark bookmark = this.pdfNewDocument_0.get_Bookmarks().Add(this.method_1().WordBookmarksTitle);
            bookmark.set_Color((PdfRGBColor)this.method_1().WordBookmarksColor);
            bookmark.set_DisplayStyle(this.method_24(this.method_1().WordBookmarksTextStyle));
            this.method_22(A_0.method_11(), bookmark);
        }
        this.method_16(A_0.method_35().BuiltinDocumentProperties);
        A_0.method_51();
        return(this.pdfNewDocument_0);
    }
示例#5
0
        public ActionResult PdfConformance(string Browser)
        {
            //Create a new document with PDF/A standard.
            PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);

            //Add a page
            PdfPage page = doc.Pages.Add();

            //Create Pdf graphics for the page
            PdfGraphics g = page.Graphics;

            SizeF bounds = page.GetClientSize();

            //Read the RTF document
            StreamReader reader = new StreamReader(ResolveApplicationDataPath("PDF_A.rtf"), System.Text.Encoding.ASCII);
            string       text   = reader.ReadToEnd();

            reader.Close();

            //Convert it as metafile.
            PdfMetafile             metafile = (PdfMetafile)PdfImage.FromRtf(text, bounds.Width, PdfImageType.Metafile);
            PdfMetafileLayoutFormat format   = new PdfMetafileLayoutFormat();

            //Allow the text to flow multiple pages without any breaks.
            format.SplitTextLines = true;

            //Draw the image.
            metafile.Draw(page, 0, 0, format);


            //Stream the output to the browser.
            if (Browser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
        public ActionResult ImageInsertion(string InsideBrowser)
        {
            string jpgImage        = ResolveApplicationImagePath("Autumn Leaves.jpg");
            string tifImage        = ResolveApplicationImagePath("256.tif");
            string bmpImage        = ResolveApplicationImagePath("mask2.bmp");
            string pngImage        = ResolveApplicationImagePath("design.png");
            string emfImage        = ResolveApplicationImagePath("metachart.emf");
            string multiframeImage = ResolveApplicationImagePath("Image.tiff");
            string gifImage        = ResolveApplicationImagePath("Ani.gif");

            PdfDocument doc = new PdfDocument();

            doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Tahoma", 22f, FontStyle.Bold), false);
            PdfSolidBrush   brush = new PdfSolidBrush(Color.DarkBlue);

            PdfSection  section = doc.Sections.Add();
            PdfPage     page    = section.Pages.Add();
            PdfGraphics g       = page.Graphics;

            //png image
            PdfImage image = new PdfBitmap(pngImage);

            g.DrawImage(image, 0, 0, image.Width, image.Height);
            page.Graphics.DrawString("Png Image", font, brush, new PointF(10, 0));

            page = section.Pages.Add();
            g    = page.Graphics;

            //Bitmap with Tiff image mask
            image = new PdfBitmap(tifImage);
            (image as PdfBitmap).Mask = new PdfImageMask(new PdfBitmap(bmpImage));
            page.Graphics.DrawString("Image mask", font, brush, new PointF(10, 0));
            g.DrawImage(image, 80, 40);

            //Metafile
            PdfMetafile metafile;

            page     = section.Pages.Add();
            g        = page.Graphics;
            metafile = new PdfMetafile(emfImage);
            page.Graphics.DrawString("Metafile", font, brush, new PointF(10, 0));
            g.DrawImage(metafile, new PointF(0, 50));

            //Image pagination -jpg
            image = new PdfBitmap(jpgImage);

            PdfLayoutFormat format = new PdfLayoutFormat();

            format.Layout = PdfLayoutType.Paginate;

            PointF     location = new PointF(0, 400);
            SizeF      size     = new SizeF(400, -1);
            RectangleF rect     = new RectangleF(location, size);

            page.Graphics.DrawString("Image Pagination", font, brush, new PointF(10, 360));
            image.Draw(page, rect, format);

            //Multiframe Tiff image
            PdfBitmap tiffImage = new PdfBitmap(multiframeImage);

            int frameCount = tiffImage.FrameCount;

            for (int i = 0; i < frameCount; i++)
            {
                page = section.Pages.Add();
                section.PageSettings.Margins.All = 0;
                g = page.Graphics;
                tiffImage.ActiveFrame = i;
                g.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
            }

            page  = section.Pages.Add();
            g     = page.Graphics;
            image = new PdfBitmap(gifImage);
            g.DrawImage(image, 0, 0, page.Graphics.ClientSize.Width, image.Height);
            page.Graphics.DrawString("Gif Image", font, brush, new PointF(10, 0));

            section.Pages[section.Pages.Count - 3].Graphics.DrawString("Multiframe Tiff Image", font, brush, new PointF(10, 10));
            section.PageSettings.Transition.PageDuration = 1;
            section.PageSettings.Transition.Duration     = 1;
            section.PageSettings.Transition.Style        = PdfTransitionStyle.Fly;

            //Stream the output to the browser.
            if (InsideBrowser == "Browser")
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open));
            }
            else
            {
                return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
        }
示例#7
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");
                    }
                }
            }
        }