Exemplo n.º 1
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        var sb = new StringBuilder();

        var slide = presentation.Slides[0];

        foreach (var shape in slide.Content.Drawings.OfType <Shape>())
        {
            sb.AppendFormat("Shape ShapeType={0}:", shape.ShapeType);
            sb.AppendLine();

            foreach (var paragraph in shape.Text.Paragraphs)
            {
                foreach (var run in paragraph.Elements.OfType <TextRun>())
                {
                    var isBold = run.Format.Bold;
                    var text   = run.Text;

                    sb.AppendFormat("{0}{1}{2}", isBold ? "<b>" : "", text, isBold ? "</b>" : "");
                }

                sb.AppendLine();
            }

            sb.AppendLine("----------");
        }

        Console.WriteLine(sb.ToString());
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Template.pptx");

        // Retrieve first slide.
        var slide = presentation.Slides[0];

        // Retrieve "Title" placeholder and set shape text.
        var shape = slide.Content.Drawings.OfType <Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.CenteredTitle).First();

        shape.Text.Paragraphs[0].AddRun("ACME Corp - 4th Quarter Financial Results");

        // Retrieve second slide.
        slide = presentation.Slides[1];

        // Retrieve "Title" placeholder and set shape text.
        shape = slide.Content.Drawings.OfType <Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title).First();
        shape.Text.Paragraphs[0].AddRun("4th Quarter Summary");

        // Retrieve "Content" placeholder.
        shape = slide.Content.Drawings.OfType <Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Content).First();

        // Set list text.
        shape.Text.Paragraphs[0].Elements.Clear();
        shape.Text.Paragraphs[0].AddRun("3 new products/services in Research and Development.");

        shape.Text.Paragraphs[1].Elements.Clear();
        shape.Text.Paragraphs[1].AddRun("Rollout planned for new division.");

        shape.Text.Paragraphs[2].Elements.Clear();
        shape.Text.Paragraphs[2].AddRun("Campaigns targeting new markets.");

        // Retrieve third slide.
        slide = presentation.Slides[2];

        // Retrieve "Title" placeholder and set shape text.
        shape = slide.Content.Drawings.OfType <Shape>().Where(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title).First();
        shape.Text.Paragraphs[0].AddRun("4th Quarter Financial Highlights");

        // Retrieve a table.
        var table = slide.Content.Drawings.OfType <GraphicFrame>().Where(item => item.Table != null).Select(item => item.Table).First();

        // Fill table data.
        table.Rows[1].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$14.2M";
        table.Rows[1].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "(0.5%)";

        table.Rows[2].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$1.6M";
        table.Rows[2].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "0.7%";

        table.Rows[3].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$12.5M";
        table.Rows[3].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "0.3%";

        table.Rows[4].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$2.3M";
        table.Rows[4].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "(0.2%)";

        presentation.Save("Template Use.pptx");
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("CloneDestination.pptx");

        var sourcePresentation = PresentationDocument.Load("CloneSource.pptx");

        // Use context so that references between
        // shapes and slides are maintained between all cloning operations.
        var context = CloneContext.Create(sourcePresentation, presentation);

        // Clone all drawings from the first slide of another presentation
        // into the first slide of the current presentation.
        foreach (var drawing in sourcePresentation.Slides[0].Content.Drawings)
        {
            presentation.Slides[0].Content.Drawings.AddClone(drawing, context);
        }

        // Establish explicit mapping between slides so that
        // hyperlink on the second slide is correctly cloned.
        context.Set(sourcePresentation.Slides[0], presentation.Slides[0]);

        // Clone the second slide from another presentation.
        presentation.Slides.AddClone(sourcePresentation.Slides[1], context);

        presentation.Save("Cloning.pptx");
    }
    static void PAdES_B_B()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        // Create visual representation of digital signature on the first slide.
        Picture signature = null;

        using (var stream = File.OpenRead("GemBoxSignature.png"))
            signature = presentation.Slides[0].Content.AddPicture(
                PictureContentType.Png, stream, 25, 15, 4, 1, LengthUnit.Centimeter);

        var options = new PdfSaveOptions()
        {
            DigitalSignature =
            {
                CertificatePath               = "GemBoxECDsa521.pfx",
                CertificatePassword           = "******",
                Signature                     = signature,
                IsAdvancedElectronicSignature = true
            }
        };

        presentation.Save("PDF Digital Signature.pdf", options);
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        var sb = new StringBuilder();

        sb.AppendLine("Slide size (width X height):");

        var width  = presentation.SlideSize.Width;
        var height = presentation.SlideSize.Height;

        foreach (LengthUnit unit in Enum.GetValues(typeof(LengthUnit)))
        {
            sb.AppendFormat(
                "{0} X {1} {2}",
                width.To(unit),
                height.To(unit),
                unit.ToString().ToLowerInvariant());

            sb.AppendLine();
        }

        Console.WriteLine(sb.ToString());
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        var slide = presentation.Slides[0];

        Picture signature = null;

        using (var stream = File.OpenRead("GemBoxSignature.png"))
            signature = slide.Content.AddPicture(
                PictureContentType.Png, stream, 25, 15, 4, 1, LengthUnit.Centimeter);

        var options = new PdfSaveOptions()
        {
            DigitalSignature =
            {
                CertificatePath     = "GemBoxExampleExplorer.pfx",
                CertificatePassword = "******",
                Signature           = signature
            }
        };

        presentation.Save("PDF Digital Signature.pdf", options);
    }
