Ejemplo n.º 1
0
        void CreateNewPage(PdfFixedDocument document, PdfFont font, PdfBrush brush)
        {
            var page = document.Pages.Add();

            page.Height = 1024;
            page.Width  = 840;

            font.Size = FONTSIZE_PAGE_TITLE;

            PdfStringAppearanceOptions appearance = new PdfStringAppearanceOptions
            {
                Brush = brush,
                Font  = font,
            };

            PdfStringLayoutOptions layout = new PdfStringLayoutOptions()
            {
                HorizontalAlign = PdfStringHorizontalAlign.Right,
                VerticalAlign   = PdfStringVerticalAlign.Bottom,
                X = page.Width - PagePadding.Right,
                Y = page.Height - PagePadding.Bottom
            };

            font.Size = FONTSIZE_DEFAULT;
            page.Graphics.DrawString(document.Pages.Count.ToString(), appearance, layout);

            CurrentPage   = page;
            AvailableSize = new Size(
                page.Width - PagePadding.Left - PagePadding.Right,
                page.Height - PagePadding.Top - PagePadding.Bottom);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFile file = new PdfFile(input);

            PdfPageContent[] content = file.ExtractPageContent(0, file.PageCount - 1);
            file = null;

            PdfFixedDocument document = new PdfFixedDocument();
            PdfPage          page1    = document.Pages.Add();

            // Draw the same page content 4 times on the new page, the content is scaled to half and flipped.
            page1.Graphics.DrawFormXObject(content[0],
                                           0, 0, page1.Width / 2, page1.Height / 2);
            page1.Graphics.DrawFormXObject(content[0],
                                           page1.Width / 2, 0, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.VerticalFlip);
            page1.Graphics.DrawFormXObject(content[0],
                                           0, page1.Height / 2, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.HorizontalFlip);
            page1.Graphics.DrawFormXObject(content[0],
                                           page1.Width / 2, page1.Height / 2, page1.Width / 2, page1.Height / 2,
                                           0, PdfFlipDirection.VerticalFlip | PdfFlipDirection.HorizontalFlip);

            PdfPage page2 = document.Pages.Add();

            // Draw 3 pages on the new page.
            page2.Graphics.DrawFormXObject(content[0],
                                           0, 0, page2.Width / 2, page2.Height / 2);
            page2.Graphics.DrawFormXObject(content[1],
                                           page2.Width / 2, 0, page2.Width / 2, page2.Height / 2);
            page2.Graphics.DrawFormXObject(content[2],
                                           0, page2.Height, page2.Height / 2, page2.Width, 90);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageimposition.pdf") };
            return(output);
        }
Ejemplo n.º 3
0
        public static void AddHeader(PdfPage page, PdfFixedDocument document, string heading, int fontSize = 18)
        {
            PdfStandardFont titleFont  = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, fontSize);
            PdfBrush        blackBrush = new PdfBrush(new PdfRgbColor());

            page.Graphics.DrawString(heading, titleFont, blackBrush, 20, 50);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extracts text fragments from the 2nd page and highlights the glyphs in the fragment.
        /// </summary>
        /// <param name="document"></param>
        private static void ExtractTextAndHighlightGlyphs(PdfFixedDocument document)
        {
            PdfRgbColor penColor = new PdfRgbColor();
            PdfPen      pen      = new PdfPen(penColor, 0.5);
            Random      rnd      = new Random();

            byte[] rgb = new byte[3];

            PdfContentExtractor       ce  = new PdfContentExtractor(document.Pages[1]);
            PdfTextFragmentCollection tfc = ce.ExtractTextFragments();
            PdfTextFragment           tf  = tfc[1];

            for (int i = 0; i < tf.Glyphs.Count; i++)
            {
                rnd.NextBytes(rgb);
                penColor.R = rgb[0];
                penColor.G = rgb[1];
                penColor.B = rgb[2];

                PdfPath boundingPath = new PdfPath();
                boundingPath.StartSubpath(tf.Glyphs[i].GlyphCorners[0].X, tf.Glyphs[i].GlyphCorners[0].Y);
                boundingPath.AddLineTo(tf.Glyphs[i].GlyphCorners[1].X, tf.Glyphs[i].GlyphCorners[1].Y);
                boundingPath.AddLineTo(tf.Glyphs[i].GlyphCorners[2].X, tf.Glyphs[i].GlyphCorners[2].Y);
                boundingPath.AddLineTo(tf.Glyphs[i].GlyphCorners[3].X, tf.Glyphs[i].GlyphCorners[3].Y);
                boundingPath.CloseSubpath();

                document.Pages[1].Graphics.DrawPath(pen, boundingPath);
            }
        }
        public static void Export(IION ion, GaugeDeviceCalibrationCertificate certificate, Stream outStream)
        {
            var pdf = new PdfFixedDocument(EmbeddedResource.Load("digital_gauge_cert.pdf"));

            // Header
            (pdf.Form.Fields[FIELD_CERT_BY] as PdfTextBoxField).Value   = certificate.certifiedBy;
            (pdf.Form.Fields[FIELD_CERT_DATE] as PdfTextBoxField).Value = certificate.lastTestCalibrationDate.ToString("d");
            // Unit Tested
            (pdf.Form.Fields[FIELD_PART_NO] as PdfTextBoxField).Text   = certificate.testPartNumber;
            (pdf.Form.Fields[FIELD_SERIAL_NO] as PdfTextBoxField).Text = certificate.testSerialNumber + "";
            // Calibration Standard
            (pdf.Form.Fields[FIELD_CAL_MODEL] as PdfTextBoxField).Text     = certificate.controlInstrument;
            (pdf.Form.Fields[FIELD_CAL_SERIAL_NO] as PdfTextBoxField).Text = certificate.controlSerial;
//      (pdf.Form.Fields[KEY_CONTROL_TRANSDUCER] as PdfTextBoxField).Text = certificate.controlTransducer;
            (pdf.Form.Fields[FIELD_CAL_ACCURACY] as PdfTextBoxField).Text = certificate.controlAccuracy + "";
            (pdf.Form.Fields[FIELD_CAL_DATE] as PdfTextBoxField).Text     = certificate.lastControlCalibrationDate.ToString("d");
            // Ambient Conditions
            (pdf.Form.Fields[FIELD_AMB_TEMP] as PdfTextBoxField).Text = certificate.environmentTemperature + "";
            (pdf.Form.Fields[FIELD_AMB_RH] as PdfTextBoxField).Text   = certificate.environmentHumidity + "";

            // Performance Data Table
            (pdf.Form.Fields[FIELD_CAL_LIMIT] as PdfTextBoxField).Text = certificate.testAccuracy + "";
            foreach (var pair in TABLE_KEYS)
            {
                var data = certificate.calibrationDataPoints[pair.second];
                for (int i = 0; i < data.Length; i++)
                {
                    (pdf.Form.Fields[pair.first + (i + 1)] as PdfTextBoxField).Text = data[i];
                }
            }

            pdf.Form.FlattenFields();
            pdf.Save(outStream);
        }
