private void btnRunSample_Click(object sender, EventArgs e)
        {
            if (sampleID != null)
            {
                SampleOutputInfo[] output       = null;
                MemoryStream       outputStream = null;
                Assembly           asm          = Assembly.GetExecutingAssembly();

                switch (sampleID)
                {
                case "actions":
                    output = Xfinium.Pdf.Samples.Actions.Run();
                    break;

                case "annotations":
                    Stream flashInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.clock.swf");
                    Stream u3dInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.airplane.u3d");
                    output = Xfinium.Pdf.Samples.Annotations.Run(flashInput, u3dInput);
                    flashInput.Close();
                    u3dInput.Close();
                    break;

                case "barcodes":
                    output = Xfinium.Pdf.Samples.Barcodes.Run();
                    break;

                case "batesnumbers":
                    Stream batesNumbersInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.BatesNumbers.Run(batesNumbersInput);
                    batesNumbersInput.Close();
                    batesNumbersInput = null;
                    break;

                case "contentextraction":
                    Stream contentExtractionInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.ContentExtraction.Run(contentExtractionInput);
                    contentExtractionInput.Close();
                    contentExtractionInput = null;
                    break;

                case "contentstream":
                    output = Xfinium.Pdf.Samples.ContentStream.Run();
                    break;

                case "documentappend":
                    Stream file1Input =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    Stream file2Input =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.formfill.pdf");
                    output = Xfinium.Pdf.Samples.DocumentAppend.Run(file1Input, file2Input);
                    file1Input.Close();
                    file2Input.Close();
                    break;

                case "documentincrementalupdate":
                    outputStream = new MemoryStream();
                    Stream sri =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    byte[] buffer = new byte[8192];
                    while (true)
                    {
                        int readSize = sri.Read(buffer, 0, buffer.Length);
                        if (readSize <= 0)
                        {
                            break;
                        }
                        outputStream.Write(buffer, 0, readSize);
                    }
                    sri.Close();

                    output = Xfinium.Pdf.Samples.DocumentIncrementalUpdate.Run(outputStream);
                    break;

                case "documentpagebypagesave":
                    outputStream = new MemoryStream();
                    output       = Xfinium.Pdf.Samples.DocumentPageByPageSave.Run(outputStream);
                    break;

                case "documentproperties":
                    output = Xfinium.Pdf.Samples.DocumentProperties.Run();
                    break;

                case "documentsplit":
                    Stream splitInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.DocumentSplit.Run(splitInput);
                    splitInput.Close();
                    break;

                case "encryption":
                    Stream encryptionInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.encrypted.pdf");
                    output = Xfinium.Pdf.Samples.Encryption.Run(encryptionInput);
                    encryptionInput.Close();
                    break;

                case "fileattachments":
                    Stream attachmentStream1 = Assets.Open("fileattachments_cs.html");
                    Stream attachmentStream2 = Assets.Open("fileattachments_vb.html");
                    output = Xfinium.Pdf.Samples.FileAttachments.Run(attachmentStream1, attachmentStream2);
                    attachmentStream1.Close();
                    attachmentStream2.Close();
                    break;

                case "fonts":
                    Stream ttfStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.verdana.ttf");
                    output = Xfinium.Pdf.Samples.Fonts.Run(ttfStream);
                    ttfStream.Close();
                    break;

                case "formattedcontent":
                    output = Xfinium.Pdf.Samples.FormattedContent.Run();
                    break;

                case "formfill":
                    Stream formStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.formfill.pdf");
                    output = Xfinium.Pdf.Samples.FormFill.Run(formStream);
                    formStream.Close();
                    break;

                case "formgenerator":
                    output = Xfinium.Pdf.Samples.FormGenerator.Run();
                    break;

                case "grayscaleconversion":
                    Stream grayscaleConversionInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.GrayscaleConversion.Run(grayscaleConversionInput);
                    grayscaleConversionInput.Close();
                    break;

                case "images":
                    Stream imageStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.image.jpg");
                    Stream cmykImageStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.cmyk.tif");
                    Stream softMaskStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.softmask.png");
                    Stream stencilMaskStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.stencilmask.png");
                    output = Xfinium.Pdf.Samples.Images.Run(imageStream, cmykImageStream, softMaskStream, stencilMaskStream);
                    imageStream.Close();
                    cmykImageStream.Close();
                    softMaskStream.Close();
                    stencilMaskStream.Close();
                    break;

                case "measurements":
                    output = Xfinium.Pdf.Samples.Measurements.Run();
                    break;

                case "optionalcontent":
                    output = Xfinium.Pdf.Samples.OptionalContent.Run();
                    break;

                case "optionalcontentextraction":
                    Stream oceInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.OptionalContentExtraction.Run(oceInput);
                    oceInput.Close();
                    break;

                case "outlines":
                    output = Xfinium.Pdf.Samples.Outlines.Run();
                    break;

                case "pageimposition":
                    Stream pageImpositionInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.PageImposition.Run(pageImpositionInput);
                    pageImpositionInput.Close();
                    break;

                case "pageobjects":
                    Stream pageObjectsInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.pageobjects.pdf");
                    output = Xfinium.Pdf.Samples.PageObjects.Run(pageObjectsInput);
                    pageObjectsInput.Close();
                    break;

                case "pdfa":
                    Stream pdfaIccInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.rgb.icc");
                    Stream pdfaTtfInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.verdana.ttf");
                    output = Xfinium.Pdf.Samples.PDFA.Run(pdfaIccInput, pdfaTtfInput);
                    pdfaIccInput.Close();
                    pdfaTtfInput.Close();
                    break;

                case "portfolios":
                    Stream imagesStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.image.jpg");
                    Stream pdfStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    Stream csStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.portfolios_cs.html");
                    Stream vbStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.portfolios_vb.html");
                    output = Xfinium.Pdf.Samples.Portfolios.Run(imagesStream, pdfStream, csStream, vbStream);
                    imagesStream.Close();
                    pdfStream.Close();
                    csStream.Close();
                    vbStream.Close();
                    break;

                case "redaction":
                    Stream redactionStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.Redaction.Run(redactionStream);
                    redactionStream.Close();
                    break;

                case "removereplaceimages":
                    Stream removeReplaceImagesInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.RemoveReplaceImages.Run(removeReplaceImagesInput);
                    removeReplaceImagesInput.Close();
                    break;

                case "searchtext":
                    Stream searchTextInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.SearchText.Run(searchTextInput);
                    searchTextInput.Close();
                    break;

                case "svgtopdf":
                    Stream svgInput =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.tiger.svg");
                    output = Xfinium.Pdf.Samples.SvgToPdf.Run(svgInput);
                    svgInput.Close();
                    break;

                case "text":
                    output = Xfinium.Pdf.Samples.Text.Run();
                    break;

                case "tifftopdf":
                    Stream tiffStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.sample.tif");
                    output = Xfinium.Pdf.Samples.TiffToPdf.Run(tiffStream);
                    tiffStream.Close();
                    break;

                case "type3fonts":
                    output = Xfinium.Pdf.Samples.Type3Fonts.Run();
                    break;

                case "vectorgraphics":
                    Stream iccStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.rgb.icc");
                    output = Xfinium.Pdf.Samples.VectorGraphics.Run(iccStream);
                    iccStream.Close();
                    break;

                case "watermarks":
                    Stream watermarkStream =
                        asm.GetManifestResourceStream("Xfinium.Pdf.SamplesExplorer.Xamarin.Android.Support.content.pdf");
                    output = Xfinium.Pdf.Samples.Watermarks.Run(watermarkStream);
                    watermarkStream.Close();
                    break;
                }

                string pdfPath = "";
                if (output != null)
                {
                    if (sampleID == "pdfa")
                    {
                        pdfPath = System.IO.Path.Combine(
                            System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), output[0].FileName);
                        Stream pdfStream = File.Open(pdfPath, FileMode.Create);
                        PdfAFormatter.Save(output[0].Document as PdfFixedDocument, pdfStream, PdfAFormat.PdfA1b);
                        pdfStream.Flush();
                        pdfStream.Close();
                    }
                    else
                    {
                        for (int i = 0; i < output.Length; i++)
                        {
                            pdfPath = System.IO.Path.Combine(
                                System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), output[i].FileName);
                            Stream pdfStream = File.Open(pdfPath, FileMode.Create);
                            output[i].Document.Save(pdfStream);
                            pdfStream.Flush();
                            pdfStream.Close();
                        }
                    }
                }

                if (outputStream != null)
                {
                    string fileName = "";
                    switch (sampleID)
                    {
                    case "documentincrementalupdate":
                        fileName = "xfinium.pdf.sample.documentincrementalupdate.pdf";
                        break;

                    case "documentpagebypagesave":
                        fileName = "xfinium.pdf.sample.documentpagebypagesave.pdf";
                        break;
                    }

                    pdfPath = System.IO.Path.Combine(
                        System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), fileName);
                    Stream pdfStream = File.Open(pdfPath, FileMode.Create);
                    outputStream.WriteTo(pdfStream);
                    pdfStream.Flush();
                    pdfStream.Close();
                }

                Java.IO.File file = new Java.IO.File(pdfPath);
                file.SetReadable(true, false);
                global::Android.Net.Uri u = global::Android.Net.Uri.FromFile(file);
                Intent intent             = new Intent(Intent.ActionView);
                intent.SetDataAndType(u, "application/pdf");
                intent.SetFlags(ActivityFlags.ClearTop);

                try
                {
                    StartActivity(intent);
                }
                catch (ActivityNotFoundException ex)
                {
                    Toast.MakeText(this, "No PDF viewer available", ToastLength.Short).Show();
                }
            }
        }