Exemplo n.º 7
0
        private void Button_Click4(object sender, RoutedEventArgs e) //.pptx
        {
            //Convert PowerPoint to PDF()
            //If using Professional version, put your serial key below.
            ComponentInfo.SetLicense("FREE-LIMITED-KEY"); // для використання  безкоштовної ліцензії
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.CheckFileExists = true;
            openFileDialog.Multiselect     = true;
            //openFileDialog.Filter = "Doc files (*.ppt)|*.ppt|All files (*.*)|*.*";
            openFileDialog.Filter           = "Doc files (*.pptx)|*.pptx|All files (*.*)|*.*";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
            Nullable <bool> result = openFileDialog.ShowDialog();

            if (result == true)
            {
                string inpFile      = openFileDialog.FileName; // Open document
                var    presentation = PresentationDocument.Load(inpFile);
                string outFile      = @"C:\Users\Mariia\Desktop\Convertor\PDFfromPPT.pdf";
                presentation.Save(outFile);
                //DocumentCore dc = DocumentCore.Load(inpFile);
                //dc.Save(outFile);
                //System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
            }
            // In order to achieve the conversion of a loaded PowerPoint file to PDF,
            // we just need to save a PresentationDocument object to desired
            // output file format.
        }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("EmbeddedObjects.pptx");

        presentation.Save("Embedded Objects.pptx");
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        // In order to achieve the conversion of a loaded PowerPoint file to PDF,
        // we just need to save a PresentationDocument object to desired
        // output file format.
        presentation.Save("Convert.pdf");
    }
Exemplo n.º 10
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        var slide = presentation.Slides[0];

        slide.Content.Drawings.Clear();

        // Create "Built-in document properties" text box.
        var textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 0.5, 0.5, 12, 10, LengthUnit.Centimeter);

        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkBlue));

        var paragraph = textBox.AddParagraph();

        paragraph.Format.Alignment = HorizontalAlignment.Left;

        var run = paragraph.AddRun("Built-in document properties:");

        run.Format.Bold = true;

        paragraph.AddLineBreak();

        foreach (var docProp in presentation.DocumentProperties.BuiltIn)
        {
            paragraph.AddRun(string.Format("{0}: {1}", docProp.Key, docProp.Value));
            paragraph.AddLineBreak();
        }

        // Create "Custom document properties" text box.
        textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 14, 0.5, 12, 10, LengthUnit.Centimeter);
        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkBlue));

        paragraph = textBox.AddParagraph();
        paragraph.Format.Alignment = HorizontalAlignment.Left;

        run             = paragraph.AddRun("Custom document properties:");
        run.Format.Bold = true;

        paragraph.AddLineBreak();

        foreach (var docProp in presentation.DocumentProperties.Custom)
        {
            paragraph.AddRun(string.Format("{0}: {1} (Type: {2})", docProp.Key, docProp.Value, docProp.Value.GetType()));
            paragraph.AddLineBreak();
        }

        presentation.Save("Document Properties.pptx");
    }
    private void LoadFileBtn_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog fileDialog = new OpenFileDialog();

        fileDialog.Filter = "PPTX files (*.pptx, *.pptm, *.potx, *.potm)|*.pptx;*.pptm;*.potx;*.potm";

        if (fileDialog.ShowDialog() == true)
        {
            this.presentation = PresentationDocument.Load(fileDialog.FileName);

            this.ShowPrintPreview();
            this.EnableControls();
        }
    }