Ejemplo n.º 6
0
        //this is a tutrila can help you with simple text
        private async void Button_Click1(object sender, RoutedEventArgs e)
        {
            var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("a.pdf", CreationCollisionOption.ReplaceExisting);

            using (Stream stream = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(file))
            {
                PdfFixedDocument document = new PdfFixedDocument();
                PdfPage          page     = document.Pages.Add();
                // Create a standard font with Helvetica face and 24 point size
                PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
                // Create a solid RGB red brush.
                PdfBrush brush = new PdfBrush(PdfRgbColor.Red);
                // Draw the text on the page.
                string cha = "title";
                page.Graphics.DrawString(cha, helvetica, brush, 250, 50);
                // Draw the text on the page. max tableau 50
                string ch = "azj aeiajiahfioe foiehfioehfiehfie feifjaepfjaepofjaepo fpaejfpeafjaefaefhevpzevje vjepzvihzev zep";
                page.Graphics.DrawString(ch, helvetica, brush, 10, 100);

                document.Save(stream);
            }
            await Launcher.LaunchFileAsync(file);

            //FileStream input = File.OpenRead("optionalcontent-src.pdf");
            //PdfFile file = new PdfFile(input);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Extracts text fragments from the 3rd page and highlights the glyphs in the fragment.
        /// </summary>
        /// <param name="document"></param>
        private static void ExtractImagesAndHighlight(PdfFixedDocument document)
        {
            PdfPen                     pen       = new PdfPen(new PdfRgbColor(255, 0, 192), 0.5);
            PdfBrush                   brush     = new PdfBrush(new PdfRgbColor(0, 0, 0));
            PdfStandardFont            helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 8);
            PdfStringAppearanceOptions sao       = new PdfStringAppearanceOptions();

            sao.Brush = brush;
            sao.Font  = helvetica;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.Width = 1000;

            PdfContentExtractor      ce  = new PdfContentExtractor(document.Pages[2]);
            PdfVisualImageCollection eic = ce.ExtractImages(false);

            for (int i = 0; i < eic.Count; i++)
            {
                string imageProperties = string.Format("Image ID: {0}\nPixel width: {1} pixels\nPixel height: {2} pixels\n" +
                                                       "Display width: {3} points\nDisplay height: {4} points\nHorizonal Resolution: {5} dpi\nVertical Resolution: {6} dpi",
                                                       eic[i].ImageID, eic[i].Width, eic[i].Height, eic[i].DisplayWidth, eic[i].DisplayHeight, eic[i].DpiX, eic[i].DpiY);

                PdfPath boundingPath = new PdfPath();
                boundingPath.StartSubpath(eic[i].ImageCorners[0].X, eic[i].ImageCorners[0].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[1].X, eic[i].ImageCorners[1].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[2].X, eic[i].ImageCorners[2].Y);
                boundingPath.AddLineTo(eic[i].ImageCorners[3].X, eic[i].ImageCorners[3].Y);
                boundingPath.CloseSubpath();

                document.Pages[2].Graphics.DrawPath(pen, boundingPath);
                slo.X = eic[i].ImageCorners[3].X + 1;
                slo.Y = eic[i].ImageCorners[3].Y + 1;
                document.Pages[2].Graphics.DrawString(imageProperties, sao, slo);
            }
        }
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfDocumentFeatures df = new PdfDocumentFeatures();

            // Do not load file attachments, new file attachments cannot be added.
            df.EnableDocumentFileAttachments = false;
            // Do not load form fields, form fields cannot be filled and new form fields cannot be added.
            df.EnableDocumentFormFields = false;
            // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added.
            df.EnableDocumentJavaScriptFragments = false;
            // Do not load the named destinations, new named destinations cannot be created.
            df.EnableDocumentNamedDestinations = false;
            // Do not load the document outlines, new outlines cannot be created.
            df.EnableDocumentOutline = false;
            // Do not load annotations, new annotations cannot be added to existing pages.
            df.EnablePageAnnotations = false;
            // Do not load the page graphics, new graphics cannot be added to existing pages.
            df.EnablePageGraphics = false;
            PdfFixedDocument document = new PdfFixedDocument(input, df);

            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 24);
            PdfBrush        brush     = new PdfBrush();

            // Add a new page with some content on it.
            PdfPage page = document.Pages.Add();

            page.Graphics.DrawString("New page added to an existing document.", helvetica, brush, 20, 50);

            // When document features have been specified at load time the document is automatically saved in incremental update mode.
            document.Save(input);

            return(null);
        }
Ejemplo n.º 9
0
        protected override void OnCreate(Bundle bundle)
        {
            PdfFixedDocument doc;
            int count;
            var newFilename = "cache.pdf"; // My new filename to be stored on local device
            string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
            var fullpath = System.IO.Path.Combine (documentsPath, newFilename);
            Java.IO.File file = new Java.IO.File (fullpath);
            file.SetReadable (true);
            Android.Net.Uri uri = Android.Net.Uri.FromFile (file);
            MemoryStream ms = new MemoryStream ();
            var contentUri = uri;
            using (Stream stream = ContentResolver.OpenInputStream (contentUri)) {
                stream.CopyTo (ms);
            }
            ms.Position = 0;
            doc = new PdfFixedDocument (ms);
            count = doc.Pages.Count;
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.Main);
            VP = FindViewById <CustomViewPager> (Resource.Id.viewPager);
            //VP.Adapter = new SimplePagerAdapter(VP,this.BaseContext,count);

            VP.Background = Android.Graphics.Drawables.Drawable.CreateFromPath ("LoadingImage.jpg");

            VP.Adapter = new  EasyPagerAdapter(this.BaseContext, count,VP,doc);
            VP.SetPageTransformer(true, new FadeTransformer ());
            VP.setPagingEnabled (true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream s1, Stream s2)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            document.DisplayMode = PdfDisplayMode.UseAttachments;

            PdfStandardFont helvetica  = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16);
            PdfBrush        blackBrush = new PdfBrush();
            PdfPage         page       = document.Pages.Add();

            page.Graphics.DrawString("This document contains 2 file attachments:", helvetica, blackBrush, 50, 50);
            page.Graphics.DrawString("1. fileattachments.cs.html", helvetica, blackBrush, 50, 70);
            page.Graphics.DrawString("2. fileattachments.vb.html", helvetica, blackBrush, 50, 90);

            byte[] fileData1 = new byte[s1.Length];
            s1.Read(fileData1, 0, fileData1.Length);
            PdfDocumentFileAttachment fileAttachment1 = new PdfDocumentFileAttachment();

            fileAttachment1.Payload     = fileData1;
            fileAttachment1.FileName    = "fileattachments.cs.html";
            fileAttachment1.Description = "C# Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment1);

            byte[] fileData2 = new byte[s2.Length];
            s2.Read(fileData2, 0, fileData2.Length);
            PdfDocumentFileAttachment fileAttachment2 = new PdfDocumentFileAttachment();

            fileAttachment2.Payload     = fileData1;
            fileAttachment2.FileName    = "fileattachments.vb.html";
            fileAttachment2.Description = "VB.NET Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment2);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fileattachments.pdf") };
            return(output);
        }