Пример #2
0
        private void RunSample_Click(object sender, RoutedEventArgs e)
        {
            SampleViewModel svm = DataContext as SampleViewModel;

            if (svm != null)
            {
                SampleOutputInfo[] output       = null;
                MemoryStream       outputStream = null;

                switch (svm.ID)
                {
                case "actions":
                    output = Xfinium.Pdf.Samples.Actions.Run();
                    break;

                case "annotations":
                    StreamResourceInfo flashInput = Application.GetResourceStream(new Uri("support/clock.swf", UriKind.Relative));
                    StreamResourceInfo u3dInput   = Application.GetResourceStream(new Uri("support/airplane.u3d", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Annotations.Run(flashInput.Stream, u3dInput.Stream);
                    flashInput.Stream.Close();
                    u3dInput.Stream.Close();
                    break;

                case "barcodes":
                    output = Xfinium.Pdf.Samples.Barcodes.Run();
                    break;

                case "contentextraction":
                    StreamResourceInfo contentExtractionInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.ContentExtraction.Run(contentExtractionInput.Stream);
                    contentExtractionInput.Stream.Close();
                    contentExtractionInput = null;
                    break;

                case "contentstream":
                    output = Xfinium.Pdf.Samples.ContentStream.Run();
                    break;

                case "batesnumbers":
                    StreamResourceInfo batesNumbersInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.BatesNumbers.Run(batesNumbersInput.Stream);
                    batesNumbersInput.Stream.Close();
                    batesNumbersInput = null;
                    break;

                case "documentappend":
                    StreamResourceInfo file1Input = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    StreamResourceInfo file2Input = Application.GetResourceStream(new Uri("support/formfill.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.DocumentAppend.Run(file1Input.Stream, file2Input.Stream);
                    file1Input.Stream.Close();
                    file2Input.Stream.Close();
                    break;

                case "documentincrementalupdate":
                    outputStream = new MemoryStream();

                    StreamResourceInfo sri    = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    byte[]             buffer = new byte[8192];
                    while (true)
                    {
                        int readSize = sri.Stream.Read(buffer, 0, buffer.Length);
                        if (readSize <= 0)
                        {
                            break;
                        }
                        outputStream.Write(buffer, 0, readSize);
                    }
                    sri.Stream.Close();

                    output = Xfinium.Pdf.Samples.DocumentIncrementalUpdate.Run(outputStream);
                    break;

                case "documentpagebypagesave":
                    outputStream = new MemoryStream();
                    output       = Xfinium.Pdf.Samples.DocumentPageByPageSave.Run(outputStream);
                    break;

                case "documentproperties":
                    output = Xfinium.Pdf.Samples.DocumentProperties.Run();
                    break;

                case "documentsplit":
                    StreamResourceInfo splitInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.DocumentSplit.Run(splitInput.Stream);
                    splitInput.Stream.Close();
                    break;

                case "encryption":
                    StreamResourceInfo encryptionInput = Application.GetResourceStream(new Uri("support/encrypted.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Encryption.Run(encryptionInput.Stream);
                    encryptionInput.Stream.Close();
                    break;

                case "fileattachments":
                    StreamResourceInfo attachmentStream1 = Application.GetResourceStream(new Uri("support/fileattachments.cs.html", UriKind.Relative));
                    StreamResourceInfo attachmentStream2 = Application.GetResourceStream(new Uri("support/fileattachments.vb.html", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.FileAttachments.Run(attachmentStream1.Stream, attachmentStream2.Stream);
                    attachmentStream1.Stream.Close();
                    attachmentStream2.Stream.Close();
                    break;

                case "fonts":
                    StreamResourceInfo ttfResource = Application.GetResourceStream(new Uri("support/verdana.ttf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Fonts.Run(ttfResource.Stream);
                    ttfResource.Stream.Close();
                    break;

                case "formattedcontent":
                    output = Xfinium.Pdf.Samples.FormattedContent.Run();
                    break;

                case "formfill":
                    StreamResourceInfo formStream = Application.GetResourceStream(new Uri("support/formfill.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.FormFill.Run(formStream.Stream);
                    formStream.Stream.Close();
                    break;

                case "formgenerator":
                    output = Xfinium.Pdf.Samples.FormGenerator.Run();
                    break;

                case "grayscaleconversion":
                    StreamResourceInfo grayscaleConversionInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.GrayscaleConversion.Run(grayscaleConversionInput.Stream);
                    grayscaleConversionInput.Stream.Close();
                    break;

                case "images":
                    StreamResourceInfo imageStream       = Application.GetResourceStream(new Uri("support/image.jpg", UriKind.Relative));
                    StreamResourceInfo cmykImageStream   = Application.GetResourceStream(new Uri("support/cmyk.tif", UriKind.Relative));
                    StreamResourceInfo softMaskStream    = Application.GetResourceStream(new Uri("support/softmask.png", UriKind.Relative));
                    StreamResourceInfo stencilMaskStream = Application.GetResourceStream(new Uri("support/stencilmask.png", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Images.Run(imageStream.Stream, cmykImageStream.Stream, softMaskStream.Stream, stencilMaskStream.Stream);
                    imageStream.Stream.Close();
                    cmykImageStream.Stream.Close();
                    softMaskStream.Stream.Close();
                    stencilMaskStream.Stream.Close();
                    break;

                case "measurements":
                    output = Xfinium.Pdf.Samples.Measurements.Run();
                    break;

                case "optionalcontent":
                    output = Xfinium.Pdf.Samples.OptionalContent.Run();
                    break;

                case "optionalcontentextraction":
                    StreamResourceInfo oceInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.OptionalContentExtraction.Run(oceInput.Stream);
                    oceInput.Stream.Close();
                    break;

                case "outlines":
                    output = Xfinium.Pdf.Samples.Outlines.Run();
                    break;

                case "pageimposition":
                    StreamResourceInfo pageImpositionInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.PageImposition.Run(pageImpositionInput.Stream);
                    pageImpositionInput.Stream.Close();
                    break;

                case "pageobjects":
                    StreamResourceInfo pageObjectsInput = Application.GetResourceStream(new Uri("support/pageobjects.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.PageObjects.Run(pageObjectsInput.Stream);
                    pageObjectsInput.Stream.Close();
                    break;

                case "pdfa":
                    StreamResourceInfo pdfaIccInput = Application.GetResourceStream(new Uri("support/rgb.icc", UriKind.Relative));
                    StreamResourceInfo pdfaTtfInput = Application.GetResourceStream(new Uri("support/verdana.ttf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.PDFA.Run(pdfaIccInput.Stream, pdfaTtfInput.Stream);
                    pdfaIccInput.Stream.Close();
                    pdfaTtfInput.Stream.Close();
                    break;

                case "portfolios":
                    StreamResourceInfo imagesStream = Application.GetResourceStream(new Uri("support/image.jpg", UriKind.Relative));
                    StreamResourceInfo pdfStream    = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    StreamResourceInfo csStream     = Application.GetResourceStream(new Uri("support/portfolios.cs.html", UriKind.Relative));
                    StreamResourceInfo vbStream     = Application.GetResourceStream(new Uri("support/portfolios.vb.html", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Portfolios.Run(imagesStream.Stream, pdfStream.Stream, csStream.Stream, vbStream.Stream);
                    imagesStream.Stream.Close();
                    pdfStream.Stream.Close();
                    csStream.Stream.Close();
                    vbStream.Stream.Close();
                    break;

                case "redaction":
                    StreamResourceInfo redactionStream = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Redaction.Run(redactionStream.Stream);
                    redactionStream.Stream.Close();
                    break;

                case "removereplaceimages":
                    StreamResourceInfo removeReplaceImagesInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.RemoveReplaceImages.Run(removeReplaceImagesInput.Stream);
                    removeReplaceImagesInput.Stream.Close();
                    break;

                case "searchtext":
                    StreamResourceInfo searchTextInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.SearchText.Run(searchTextInput.Stream);
                    searchTextInput.Stream.Close();
                    break;

                case "svgtopdf":
                    StreamResourceInfo svgInput = Application.GetResourceStream(new Uri("support/tiger.svg", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.SvgToPdf.Run(svgInput.Stream);
                    svgInput.Stream.Close();
                    break;

                case "text":
                    output = Xfinium.Pdf.Samples.Text.Run();
                    break;

                case "tifftopdf":
                    StreamResourceInfo tiffStream = Application.GetResourceStream(new Uri("support/sample.tif", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.TiffToPdf.Run(tiffStream.Stream);
                    tiffStream.Stream.Close();
                    break;

                case "type3fonts":
                    output = Xfinium.Pdf.Samples.Type3Fonts.Run();
                    break;

                case "vectorgraphics":
                    StreamResourceInfo iccStream = Application.GetResourceStream(new Uri("support/rgb.icc", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.VectorGraphics.Run(iccStream.Stream);
                    iccStream.Stream.Close();
                    break;

                case "watermarks":
                    StreamResourceInfo watermarksInput = Application.GetResourceStream(new Uri("support/content.pdf", UriKind.Relative));
                    output = Xfinium.Pdf.Samples.Watermarks.Run(watermarksInput.Stream);
                    watermarksInput.Stream.Close();
                    break;
                }

                if (output != null)
                {
                    IsolatedStorageFile       fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
                    IsolatedStorageFileStream pdfStream   = new IsolatedStorageFileStream(output[0].FileName, FileMode.Create, fileStorage);
                    if (svm.ID == "pdfa")
                    {
                        PdfAFormatter.Save(output[0].Document as PdfFixedDocument, pdfStream, PdfAFormat.PdfA1b);
                    }
                    else
                    {
                        output[0].Document.Save(pdfStream);
                    }
                    pdfStream.Flush();
                    pdfStream.Close();

                    MessageBox.Show("Sample completed with success. File " + output[0].FileName + " saved to isolated storage.", "Xfinium.Pdf Samples Explorer", MessageBoxButton.OK);
                }
                if (outputStream != null)
                {
                    string fileName = "";
                    switch (svm.ID)
                    {
                    case "documentincrementalupdate":
                        fileName = "xfinium.pdf.sample.documentincrementalupdate.pdf";
                        break;

                    case "documentpagebypagesave":
                        fileName = "xfinium.pdf.sample.documentpagebypagesave.pdf";
                        break;
                    }

                    IsolatedStorageFile       fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
                    IsolatedStorageFileStream pdfStream   = new IsolatedStorageFileStream(fileName, FileMode.Create, fileStorage);
                    outputStream.WriteTo(pdfStream);
                    pdfStream.Flush();
                    pdfStream.Close();

                    MessageBox.Show("Sample completed with success. File " + fileName + " saved to isolated storage.", "Xfinium.Pdf Samples Explorer", MessageBoxButton.OK);
                }
            }
        }
Пример #3
0
        partial void runSampleClick(NSObject sender)
        {
            SampleOutputInfo[] output      = null;
            string             contentPath = Path.Combine(NSBundle.MainBundle.BundlePath, "Support/");
            string             outputPath  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            switch (currentSample.ID)
            {
            case "actions":
                output = Xfinium.Pdf.Samples.Actions.Run();
                break;

            case "annotations":
                FileStream flashInput = new FileStream(contentPath + "clock.swf", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream u3dInput   = new FileStream(contentPath + "airplane.u3d", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Annotations.Run(flashInput, u3dInput);
                flashInput.Close();
                u3dInput.Close();
                break;

            case "barcodes":
                output = Xfinium.Pdf.Samples.Barcodes.Run();
                break;

            case "batesnumbers":
                FileStream batesNumbersInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.BatesNumbers.Run(batesNumbersInput);
                batesNumbersInput.Close();
                break;

            case "contentextraction":
                FileStream contentExtractionInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.ContentExtraction.Run(contentExtractionInput);
                contentExtractionInput.Close();
                break;

            case "contentstream":
                output = Xfinium.Pdf.Samples.ContentStream.Run();
                break;

            case "documentappend":
                FileStream file1Input = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream file2Input = new FileStream(contentPath + "formfill.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.DocumentAppend.Run(file1Input, file2Input);
                file1Input.Close();
                file2Input.Close();
                break;

            case "documentincrementalupdate":
                File.Copy(contentPath + "content.pdf", outputPath + "/xfinium.pdf.sample.documentincrementalupdate.pdf", true);
                FileStream incrementalUpdateInput = new FileStream(outputPath + "/xfinium.pdf.sample.documentincrementalupdate.pdf", FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
                output      = Xfinium.Pdf.Samples.DocumentIncrementalUpdate.Run(incrementalUpdateInput);
                pdfFileName = "xfinium.pdf.sample.documentincrementalupdate.pdf";
                incrementalUpdateInput.Flush();
                incrementalUpdateInput.Close();
                break;

            case "documentpagebypagesave":
                FileStream documentPageByPageSaveOutput = new FileStream(outputPath + "/xfinium.pdf.sample.documentpagebypagesave.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
                output = Xfinium.Pdf.Samples.DocumentPageByPageSave.Run(documentPageByPageSaveOutput);
                documentPageByPageSaveOutput.Flush();
                documentPageByPageSaveOutput.Close();
                pdfFileName = "xfinium.pdf.sample.documentpagebypagesave.pdf";
                break;

            case "documentproperties":
                output = Xfinium.Pdf.Samples.DocumentProperties.Run();
                break;

            case "documentsplit":
                FileStream splitInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.DocumentSplit.Run(splitInput);
                splitInput.Close();
                break;

            case "encryption":
                FileStream encryptionInput = new FileStream(contentPath + "encrypted.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Encryption.Run(encryptionInput);
                encryptionInput.Close();
                break;

            case "fileattachments":
                FileStream attachmentStream1 = new FileStream(contentPath + "fileattachments_cs.html", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream attachmentStream2 = new FileStream(contentPath + "fileattachments_vb.html", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.FileAttachments.Run(attachmentStream1, attachmentStream2);
                attachmentStream1.Close();
                attachmentStream2.Close();
                break;

            case "fonts":
                FileStream ttfStream = new FileStream(contentPath + "verdana.ttf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Fonts.Run(ttfStream);
                ttfStream.Close();
                break;

            case "formattedcontent":
                output = Xfinium.Pdf.Samples.FormattedContent.Run();
                break;

            case "formfill":
                FileStream formStream = new FileStream(contentPath + "formfill.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.FormFill.Run(formStream);
                formStream.Close();
                break;

            case "formgenerator":
                output = Xfinium.Pdf.Samples.FormGenerator.Run();
                break;

            case "grayscaleconversion":
                FileStream grayscaleConversionInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.GrayscaleConversion.Run(grayscaleConversionInput);
                grayscaleConversionInput.Close();
                break;

            case "images":
                FileStream imageStream       = new FileStream(contentPath + "image.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream cmykImageStream   = new FileStream(contentPath + "cmyk.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream softMaskStream    = new FileStream(contentPath + "softmask.png", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream stencilMaskStream = new FileStream(contentPath + "stencilmask.png", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Images.Run(imageStream, cmykImageStream, softMaskStream, stencilMaskStream);
                imageStream.Close();
                cmykImageStream.Close();
                softMaskStream.Close();
                stencilMaskStream.Close();
                break;

            case "measurements":
                output = Xfinium.Pdf.Samples.Measurements.Run();
                break;

            case "optionalcontent":
                output = Xfinium.Pdf.Samples.OptionalContent.Run();
                break;

            case "optionalcontentextraction":
                FileStream oceInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.OptionalContentExtraction.Run(oceInput);
                oceInput.Close();
                break;

            case "outlines":
                output = Xfinium.Pdf.Samples.Outlines.Run();
                break;

            case "pageimposition":
                FileStream pageImpositionInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.PageImposition.Run(pageImpositionInput);
                pageImpositionInput.Close();
                break;

            case "pageobjects":
                FileStream pageObjectsInput = new FileStream(contentPath + "pageobjects.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.PageObjects.Run(pageObjectsInput);
                pageObjectsInput.Close();
                break;

            case "pdfa":
                FileStream pdfaIccInput = new FileStream(contentPath + "rgb.icc", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream pdfaTtfInput = new FileStream(contentPath + "verdana.ttf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.PDFA.Run(pdfaIccInput, pdfaTtfInput);
                pdfaIccInput.Close();
                pdfaTtfInput.Close();
                break;

            case "portfolios":
                FileStream imagesStream = new FileStream(contentPath + "image.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream pdfStream    = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream csStream     = new FileStream(contentPath + "portfolios_cs.html", FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream vbStream     = new FileStream(contentPath + "portfolios_vb.html", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Portfolios.Run(imagesStream, pdfStream, csStream, vbStream);
                imagesStream.Close();
                pdfStream.Close();
                csStream.Close();
                vbStream.Close();
                break;

            case "redaction":
                FileStream redactionStream = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Redaction.Run(redactionStream);
                redactionStream.Close();
                break;

            case "removereplaceimages":
                FileStream removeReplaceImagesInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.RemoveReplaceImages.Run(removeReplaceImagesInput);
                removeReplaceImagesInput.Close();
                break;

            case "searchtext":
                FileStream searchTextInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.SearchText.Run(searchTextInput);
                searchTextInput.Close();
                break;

            case "svgtopdf":
                FileStream svgInput = new FileStream(contentPath + "tiger.svg", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.SvgToPdf.Run(svgInput);
                svgInput.Close();
                break;

            case "text":
                output = Xfinium.Pdf.Samples.Text.Run();
                break;

            case "tifftopdf":
                FileStream tiffStream = new FileStream(contentPath + "sample.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.TiffToPdf.Run(tiffStream);
                tiffStream.Close();
                break;

            case "type3fonts":
                output = Xfinium.Pdf.Samples.Type3Fonts.Run();
                break;

            case "vectorgraphics":
                FileStream iccStream = new FileStream(contentPath + "rgb.icc", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.VectorGraphics.Run(iccStream);
                iccStream.Close();
                break;

            case "watermarks":
                FileStream watermarksInput = new FileStream(contentPath + "content.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);
                output = Xfinium.Pdf.Samples.Watermarks.Run(watermarksInput);
                watermarksInput.Close();
                break;
            }

            if (output != null)
            {
                if (currentSample.ID == "pdfa")
                {
                    PdfAFormatter.Save(output[0].Document as PdfFixedDocument, outputPath + "/" + output[0].FileName, PdfAFormat.PdfA1b);
                }
                else
                {
                    for (int i = 0; i < output.Length; i++)
                    {
                        output[i].Document.Save(outputPath + "/" + output[i].FileName);
                    }
                }

                pdfFileName = output[0].FileName;

                UIAlertView messageBox = new UIAlertView("XFINIUM.PDF", "Sample completed with success", null, "Close", "View PDF");
                messageBox.Clicked += HandleClicked;
                messageBox.Show();
            }
        }