Exemplo n.º 12
0
    protected void generateButton_Click(object sender, EventArgs e)
    {
        string path = Path.Combine(Request.PhysicalApplicationPath, "Template.pptx");

        // Load template presentation.
        var presentation = PresentationDocument.Load(path);

        // Populate the template presentation with data.
        UpdatePresentation(presentation, this.titleTextBox.Text, this.summaryHeadingTextBox.Text, this.summaryBulletsTextBox.Text, this.highlightsHeadingTextBox.Text, (DataTable)Session["highlightsDataTable"]);

        // Stream the presentation to the browser.
        string fileName = "Presentation." + this.outputFormatDropDownList.SelectedValue;

        presentation.Save(this.Response, fileName);
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // If example exceeds Free version limitations then continue as trial version:
        // https://www.gemboxsoftware.com/Presentation/help/html/Evaluation_and_Licensing.htm
        ComponentInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;

        Console.WriteLine("Performance example:");
        Console.WriteLine();

        var stopwatch = new Stopwatch();

        stopwatch.Start();

        var presentation = PresentationDocument.Load("Template.pptx", LoadOptions.Pptx);

        Console.WriteLine("Load file (seconds): " + stopwatch.Elapsed.TotalSeconds);

        stopwatch.Reset();
        stopwatch.Start();

        int numberOfShapes     = 0;
        int numberOfParagraphs = 0;

        foreach (var slide in presentation.Slides)
        {
            foreach (var shape in slide.Content.Drawings.OfType <Shape>())
            {
                foreach (var paragraph in shape.Text.Paragraphs)
                {
                    ++numberOfParagraphs;
                }

                ++numberOfShapes;
            }
        }

        Console.WriteLine("Iterate through " + numberOfShapes + " shapes and " + numberOfParagraphs + " paragraphs (seconds): " + stopwatch.Elapsed.TotalSeconds);

        stopwatch.Reset();
        stopwatch.Start();

        presentation.Save("Report.pptx");

        Console.WriteLine("Save file (seconds): " + stopwatch.Elapsed.TotalSeconds);
    }
Exemplo n.º 14
0
        private void LoadPresentation(string path)
        {
            if (File.Exists(path))
            {
                try
                {
                    this.presentation = PresentationDocument.Load(path);

                    this.UpdatePresentationViewer();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.ToString(), "Exception " + ex.GetType() + " occurred while opening a presentation!", MessageBoxButton.OK, MessageBoxImage.Error);
                    Process.Start("http://support.gemboxsoftware.com/new-ticket");
                }
            }
        }
Exemplo n.º 15
0
    static void Example2()
    {
        // Load input file and save it in selected output format
        var presentation = PresentationDocument.Load("Chart.pptx");

        // Get PowerPoint chart.
        var chart = ((GraphicFrame)presentation.Slides[0].Content.Drawings[0]).Chart;

        // Get underlying Excel chart and cast it as LineChart.
        var lineChart = (LineChart)chart.ExcelChart;

        // Add new line series which has doubled values from the first series.
        lineChart.Series.Add("Series 3", lineChart.Series.First()
                             .Values.Cast <double>().Select(val => val * 2));

        presentation.Save("Updated Chart.pptx");
    }