Ejemplo n.º 11
0
        private static void CreateTextMarkupAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            page.Graphics.DrawString("Text markup annotations", font, blackBrush, 50, 50);

            PdfTextMarkupAnnotationType[] tmat = new PdfTextMarkupAnnotationType[]
            {
                PdfTextMarkupAnnotationType.Highlight, PdfTextMarkupAnnotationType.Squiggly, PdfTextMarkupAnnotationType.StrikeOut, PdfTextMarkupAnnotationType.Underline
            };

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;

            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Bottom;
            for (int i = 0; i < tmat.Length; i++)
            {
                PdfTextMarkupAnnotation tma = new PdfTextMarkupAnnotation();
                page.Annotations.Add(tma);
                tma.VisualRectangle = new PdfVisualRectangle(50, 100 + 50 * i, 200, font.Size + 2);
                tma.TextMarkupType  = tmat[i];

                slo.X = 150;
                slo.Y = 100 + 50 * i + font.Size;

                page.Graphics.DrawString(tmat[i].ToString() + " annotation.", sao, slo);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// <para>
        /// Page specific logic should be placed in event handlers for the
        /// <see cref="NavigationHelper.LoadState"/>
        /// and <see cref="NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method
        /// in addition to page state preserved during an earlier session.
        /// </para>
        /// </summary>
        /// <param name="e">Provides data for navigation methods and event
        /// handlers that cannot cancel the navigation request.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

            int pageNumber            = (int)e.Parameter;
            PdfFixedDocument document = (Application.Current as App).Document;

            var t = Task <PdfBgraByteRenderingSurface> .Factory.StartNew(() =>
            {
                PdfPageRenderer renderer       = new PdfPageRenderer(document.Pages[pageNumber]);
                PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface <PdfBgraByteRenderingSurface>(96, 96);
                PdfRendererSettings settings   = new PdfRendererSettings(96, 96, rs);
                renderer.ConvertPageToImage(settings);

                return(rs);
            })
                    .ContinueWith(value =>
            {
                PdfBgraByteRenderingSurface rs = value.Result;
                WriteableBitmap pageBitmap     = new WriteableBitmap(rs.Width, rs.Height);
                Stream imageStream             = pageBitmap.PixelBuffer.AsStream();
                imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);
                pageImage.Width  = pageBitmap.PixelWidth;
                pageImage.Height = pageBitmap.PixelHeight;
                pageImage.Source = pageBitmap;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 13
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            Assembly asm = Assembly.GetExecutingAssembly();
            Stream pdfStream = asm.GetManifestResourceStream("PDFToImage.xfinium.pdf");
            document = new PdfFixedDocument (pdfStream);
            pdfStream.Close();

            Spinner pageNumbers = FindViewById<Spinner>(Resource.Id.pageNumberSpinner);
            ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            pageNumbers.Adapter = adapter;
            adapter.Add("Please select a page number");
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                adapter.Add(i.ToString());
            }
            Button button = FindViewById<Button> (Resource.Id.btnConvertToImage);

            button.Click += delegate {
                if ((pageNumbers.SelectedItemPosition >= 1) && (pageNumbers.SelectedItemPosition <= document.Pages.Count))
                {
                    PdfPageRenderer renderer = new PdfPageRenderer (document.Pages [pageNumbers.SelectedItemPosition - 1]);
                    Bitmap pageImage = renderer.ConvertPageToImage (96);

                    ImageView pageImageView = FindViewById<ImageView> (Resource.Id.pageImageView);
                    pageImageView.SetImageBitmap(pageImage);
                }
            };
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfRc4SecurityHandler rc4_40    = new PdfRc4SecurityHandler();
            PdfFixedDocument      document1 = EncryptRC4(40, rc4_40);
            PdfRc4SecurityHandler rc4_128   = new PdfRc4SecurityHandler();
            PdfFixedDocument      document2 = EncryptRC4(128, rc4_128);

            PdfAesSecurityHandler aes128    = new PdfAesSecurityHandler();
            PdfFixedDocument      document3 = EncryptAES(128, aes128);
            PdfAesSecurityHandler aes256    = new PdfAesSecurityHandler();
            PdfFixedDocument      document4 = EncryptAES(256, aes256);
            PdfAesSecurityHandler aes256e   = new PdfAesSecurityHandler();

            aes256e.UseEnhancedPasswordValidation = true;
            PdfFixedDocument document5 = EncryptAES(256, aes256e);
            PdfFixedDocument document6 = Decrypt(input);

            SampleOutputInfo[] output = new SampleOutputInfo[]
            {
                new SampleOutputInfo(document1, "xfinium.pdf.sample.encryption.rc4.40bit.pdf", rc4_40),
                new SampleOutputInfo(document2, "xfinium.pdf.sample.encryption.rc4.128bit.pdf", rc4_128),
                new SampleOutputInfo(document3, "xfinium.pdf.sample.encryption.aes.128bit.pdf", aes128),
                new SampleOutputInfo(document4, "xfinium.pdf.sample.encryption.aes.256bit.pdf", aes256),
                new SampleOutputInfo(document5, "xfinium.pdf.sample.encryption.aes.256bit.enhanced.pdf", aes256e),
                new SampleOutputInfo(document6, "xfinium.pdf.sample.encryption.decrypted.pdf"),
            };
            return(output);
        }
Ejemplo n.º 15
0
        private static void CreateDocumentActions(PdfFixedDocument document)
        {
            // Create an action that will open the document at the last page with 200% zoom.
            PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();
            pageDestination.Page = document.Pages[document.Pages.Count - 1];
            pageDestination.Zoom = 200;
            pageDestination.Top = 0;
            pageDestination.Left = 0;
            PdfGoToAction openAction = new PdfGoToAction();
            openAction.Destination = pageDestination;
            document.OpenAction = openAction;

            // Create an action that is executed when the document is closed.
            PdfJavaScriptAction jsCloseAction = new PdfJavaScriptAction();
            jsCloseAction.Script = "app.alert({cMsg: \"The document will close now.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforeCloseAction = jsCloseAction;

            // Create an action that is executed before the document is printed.
            PdfJavaScriptAction jsBeforePrintAction = new PdfJavaScriptAction();
            jsBeforePrintAction.Script = "app.alert({cMsg: \"The document will be printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforePrintAction = jsBeforePrintAction;

            // Create an action that is executed after the document is printed.
            PdfJavaScriptAction jsAfterPrintAction = new PdfJavaScriptAction();
            jsAfterPrintAction.Script = "app.alert({cMsg: \"The document has been printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.AfterPrintAction = jsAfterPrintAction;
        }
        /// <summary>c
        /// Commits the pdf to a stream.
        /// </summary>
        /// <param name="outstream">Outstream.</param>
        public static void Export(ScreenshotReport report, Stream outstream)
        {
            // Create the document to export.
            var document = new PdfFixedDocument();
            // Add the first page.
            var page = document.Pages.Add();

            // Init the document fonts
            var title    = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18);
            var subtitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 14);
            var header   = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 12);
            var content  = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12);

            double ml, mt, mr, mb; // Margins

            ml = mt = mr = mb = 18;
            double pw = page.Width - (ml + mr);

            // Bounds
            // 0,0 is top left with positive x going right, and positive y going down. Lower
            // approaches the orgin whilst higher extends away from the orgin approaching infinity.
            var headerBounds  = NewRect(ml, mt, pw, 50); // ux, uy, lx, ly
            var cx            = page.Width / 2;
            var imageBounds   = NewRect(ml, headerBounds.URY, cx - mr - ml, page.Height - headerBounds.Height - mt - mb);
            var contentBounds = NewRect(cx + mr, headerBounds.URY, cx - mr - ml, page.Height - headerBounds.Height - mt - mb);

            // Draw the page
            DrawHeader(report, page, headerBounds, title, subtitle);
            DrawScreenshot(report, page, imageBounds);
            DrawContent(report, page, contentBounds, header, content);

            // Commit
            document.Save(outstream);
        }
Ejemplo n.º 17
0
        private static void CreateLaunchActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Launch actions:", font, blackBrush, 400, 360);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 380, 200, 20);
                slo.X = 500;
                slo.Y = 390;
                document.Pages[i].Graphics.DrawString("Launch samples explorer", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 380, 200, 20);

                // Create a launch action and attach it to the link.
                PdfLaunchAction launchAction = new PdfLaunchAction();
                launchAction.FileName = "Xfinium.Pdf.SamplesExplorer.Win.exe";
                link.Action           = launchAction;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            // Create a PDF document with 10 pages.
            PdfFixedDocument document = new PdfFixedDocument();
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216);
            PdfBrush blackBrush = new PdfBrush();
            for (int i = 0; i < 10; i++)
            {
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 5, 5);
            }

            CreateNamedActions(document, helvetica);

            CreateGoToActions(document, helvetica);

            CreateRemoteGoToActions(document, helvetica);

            CreateLaunchActions(document, helvetica);

            CreateUriActions(document, helvetica);

            CreateJavaScriptActions(document, helvetica);

            CreateDocumentActions(document);

            // Compress the page graphic content.
            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.CompressAndClose();
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.actions.pdf") };
            return output;
        }
Ejemplo n.º 19
0
        private static void CreateInkAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();
            Random   rnd        = new Random();

            PdfPage page = document.Pages.Add();

            page.Graphics.DrawString("Ink annotations", font, blackBrush, 50, 50);

            // The ink annotation will contain 3 lines, each one with 10 points.
            PdfPoint[][] points = new PdfPoint[3][];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new PdfPoint[10];
                for (int j = 0; j < points[i].Length; j++)
                {
                    points[i][j] = new PdfPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height);
                }
            }

            PdfInkAnnotation ia = new PdfInkAnnotation();

            page.Annotations.Add(ia);
            ia.Contents = "I am an ink annotation.";
            ia.InkColor = new PdfRgbColor(255, 0, 255);
            ia.InkWidth = 5;
            ia.Points   = points;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream s1, Stream s2)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            document.DisplayMode = PdfDisplayMode.UseAttachments;

            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16);
            PdfBrush blackBrush = new PdfBrush();
            PdfPage page = document.Pages.Add();
            page.Graphics.DrawString("This document contains 2 file attachments:", helvetica, blackBrush, 50, 50);
            page.Graphics.DrawString("1. fileattachments.cs.html", helvetica, blackBrush, 50, 70);
            page.Graphics.DrawString("2. fileattachments.vb.html", helvetica, blackBrush, 50, 90);

            byte[] fileData1 = new byte[s1.Length];
            s1.Read(fileData1, 0, fileData1.Length);
            PdfDocumentFileAttachment fileAttachment1 = new PdfDocumentFileAttachment();
            fileAttachment1.Payload = fileData1;
            fileAttachment1.FileName = "fileattachments.cs.html";
            fileAttachment1.Description = "C# Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment1);

            byte[] fileData2 = new byte[s2.Length];
            s2.Read(fileData2, 0, fileData2.Length);
            PdfDocumentFileAttachment fileAttachment2 = new PdfDocumentFileAttachment();
            fileAttachment2.Payload = fileData1;
            fileAttachment2.FileName = "fileattachments.vb.html";
            fileAttachment2.Description = "VB.NET Source Code for FileAttachments sample";
            document.FileAttachments.Add(fileAttachment2);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fileattachments.pdf") };
            return output;
        }
Ejemplo n.º 21
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Assembly asm       = Assembly.GetExecutingAssembly();
            Stream   pdfStream = asm.GetManifestResourceStream("PDFToImage.xfinium.pdf");

            document = new PdfFixedDocument(pdfStream);
            pdfStream.Close();

            Spinner pageNumbers           = FindViewById <Spinner>(Resource.Id.pageNumberSpinner);
            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);

            pageNumbers.Adapter = adapter;
            adapter.Add("Please select a page number");
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                adapter.Add(i.ToString());
            }
            Button button = FindViewById <Button> (Resource.Id.btnConvertToImage);

            button.Click += delegate {
                if ((pageNumbers.SelectedItemPosition >= 1) && (pageNumbers.SelectedItemPosition <= document.Pages.Count))
                {
                    PdfPageRenderer renderer  = new PdfPageRenderer(document.Pages [pageNumbers.SelectedItemPosition - 1]);
                    Bitmap          pageImage = renderer.ConvertPageToImage(96);

                    ImageView pageImageView = FindViewById <ImageView> (Resource.Id.pageImageView);
                    pageImageView.SetImageBitmap(pageImage);
                }
            };
        }
Ejemplo n.º 22
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string pageNumber = "";

            if (NavigationContext.QueryString.TryGetValue("pagenumber", out pageNumber))
            {
                PdfFixedDocument document = (Application.Current as App).Document;

                var t = Task <PdfArgbIntRenderingSurface> .Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer      = new PdfPageRenderer(document.Pages[int.Parse(pageNumber)]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface <PdfArgbIntRenderingSurface>(96, 96);
                    PdfRendererSettings settings  = new PdfRendererSettings(96, 96, rs);
                    renderer.ConvertPageToImage(settings);

                    return(rs);
                })
                        .ContinueWith(value =>
                {
                    PdfArgbIntRenderingSurface rs = value.Result;
                    WriteableBitmap wb            = new WriteableBitmap(rs.Width, rs.Height);
                    Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                    pageImage.Width  = wb.PixelWidth;
                    pageImage.Height = wb.PixelHeight;
                    pageImage.Source = wb;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Ejemplo n.º 23
0
        public void UploadImage(string imageData)
        {
            string fileName        = "MyUniqueImageFileName.png";
            string fileNameWitPath = Path.Combine(Server.MapPath("~/Temp"), fileName);

            using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
            {
                using (BinaryWriter bw = new BinaryWriter(fs))
                {
                    byte[] data = Convert.FromBase64String(imageData);
                    bw.Write(data);
                    bw.Close();
                }
                fs.Close();
            }
            PdfFixedDocument poDocument = new PdfFixedDocument();
            PdfPngImage      pngImg     = new PdfPngImage(fileNameWitPath);
            PdfPage          p          = new PdfPage();

            p.Graphics.DrawImage(pngImg, 0, 0, pngImg.Width, pngImg.Height);
            poDocument.Pages.Add(p);
            poDocument.Save(fileNameWitPath.Replace("png", "pdf"));
            byte[] pdfContent = System.IO.File.ReadAllBytes(fileNameWitPath.Replace("png", "pdf"));
            Response.BinaryWrite(pdfContent);
        }
Ejemplo n.º 24
0
        //this is a tutrila can help you with paragraph block
        private async void Button_Click2(object sender, RoutedEventArgs e)
        {
            var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("a.pdf", CreationCollisionOption.ReplaceExisting);

            using (Stream stream = await WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync(file))
            {
                string paragraph2Block1Text = "The development style is based on fixed document model, where each page is created as needed " +
                                              "and content is placed at fixed position using a grid based layout.\r\n" +
                                              "This gives you access to all PDF features, whether you want to create a simple file " +
                                              "or you want to create a transparency knockout group at COS level, and lets you build more complex models on top of the library.";

                PdfStandardFont textFont = new PdfStandardFont(PdfStandardFontFace.TimesRoman, 12);

                PdfFormattedParagraph paragraph2 = new PdfFormattedParagraph();
                paragraph2.SpacingAfter    = 3;
                paragraph2.FirstLineIndent = 10;
                paragraph2.HorizontalAlign = PdfStringHorizontalAlign.Justified;
                paragraph2.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple;
                paragraph2.LineSpacing     = 1.2;
                paragraph2.Blocks.Add(new PdfFormattedTextBlock(paragraph2Block1Text, textFont));

                PdfFormattedContent formattedContent = new PdfFormattedContent();
                formattedContent.Paragraphs.Add(paragraph2);

                PdfFixedDocument document = new PdfFixedDocument();
                PdfPage          page     = document.Pages.Add();

                page.Graphics.DrawFormattedContent(formattedContent, 50, 50, 500, 700);
                page.Graphics.CompressAndClose();

                document.Save(stream);
            }
            await Launcher.LaunchFileAsync(file);
        }
Ejemplo n.º 25
0
        private static void CreateDocumentActions(PdfFixedDocument document)
        {
            // Create an action that will open the document at the last page with 200% zoom.
            PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();

            pageDestination.Page = document.Pages[document.Pages.Count - 1];
            pageDestination.Zoom = 200;
            pageDestination.Top  = 0;
            pageDestination.Left = 0;
            PdfGoToAction openAction = new PdfGoToAction();

            openAction.Destination = pageDestination;
            document.OpenAction    = openAction;

            // Create an action that is executed when the document is closed.
            PdfJavaScriptAction jsCloseAction = new PdfJavaScriptAction();

            jsCloseAction.Script       = "app.alert({cMsg: \"The document will close now.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforeCloseAction = jsCloseAction;

            // Create an action that is executed before the document is printed.
            PdfJavaScriptAction jsBeforePrintAction = new PdfJavaScriptAction();

            jsBeforePrintAction.Script = "app.alert({cMsg: \"The document will be printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.BeforePrintAction = jsBeforePrintAction;

            // Create an action that is executed after the document is printed.
            PdfJavaScriptAction jsAfterPrintAction = new PdfJavaScriptAction();

            jsAfterPrintAction.Script = "app.alert({cMsg: \"The document has been printed.\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
            document.AfterPrintAction = jsAfterPrintAction;
        }
Ejemplo n.º 26
0
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action     = jsAction;
            }
        }