Exemplo n.º 16
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("FindAndReplace.pptx");

        var slide = presentation.Slides[0];

        slide.TextContent.Replace("companyName", "Acme Corporation");

        var items = new string[][]
        {
            new string[] { "January", "$14.2M", "$1.6M", "$12.5M", "$2.3M" },
            new string[] { "February", "$15.2M", "$0.6M", "$11.3M", "$4.3M" },
            new string[] { "March", "$17.2M", "$0M", "$12.1M", "$52.3M" },
            new string[] { "April", "$7.2M", "$1.6M", "$7.2M", "$0M" },
            new string[] { "May", "$3.2M", "$1.6M", "$0M", "$3.2M" }
        };

        var table = slide.Content.Drawings.OfType <GraphicFrame>().First().Table;

        // Clone the row with custom text tags (e.g. '@month', '@revenue', etc.).
        for (int i = 0; i < items.Length - 1; i++)
        {
            table.Rows.AddClone(table.Rows[1]);
        }

        // Replace custom text tags with data.
        for (int i = 0; i < items.Length; i++)
        {
            var row  = table.Rows[i + 1];
            var item = items[i];
            row.TextContent.Replace("@month", item[0]);
            row.TextContent.Replace("@revenue", item[1]);
            row.TextContent.Replace("@cashExpense", item[2]);
            row.TextContent.Replace("@operatingIncome", item[3]);
            row.TextContent.Replace("@operatingExpense", item[4]);
        }

        // Find all text content with "0M" value in the table.
        var zeroValueRanges = table.TextContent.Find("0M");

        presentation.Save("Find And Replace.pptx");
    }
Exemplo n.º 17
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        string inputPassword  = "******";
        string outputPassword = "******";

        var presentation = PresentationDocument.Load("PptxEncryption.pptx", new PptxLoadOptions()
        {
            Password = inputPassword
        });

        presentation.Save("PPTX Encryption.pptx", new PptxSaveOptions()
        {
            Password = outputPassword
        });
    }
Exemplo n.º 18
0
        public string ConvertPPTtoPDF(string FilePath)
        {
            //Converts the PPT To doc to get the computation

            string DefaultLoc = Properties.Settings.Default.FolderPath + "Convert.pdf";

            ComponentInfo.SetLicense("FREE-LIMITED-KEY");

            var presentation = PresentationDocument.Load(FilePath);

            // In order to achieve the conversion of a loaded PowerPoint file to PDF,
            // we just need to save a PresentationDocument object to desired
            // output file format. "C:\\Users\\MSI\\Documents\\Convert.pdf"
            presentation.Save(DefaultLoc);
            string loc = Properties.Settings.Default.FolderPath + "Convert.pdf"; // "C:\\Users\\MSI\\Documents\\Convert.pdf";

            FileInDocFormat = ConvertPDFtoWord(DefaultLoc);
            return(loc);
        }
Exemplo n.º 19
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        string password      = "******";
        string ownerPassword = "";

        var options = new PdfSaveOptions()
        {
            DocumentOpenPassword = password,
            PermissionsPassword  = ownerPassword,
            Permissions          = PdfPermissions.None
        };

        presentation.Save("PDF Encryption.pdf", options);
    }