Ejemplo n.º 27
0
        private static void CreateUriActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Graphics.DrawString("Go to xfiniumpdf.com", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PdfUriAction uriAction = new PdfUriAction();
                uriAction.URI = "http://www.xfiniumpdf.com";
                link.Action   = uriAction;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Generates a PDF document that is encrypted using AES method.
        /// </summary>
        /// <param name="keySize">The encryption key size.</param>
        /// <param name="aes"></param>
        /// <returns></returns>
        private static PdfFixedDocument EncryptAES(int keySize, PdfAesSecurityHandler aes)
        {
            PdfFixedDocument doc = new PdfFixedDocument();

            aes.EnableContentExtractionForAccessibility = false;
            aes.EnableDocumentAssembly         = false;
            aes.EnableDocumentChange           = false;
            aes.EnableContentExtraction        = false;
            aes.EnableFormsFill                = false;
            aes.EnableAnnotationsAndFieldsEdit = false;
            aes.EnablePrint     = false;
            aes.EncryptMetadata = true;
            aes.KeySize         = keySize;
            aes.UserPassword    = "******";
            aes.OwnerPassword   = "******";

            PdfPage         page       = doc.Pages.Add();
            PdfStandardFont helvetica  = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16);
            PdfBrush        blackBrush = new PdfBrush();

            string text = string.Format("Encryption: AES {0} bit", keySize);

            if ((aes.KeySize == 256) && aes.UseEnhancedPasswordValidation)
            {
                text = text + " with enhanced password validation (Acrobat X or later)";
            }
            page.Graphics.DrawString(text, helvetica, blackBrush, 50, 100);

            return(doc);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Generates a PDF document that is encrypted using AES method.
        /// </summary>
        /// <param name="keySize">The encryption key size.</param>
        /// <param name="aes"></param>
        /// <returns></returns>
        private static PdfFixedDocument EncryptAES(int keySize, PdfAesSecurityHandler aes)
        {
            PdfFixedDocument doc = new PdfFixedDocument();
            aes.EnableContentExtractionForAccessibility = false;
            aes.EnableDocumentAssembly = false;
            aes.EnableDocumentChange = false;
            aes.EnableContentExtraction = false;
            aes.EnableFormsFill = false;
            aes.EnableAnnotationsAndFieldsEdit = false;
            aes.EnablePrint = false;
            aes.EncryptMetadata = true;
            aes.KeySize = keySize;
            aes.UserPassword = "******";
            aes.OwnerPassword = "******";

            PdfPage page = doc.Pages.Add();
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16);
            PdfBrush blackBrush = new PdfBrush();

            string text = string.Format("Encryption: AES {0} bit", keySize);
            if ((aes.KeySize == 256) && aes.UseEnhancedPasswordValidation)
            {
                text = text + " with enhanced password validation (Acrobat X or later)";
            }
            page.Graphics.DrawString(text, helvetica, blackBrush, 50, 100);

            return doc;
        }
Ejemplo n.º 30
0
        private static void CreateLineAnnotations(PdfFixedDocument document, PdfFont font)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();

            page.Graphics.DrawString("Line annotations", font, blackBrush, 50, 50);

            PdfLineEndSymbol[] les = new PdfLineEndSymbol[]
            {
                PdfLineEndSymbol.Circle, PdfLineEndSymbol.ClosedArrow, PdfLineEndSymbol.None, PdfLineEndSymbol.OpenArrow
            };

            for (int i = 0; i < les.Length; i++)
            {
                PdfLineAnnotation la = new PdfLineAnnotation();
                page.Annotations.Add(la);
                la.Author        = "Xfinium.Pdf";
                la.Contents      = "I am a line annotation with " + les[i].ToString() + " ending.";
                la.StartPoint    = new PdfPoint(50, 100 + 40 * i);
                la.EndPoint      = new PdfPoint(250, 100 + 40 * i);
                la.EndLineSymbol = les[i];
                page.Graphics.DrawString("Line end symbol: " + les[i].ToString(), font, blackBrush, 270, 100 + 40 * i);
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument   document = new PdfFixedDocument(input);
            PdfContentRedactor crText   = new PdfContentRedactor(document.Pages[0]);

            // Redact a rectangular area of 200*100 points and leave the redacted area uncovered.
            crText.RedactArea(new PdfVisualRectangle(50, 50, 200, 100));
            // Redact a rectangular area of 200*100 points and mark the redacted area with red.
            crText.RedactArea(new PdfVisualRectangle(50, 350, 200, 100), PdfRgbColor.Red);

            PdfContentRedactor crImages = new PdfContentRedactor(document.Pages[2]);

            // Initialize the bulk redaction.
            crImages.BeginRedaction();
            // Prepare for redaction a rectangular area of 500*100 points and leave the redacted area uncovered.
            crImages.RedactArea(new PdfVisualRectangle(50, 50, 500, 100));
            // Prepare for redaction a rectangular area of 200*100 points and mark the redacted area with red.
            crImages.RedactArea(new PdfVisualRectangle(50, 350, 500, 100), PdfRgbColor.Red);
            // When images are redacted, the cleared pixels are set to 0. Depending on image colorspace the redacted area can appear black or colored.
            // Finish the redaction
            crImages.ApplyRedaction();

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.redaction.pdf") };
            return(output);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream file1Input, Stream file2Input)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            // The documents are merged by creating an empty PDF document and appending the file to it.
            // The outlines from the source file are also included in the merged file.
            document.AppendFile(file1Input);
            int count = document.Pages.Count;

            document.AppendFile(file2Input);

            // Create outlines that point to each merged file.
            PdfOutlineItem file1Outline = CreateOutline("First file", document.Pages[0]);

            document.Outline.Add(file1Outline);
            PdfOutlineItem file2Outline = CreateOutline("Second file", document.Pages[count]);

            document.Outline.Add(file2Outline);

            // Optionally we can add a new page at the beginning of the merged document.
            PdfPage page = new PdfPage();

            document.Pages.Insert(0, page);

            PdfOutlineItem blankPageOutline = CreateOutline("Blank page", page);

            document.Outline.Insert(0, blankPageOutline);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.documentappend.pdf") };
            return(output);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFile file = new PdfFile(input);
            PdfPageContent[] content = file.ExtractPageContent(0, file.PageCount - 1);
            file = null;

            PdfFixedDocument document = new PdfFixedDocument();
            PdfPage page1 = document.Pages.Add();
            // Draw the same page content 4 times on the new page, the content is scaled to half and flipped.
            page1.Graphics.DrawFormXObject(content[0],
                0, 0, page1.Width / 2, page1.Height / 2);
            page1.Graphics.DrawFormXObject(content[0],
                page1.Width / 2, 0, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.VerticalFlip);
            page1.Graphics.DrawFormXObject(content[0],
                0, page1.Height / 2, page1.Width / 2, page1.Height / 2, 0, PdfFlipDirection.HorizontalFlip);
            page1.Graphics.DrawFormXObject(content[0],
                page1.Width / 2, page1.Height / 2, page1.Width / 2, page1.Height / 2,
                0, PdfFlipDirection.VerticalFlip | PdfFlipDirection.HorizontalFlip);

            PdfPage page2 = document.Pages.Add();
            // Draw 3 pages on the new page.
            page2.Graphics.DrawFormXObject(content[0],
                0, 0, page2.Width / 2, page2.Height / 2);
            page2.Graphics.DrawFormXObject(content[1],
                page2.Width / 2, 0, page2.Width / 2, page2.Height / 2);
            page2.Graphics.DrawFormXObject(content[2],
                0, page2.Height, page2.Height / 2, page2.Width, 90);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageimposition.pdf") };
            return output;
        }
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfDocumentFeatures df = new PdfDocumentFeatures();
            // Do not load file attachments, new file attachments cannot be added.
            df.EnableDocumentFileAttachments = false;
            // Do not load form fields, form fields cannot be filled and new form fields cannot be added.
            df.EnableDocumentFormFields = false;
            // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added.
            df.EnableDocumentJavaScriptFragments = false;
            // Do not load the named destinations, new named destinations cannot be created.
            df.EnableDocumentNamedDestinations = false;
            // Do not load the document outlines, new outlines cannot be created.
            df.EnableDocumentOutline = false;
            // Do not load annotations, new annotations cannot be added to existing pages.
            df.EnablePageAnnotations = false;
            // Do not load the page graphics, new graphics cannot be added to existing pages.
            df.EnablePageGraphics = false;
            PdfFixedDocument document = new PdfFixedDocument(input, df);

            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 24);
            PdfBrush brush = new PdfBrush();

            // Add a new page with some content on it.
            PdfPage page = document.Pages.Add();
            page.Graphics.DrawString("New page added to an existing document.", helvetica, brush, 20, 50);

            // When document features have been specified at load time the document is automatically saved in incremental update mode.
            document.Save(input);

            return null;
        }
Ejemplo n.º 35
0
        public static response GenerateImgThumbNail(string sType, string path, string fileName, int width, int height)
        {
            FileInfo fi = new FileInfo(Path.Combine(path, fileName));
            //string outputFile = fileName.Replace(fi.Extension, sType == "s" ? "_s.gif" : "_m.gif");
            string outputFile = fileName.Replace(fi.Extension, "_" + sType + ".jpg");

            switch (fi.Extension.ToLower())
            {
            case ".pdf":
                try
                {
                    FileStream       fs   = new FileStream(Path.Combine(path, fileName), FileMode.Open, FileAccess.Read);
                    PdfFixedDocument pDoc = new PdfFixedDocument(fs);
                    fs.Dispose();
                    PdfPageRenderer     renderer = new PdfPageRenderer(pDoc.Pages[0]);
                    PdfRendererSettings s        = new PdfRendererSettings();
                    s.DpiX = s.DpiY = 96;

                    FileStream pngStream = File.OpenWrite(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    renderer.ConvertPageToImage(pngStream, PdfPageImageFormat.Png, s);
                    pngStream.Flush();
                    pngStream.Dispose();

                    response r = SaveThumbNail(sType, path, fileName.Replace(".pdf", ".png"), null, width, height);
                    try
                    {
                        File.Delete(Path.Combine(path, fileName.Replace(".pdf", ".png")));
                    }
                    catch { }
                    return(r);

                    //return new response(false, "eroare", null, null, null);
                }
                catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                    {
                        new Error(exp)
                    })); }

            case ".jpg":
            case ".jpeg":
            case ".png":
            case ".bmp":
                try
                {
                    return(SaveThumbNail(sType, path, fileName, null, width, height));
                }
                catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.ToString(), null, null, new System.Collections.Generic.List <Error>()
                    {
                        new Error(exp)
                    })); }

            default:
                Error err = ErrorParser.ErrorMessage("unsupportedFormat");
                return(new response(false, err.ERROR_MESSAGE, null, null, new System.Collections.Generic.List <Error>()
                {
                    err
                }));
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            document = new PdfFixedDocument(NSBundle.MainBundle.BundlePath + "/xfinium.pdf");
            PageNumberSelector.MaximumValue = document.Pages.Count - 1;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Perform any additional setup after loading the view, typically from a nib.
            document = new PdfFixedDocument (NSBundle.MainBundle.BundlePath + "/xfinium.pdf");
            PageNumberSelector.MaximumValue = document.Pages.Count - 1;
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            document.DisplayMode = PdfDisplayMode.UseOutlines;

            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216);
            PdfBrush blackBrush = new PdfBrush();
            for (int i = 0; i < 10; i++)
            {
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 50, 50);
            }

            PdfOutlineItem root = new PdfOutlineItem();
            root.Title = "Contents";
            root.VisualStyle = PdfOutlineItemVisualStyle.Bold;
            root.Color = new PdfRgbColor(255, 0, 0);
            document.Outline.Add(root);

            for (int i = 0; i < document.Pages.Count; i++)
            {
                // Create a destination to target page.
                PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();
                pageDestination.Page = document.Pages[i];
                pageDestination.Top = 0;
                pageDestination.Left = 0;
                // Inherit current zoom
                pageDestination.Zoom = 0;

                // Create a go to action to be executed when the outline is clicked,
                // the go to action goes to specified destination.
                PdfGoToAction gotoPage = new PdfGoToAction();
                gotoPage.Destination = pageDestination;

                // Create the outline in the table of contents
                PdfOutlineItem outline = new PdfOutlineItem();
                outline.Title = string.Format("Go to page {0}", i + 1);
                outline.VisualStyle = PdfOutlineItemVisualStyle.Italic;
                outline.Action = gotoPage;
                root.Items.Add(outline);
            }
            root.Expanded = true;

            // Create an outline that will launch a link in the browser.
            PdfUriAction uriAction = new PdfUriAction();
            uriAction.URI = "http://www.xfiniumsoft.com/";

            PdfOutlineItem webOutline = new PdfOutlineItem();
            webOutline.Title = "http://www.xfiniumsoft.com/";
            webOutline.Color = new PdfRgbColor(0, 0, 255);
            webOutline.Action = uriAction;
            document.Outline.Add(webOutline);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.outlines.pdf") };
            return output;
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream iccInput, Stream ttfInput)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PdfIccColorSpace icc = new PdfIccColorSpace();

            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PdfOutputIntent oi = new PdfOutputIntent();

            oi.Type = PdfOutputIntentType.PdfA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile  = icc;
            document.OutputIntents       = new PdfOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation          = new PdfDocumentInformation();
            document.DocumentInformation.Author   = "XFINIUM Software";
            document.DocumentInformation.Title    = "XFINIUM.PDF PDF/A-1B Demo";
            document.DocumentInformation.Creator  = "XFINIUM.PDF PDF/A-1B Demo";
            document.DocumentInformation.Producer = "XFINIUM.PDF";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject  = "PDF/A-1B Sample produced by XFINIUM.PDF";
            document.XmpMetadata = new PdfXmpMetadata();

            PdfPage page = document.Pages.Add();

            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Font  = new PdfAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PdfBrush(new PdfRgbColor(0, 0, 128));

            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Graphics.DrawString("XFINIUM.PDF", sao, slo);
            slo.Y             = page.Height / 2 + 10;
            slo.VerticalAlign = PdfStringVerticalAlign.Top;
            sao.Font.Size     = 16;
            page.Graphics.DrawString("This is a sample PDF/A document that shows the PDF/A capabilities in XFINIUM.PDF library", sao, slo);

            // The document is formatted as PDF/A using the PdfAFormatter class:
            // PdfAFormatter.Save(document, outputStream, PdfAFormat.PdfA1b);
            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pdfa.pdf") };
            return(output);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Converts simple XHTML code to a PDF document.
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public PdfFixedDocument Convert(Stream html)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            PdfFormattedContent fc = ConvertHtmlToFormattedContent(html);

            DrawFormattedContent(document, fc);

            return(document);
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;

            Stream pdfStream =
                assembly.GetManifestResourceStream("Xfinium.Pdf.Samples.Pro.WP81.PageThumbnails.xfinium.pdf");
            PdfFixedDocument document = new PdfFixedDocument(pdfStream);
            pdfStream.Dispose();

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.Margin = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                border.Child = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task<PdfBgraByteRenderingSurface>.Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[index]);
                    PdfBgraByteRenderingSurface rs = renderer.CreateRenderingSurface<PdfBgraByteRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return rs;
                })
                    .ContinueWith(value =>
                    {
                        PdfBgraByteRenderingSurface rs = value.Result;
                        WriteableBitmap pageBitmap = new WriteableBitmap(rs.Width, rs.Height);
                        Stream imageStream = pageBitmap.PixelBuffer.AsStream();
                        imageStream.Write(rs.Bitmap, 0, rs.Bitmap.Length);

                        pageThumbnailImages[index].Width = pageBitmap.PixelWidth;
                        pageThumbnailImages[index].Height = pageBitmap.PixelHeight;
                        pageThumbnailImages[index].Source = pageBitmap;

                    }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Decrypts a PDF file
        /// </summary>
        /// <param name="input">Input stream.</param>
        /// <returns></returns>
        private static PdfFixedDocument Decrypt(Stream input)
        {
            PdfFixedDocument doc = new PdfFixedDocument(input, "xfiniumopen");

            PdfPage page = doc.Pages[0];
            PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16);
            PdfBrush blackBrush = new PdfBrush();
            page.Graphics.DrawString("Decrypted document", helvetica, blackBrush, 5, 5);

            return doc;
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfPage page = document.Pages.Add();

            PdfSvgDrawing svg = new PdfSvgDrawing(input);
            page.Graphics.DrawFormXObject(svg, 20, 20, page.Width - 40, page.Width - 40);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.svgtopdf.pdf") };
            return output;
        }