Exemplo n.º 20
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("RightToLeft.pptx");

        var slide = presentation.Slides[0];

        var shape = slide.Content.AddShape(ShapeGeometryType.Rectangle, 2, 2, 8, 4, LengthUnit.Centimeter);

        // Create a new right-to-left paragraph.
        var paragraph = shape.Text.AddParagraph();

        paragraph.Format.RightToLeft = true;
        paragraph.Format.Alignment   = HorizontalAlignment.Right;
        var run = paragraph.AddRun("هذا ثمّة أمّا العالم، أم, السادس مواقعها");

        run.Format.Size = Length.From(28, LengthUnit.Point);

        presentation.Save("RightToLeft.pdf");
    }
    static void PAdES_B_LTA()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Reading.pptx");

        // Create visual representation of digital signature on the first slide.
        Picture signature = null;

        using (var stream = File.OpenRead("GemBoxSignature.png"))
            signature = presentation.Slides[0].Content.AddPicture(
                PictureContentType.Png, stream, 25, 15, 4, 1, LengthUnit.Centimeter);

        // If using Professional version, put your serial key below.
        GemBox.Pdf.ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Get a digital ID from PKCS#12/PFX file.
        var digitalId = new PdfDigitalId("GemBoxECDsa521.pfx", "GemBoxPassword");

        // Create a PDF signer that will create PAdES B-LTA level signature.
        var signer = new PdfSigner(digitalId);

        // PdfSigner should create CAdES-equivalent signature.
        signer.SignatureFormat = PdfSignatureFormat.CAdES;

        // PdfSigner will embed a timestamp created by freeTSA.org Time Stamp Authority in the signature.
        signer.Timestamper = new PdfTimestamper("https://freetsa.org/tsr");

        // Make sure that all properties specified on PdfSigner are according to PAdES B-LTA level.
        signer.SignatureLevel = PdfSignatureLevel.PAdES_B_LTA;

        // Inject PdfSigner from GemBox.Pdf into
        // PdfDigitalSignatureSaveOptions from GemBox.Presentation.
        var signatureOptions = PdfDigitalSignatureSaveOptions.FromSigner(
            () => signer.SignatureFormat.ToString(),
            () => signer.EstimatedSignatureContentsLength,
            signer.ComputeSignature);

        signatureOptions.Signature = signature;

        var options = new PdfSaveOptions()
        {
            DigitalSignature = signatureOptions
        };

        presentation.Save("PAdES B-LTA.pdf", options);

        using (var pdfDocument = GemBox.Pdf.PdfDocument.Load("PAdES B-LTA.pdf"))
        {
            var signatureField = (PdfSignatureField)pdfDocument.Form.Fields[0];

            // Download validation-related information for the signature and the signature's timestamp and embed it in the PDF file.
            // This will make the signature "LTV enabled".
            pdfDocument.SecurityStore.AddValidationInfo(signatureField.Value);

            // Add an invisible signature field to the PDF document that will hold the document timestamp.
            var timestampField = pdfDocument.Form.Fields.AddSignature();

            // Initiate timestamping of a PDF file with the specified timestamper.
            timestampField.Timestamp(signer.Timestamper);

            // Save any changes done to the PDF file that were done since the last time Save was called and
            // finish timestamping of a PDF file.
            pdfDocument.Save();
        }
    }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine("File path as(C:\\Users\\Desktop\\fileConverson\\<FileName>.<FileExtension>)");
            Console.WriteLine("Enter file path: ");
            string path    = Console.ReadLine();
            string strpath = System.IO.Path.GetExtension(path);


            //key for using GemBox
            GemBox.Document.ComponentInfo.SetLicense("FREE-LIMITED-KEY");
            GemBox.Pdf.ComponentInfo.SetLicense("FREE-LIMITED-KEY");
            GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            GemBox.Presentation.ComponentInfo.SetLicense("FREE-LIMITED-KEY");

            //Extracting data from .txt
            if (strpath == ".txt")
            {
                var data = System.IO.File.ReadAllText(@path);
                Console.WriteLine(data);
                Console.WriteLine("\n");
            }
            //Extracting data from .docx
            else if (strpath == ".docx" || strpath == "doc")
            {
                var    doc_Data = DocumentModel.Load(@path);
                string doc_text = doc_Data.Content.ToString();
                Console.WriteLine(doc_text);
            }
            //Extracting data from .pdf
            else if (strpath == ".pdf")
            {
                //using foreach to iterate through pages
                using (var document = PdfDocument.Load(@path))
                {
                    foreach (var page in document.Pages)
                    {
                        Console.WriteLine(page.Content.ToString());
                    }
                }
            }


            //Extracting data from excel
            else if (strpath == ".xlsx")
            {
                ExcelFile spreadsheet = ExcelFile.Load(@path);

                //Loop to move between multiple sheets
                foreach (ExcelWorksheet worksheet in spreadsheet.Worksheets)
                {
                    Console.WriteLine(worksheet.Name);

                    //Loop for rows
                    foreach (ExcelRow row in worksheet.Rows)
                    {
                        //Loop for cells in a row
                        foreach (ExcelCell cell in row.AllocatedCells)
                        {
                            //Reading data from cell
                            string value = cell.Value?.ToString() ?? "EMPTY";


                            Console.Write($"{value}".PadRight(20));
                        }
                        Console.WriteLine("\n");
                    }
                }
            }

            //Extracting data from ppt
            else if (strpath == ".pptx" || strpath == ".ppt")
            {
                var presentation = PresentationDocument.Load(@path);
                var sb           = new StringBuilder();
                var i            = 0;
                try
                {
                    while (presentation.Slides[i] != null)
                    {
                        var slide = presentation.Slides[i];
                        foreach (var shape in slide.Content.Drawings.OfType <Shape>())
                        {
                            sb.AppendLine();

                            foreach (var paragraph in shape.Text.Paragraphs)
                            {
                                foreach (var run in paragraph.Elements.OfType <TextRun>())
                                {
                                    var isBold = run.Format.Bold;
                                    var text   = run.Text;

                                    sb.AppendFormat("{0}{1}{2}", isBold ? "<b>" : "", text, isBold ? "</b>" : "");
                                }

                                sb.AppendLine();
                            }
                        }

                        sb.ToString();

                        if (sb == null)
                        {
                            i = -1;
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
                catch
                {
                    if (sb != null)
                    {
                        Console.WriteLine(sb);
                    }
                }
            }



            Console.ReadKey();
        }
Exemplo n.º 23
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = PresentationDocument.Load("Template.pptx");

        // Retrieve first slide.
        var slide = presentation.Slides[0];

        // Retrieve "Title" placeholder and set shape text.
        var shape = slide.Content.Drawings
                    .OfType <Shape>()
                    .First(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title);

        shape.Text.Paragraphs[0].AddRun("ACME Corp - 4th Quarter Financial Results");

        // Retrieve a picture and replace its image data.
        var picture = slide.Content.Drawings
                      .OfType <Picture>()
                      .First();

        using (var image = File.OpenRead("Acme.png"))
            picture.Fill.SetData(PictureContentType.Png, image);

        // Retrieve "Content" placeholder.
        shape = slide.Content.Drawings
                .OfType <Shape>()
                .First(item => item.Placeholder?.PlaceholderType == PlaceholderType.Content);

        // Set list text.
        shape.Text.Paragraphs[0].Elements.Clear();
        shape.Text.Paragraphs[0].AddRun("First item, new services.");

        shape.Text.Paragraphs[1].Elements.Clear();
        shape.Text.Paragraphs[1].AddRun("Second item, new division plan.");

        shape.Text.Paragraphs[2].Elements.Clear();
        shape.Text.Paragraphs[2].AddRun("Third item, new marketing campaign.");

        // Retrieve second slide.
        slide = presentation.Slides[1];

        // Retrieve "Title" placeholder and set shape text.
        shape = slide.Content.Drawings
                .OfType <Shape>()
                .First(item => item.Placeholder?.PlaceholderType == PlaceholderType.Title);
        shape.Text.Paragraphs[0].AddRun("4th Quarter Financial Highlights");

        // Retrieve a table.
        var table = slide.Content.Drawings
                    .OfType <GraphicFrame>()
                    .First(item => item.Table != null)
                    .Table;

        // Fill table data.
        table.Rows[1].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$14.2M";
        table.Rows[1].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "(0.5%)";

        table.Rows[2].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$1.6M";
        table.Rows[2].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "0.7%";

        table.Rows[3].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$12.5M";
        table.Rows[3].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "0.3%";

        table.Rows[4].Cells[1].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "$2.3M";
        table.Rows[4].Cells[2].Text.Paragraphs[0].Elements.OfType <TextRun>().First().Text = "(0.2%)";

        presentation.Save("Template Use.pptx");
    }