Ejemplo n.º 44
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            StreamResourceInfo xfiniumPdf = Application.GetResourceStream(new Uri("xfinium.pdf", UriKind.Relative));
            PdfFixedDocument document = new PdfFixedDocument(xfiniumPdf.Stream);
            xfiniumPdf.Stream.Close();
            (Application.Current as App).Document = document;

            int i = 0;

            pageThumbnailImages = new Image[document.Pages.Count];

            for (i = 0; i < document.Pages.Count; i++)
            {
                Border border = new Border();
                border.BorderThickness = new Thickness(1);
                border.BorderBrush = new SolidColorBrush(Colors.Black);
                border.Margin = new Thickness(10, 10, 0, 0);

                Image pageImage = new Image();
                pageImage.Tag = i;
                pageImage.Tap += pageImage_Tap;
                border.Child = pageImage;
                pageThumbnailImages[i] = pageImage;

                pageThumbnails.Children.Add(border);
            }

            for (i = 0; i < document.Pages.Count; i++)
            {
                int index = i;

                var t = Task<PdfArgbIntRenderingSurface>.Factory.StartNew(() =>
                {
                    PdfPageRenderer renderer = new PdfPageRenderer(document.Pages[index]);
                    PdfArgbIntRenderingSurface rs = renderer.CreateRenderingSurface<PdfArgbIntRenderingSurface>(thumbnailDpi, thumbnailDpi);
                    PdfRendererSettings settings = new PdfRendererSettings(thumbnailDpi, thumbnailDpi, rs);
                    renderer.ConvertPageToImage(settings);

                    return rs;
                })
                    .ContinueWith(value =>
                    {
                        PdfArgbIntRenderingSurface rs = value.Result;
                        WriteableBitmap wb = new WriteableBitmap(rs.Width, rs.Height);
                        Array.Copy(rs.Bitmap, wb.Pixels, rs.Bitmap.Length);
                        pageThumbnailImages[index].Width = wb.PixelWidth;
                        pageThumbnailImages[index].Height = wb.PixelHeight;
                        pageThumbnailImages[index].Source = wb;

                    }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream iccInput, Stream ttfInput)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PdfIccColorSpace icc = new PdfIccColorSpace();
            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PdfOutputIntent oi = new PdfOutputIntent();
            oi.Type = PdfOutputIntentType.PdfA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile = icc;
            document.OutputIntents = new PdfOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation = new PdfDocumentInformation();
            document.DocumentInformation.Author = "XFINIUM Software";
            document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-1B Demo";
            document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-1B Demo";
            document.DocumentInformation.Producer = "XFINIUM.PDF";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject = "PDF/A-1B Sample produced by XFINIUM.PDF";
            document.XmpMetadata = new PdfXmpMetadata();

            PdfPage page = document.Pages.Add();
            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Font = new PdfAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PdfBrush(new PdfRgbColor(0, 0, 128));

            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Graphics.DrawString("XFINIUM.PDF", sao, slo);
            slo.Y = page.Height / 2 + 10;
            slo.VerticalAlign = PdfStringVerticalAlign.Top;
            sao.Font.Size = 16;
            page.Graphics.DrawString("This is a sample PDF/A document that shows the PDF/A capabilities in XFINIUM.PDF library", sao, slo);

            // The document is formatted as PDF/A using the PdfAFormatter class:
            // PdfAFormatter.Save(document, outputStream, PdfAFormat.PdfA1b);
            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pdfa.pdf") };
            return output;
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;

            Stream pdfStream =
                assembly.GetManifestResourceStream("Xfinium.Pdf.Samples.Pro.WP81.PDFToImage.xfinium.pdf");
            document = new PdfFixedDocument(pdfStream);
            pdfStream.Dispose();

            for (int i = 0; i < document.Pages.Count; i++)
            {
                cbxPageNumber.Items.Add(i + 1);
            }
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // Load the input file.
            PdfFixedDocument document = new PdfFixedDocument(input);

            PdfReplaceImageTransform replaceImageTransform = new PdfReplaceImageTransform();
            replaceImageTransform.ReplaceImage += new EventHandler<PdfReplaceImageEventArgs>(HandleReplaceImage);
            PdfPageTransformer pageTransformer = new PdfPageTransformer(document.Pages[2]);
            pageTransformer.ApplyTransform(replaceImageTransform);
            replaceImageTransform.ReplaceImage -= new EventHandler<PdfReplaceImageEventArgs>(HandleReplaceImage);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.removereplaceimages.pdf") };
            return output;
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfTiffImage tiff = new PdfTiffImage(input);

            for (int i = 0; i < tiff.FrameCount; i++)
            {
                tiff.ActiveFrame = i;
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawImage(tiff, 0, 0, page.Width, page.Height);
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.tifftopdf.pdf") };
            return output;
        }
Ejemplo n.º 49
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            StreamResourceInfo pdfStream = Application.GetResourceStream(new Uri("xfinium.pdf", UriKind.Relative));
            document = new PdfFixedDocument(pdfStream.Stream);
            pdfStream.Stream.Close();

            for (int i = 0; i < document.Pages.Count; i++)
            {
                RadioButton rbtn = new RadioButton();
                rbtn.Content = (i + 1).ToString();
                rbtn.Tag = i;
                rbtn.Click += rbtn_Click;
                pageList.Children.Add(rbtn);
            }
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimplePagerAdapter"/> class able to present PDF documents.
        /// </summary>
        /// <param name="baseContext">The base context.</param>
        /// <param name="doc">The document.</param>
        public EasyPagerAdapter(Context baseContext, int kol,CustomViewPager VP,PdfFixedDocument docm)
        {
            this.col = kol;
            this.baseContext = baseContext;
            this.tVP = VP;
            views = new ScaleImageView[col];
            bitmaps = new Bitmap[col];

            cacheDirName = "PagesCache";

            syncObject = new object();

            doc = docm;

            InitializeCache();
        }
Ejemplo n.º 51
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // The input file is split by extracting pages from source file and inserting them in new empty PDF documents.
            PdfFile file = new PdfFile(input);
            SampleOutputInfo[] output = new SampleOutputInfo[file.PageCount];

            for (int i = 0; i < file.PageCount; i++)
            {
                PdfFixedDocument document = new PdfFixedDocument();
                PdfPage page = file.ExtractPage(i);
                document.Pages.Add(page);

                output[i] = new SampleOutputInfo(document, string.Format("xfinium.pdf.sample.documentsplit.{0}.pdf", i + 1));
            }

            return output;
        }
Ejemplo n.º 52
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream output)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            // Init the save operation
            document.BeginSave(output);

            PdfRgbColor color = new PdfRgbColor();
            PdfBrush brush = new PdfBrush(color);
            Random rnd = new Random();

            for (int i = 0; i < 3; i++)
            {
                PdfPage page = document.Pages.Add();
                page.Width = 1000;
                page.Height = 1000;

                for (int y = 1; y <= page.Height; y++)
                {
                    for (int x = 0; x < page.Width; x++)
                    {
                        color.R = (byte)rnd.Next(256);
                        color.G = (byte)rnd.Next(256);
                        color.B = (byte)rnd.Next(256);

                        page.Graphics.DrawRectangle(brush, x, y - 1, 1, 1);
                    }

                    if ((y % 100) == 0)
                    {
                        // Compress the graphics that have been drawn so far and save them.
                        page.Graphics.Compress();
                        page.SaveGraphics();
                    }
                }

                // Close the page graphics and save the page.
                page.Graphics.CompressAndClose();
                page.Save();
            }

            // Finish the document.
            document.EndSave();

            return null;
        }
Ejemplo n.º 53
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run()
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16);

            PdfPage page = document.Pages.Add();
            DrawTextLines(page, helveticaBold);

            page = document.Pages.Add();
            DrawTextWrap(page, helveticaBold);

            page = document.Pages.Add();
            DrawTextRenderingModes(page, helveticaBold);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.text.pdf") };
            return output;
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        /// <param name="stream"></param>
        public static SampleOutputInfo[] Run(Stream stream)
        {
            PdfFixedDocument document = new PdfFixedDocument(stream);
            (document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John";
            (document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe";

            (document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true;

            (document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0;

            (document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1;

            (document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true;
            document.Form.FlattenFields();

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formfill.pdf") };
            return output;
        }
Ejemplo n.º 55
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream ttfStream)
        {
            PdfFixedDocument document = new PdfFixedDocument();

            PdfPage page = document.Pages.Add();
            DrawStandardFonts(page);

            page = document.Pages.Add();
            DrawStandardCjkFonts(page);

            page = document.Pages.Add();
            DrawTrueTypeFonts(page, ttfStream);

            page = document.Pages.Add();
            DisableTextCopy(page, ttfStream);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fonts.pdf") };
            return output;
        }
Ejemplo n.º 56
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // Load the input file.
            PdfFixedDocument document = new PdfFixedDocument(input);

            PdfBatesNumberAppearance bna = new PdfBatesNumberAppearance();
            bna.Location = new PdfPoint(25, 5);
            bna.Brush = new PdfBrush(PdfRgbColor.DarkRed);

            PdfBatesNumberProvider bnp = new PdfBatesNumberProvider();
            bnp.Prefix = "XFINIUM";
            bnp.Suffix = "PDF";
            bnp.StartNumber = 1;

            PdfBatesNumber.WriteBatesNumber(document, bnp, bna);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.batesnumbers.pdf") };
            return output;
        }
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFile file = new PdfFile(input);

            PdfFixedDocument document = new PdfFixedDocument();
            PdfPage page = document.Pages.Add();

            PdfPageOptionalContent oc1 = file.ExtractPageOptionalContentGroup(4, "1");
            page.Graphics.DrawFormXObject(oc1, 0, 0, page.Width / 2, page.Height / 2);
            PdfPageOptionalContent oc2 = file.ExtractPageOptionalContentGroup(4, "2");
            page.Graphics.DrawFormXObject(oc2, page.Width / 2, 0, page.Width / 2, page.Height / 2);
            PdfPageOptionalContent oc3 = file.ExtractPageOptionalContentGroup(4, "3");
            page.Graphics.DrawFormXObject(oc3, 0, page.Height / 2, page.Width / 2, page.Height / 2);
            PdfPageOptionalContent oc4 = file.ExtractPageOptionalContentGroup(4, "4");
            page.Graphics.DrawFormXObject(oc4, page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontentextraction.pdf") };
            return output;
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        /// <param name="iccStream"></param>
        public static SampleOutputInfo[] Run(Stream iccStream)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16);
            PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10);

            PdfPage page = document.Pages.Add();
            DrawLines(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawRectangles(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawRoundRectangles(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawEllipses(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawArcsAndPies(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawBezierCurves(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawAffineTransformations(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawColorsAndColorSpaces(page, helveticaBoldTitle, helveticaSection, iccStream);

            page = document.Pages.Add();
            DrawShadings(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawPatterns(page, helveticaBoldTitle, helveticaSection);

            page = document.Pages.Add();
            DrawFormXObjects(page, helveticaBoldTitle, helveticaSection);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.vectorgraphics.pdf") };
            return output;
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument document = new PdfFixedDocument(input);
            PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]);

            // Simple search.
            PdfTextSearchResultCollection searchResults = ce.SearchText("at");
            HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Red);

            // Whole words search.
            searchResults = ce.SearchText("at", PdfTextSearchOptions.WholeWordSearch);
            HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Green);

            // Regular expression search, find all words that start with uppercase.
            searchResults = ce.SearchText("[A-Z][a-z]*", PdfTextSearchOptions.RegExSearch);
            HighlightSearchResults(document.Pages[0], searchResults, PdfRgbColor.Blue);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.searchtext.pdf") };
            return output;
        }
Ejemplo n.º 60
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // Load the input file.
            PdfFixedDocument document = new PdfFixedDocument(input);

            DrawWatermarkUnderPageContent(document.Pages[0]);

            DrawWatermarkOverPageContent(document.Pages[1]);

            DrawWatermarkWithTransparency(document.Pages[2]);

            // Compress the page graphic content.
            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.CompressAndClose();
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.watermarks.pdf") };
            return output;
        }