page 118

This article demonstrates how to apply a shadow effect to the text in a PowerPoint slide using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.OuterShadowEffect;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class SetShadowEffect {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Get the first slide
        ISlide slide = presentation.getSlides().get(0);

        //Add a rectangle to slide
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(50,80,500,100));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getLine().setFillType(FillFormatType.NONE);

        //Set text of the shape
        shape.appendTextFrame("Text shading on slide");

        //Set font style
        shape.getTextFrame().getTextRange().setFontHeight(38f);
        shape.getTextFrame().getTextRange().setLatinFont(new TextFont("Arial Black"));
        shape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        shape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Create a OuterShadowEffect object
        OuterShadowEffect outerShadow= new OuterShadowEffect();

        //Set the shadow effect
        outerShadow.setBlurRadius(0);
        outerShadow.setDirection(50);
        outerShadow.setDistance(10);
        outerShadow.getColorFormat().setColor(Color.orange);

        //Apply shadow effect to text
        shape.getTextFrame().getTextRange().getEffectDag().setOuterShadowEffect(outerShadow);

        //Save to file
        presentation.saveToFile("output/AddShadow.pptx", FileFormat.PPTX_2013);
    }
}

Apply a Shadow Effect to Text in PowerPoint in Java

This article will demonstrate how to use Spire.XLS for Java to remove the formulas but keep the values on the Excel worksheet.

Firstly, view the original Excel:

Java remove the formulas but keep the values on Excel worksheet

import com.spire.xls.*;

public class Test {
    public static void main(String[] args) throws Exception {

        String inputFile = "Sample.xlsx";
        String outputFile="output/removeFormulasButKeepValues_result.xlsx";

        //Create a workbook.
        Workbook workbook = new Workbook();
        //Load the file from disk.
        workbook.loadFromFile(inputFile);
        //Loop through worksheets.
        for (Worksheet sheet : (Iterable) workbook.getWorksheets())
        {
            //Loop through cells.
            for (CellRange cell : (Iterable) sheet.getRange())
            {
                //If the cell contains formula, get the formula value, clear cell content, and then fill the formula value into the cell.
                if (cell.hasFormula())
                {
                    Object value = cell.getFormulaValue();
                    cell.clear(ExcelClearOptions.ClearContent);
                    cell.setValue(value.toString());
                }
            }
        }
        //Save to file
        workbook.saveToFile(outputFile, ExcelVersion.Version2013);
    }
}

Output:

Java remove the formulas but keep the values on Excel worksheet

Password protection is a widely used security feature in PDFs to restrict access and prevent unauthorized modifications. Before working with a PDF, it is essential to determine whether it is password-protected. If protection is enabled, verifying the correct password allows you to unlock the document, ensuring smooth access for viewing, editing, or extracting its contents.

In this article, we will guide you through the process of checking whether a PDF is password-protected and how to verify the correct password using C# and the Spire.PDF for .NET library.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Check Whether a PDF is Password Protected in C#

Spire.PDF for .NET provides the PdfDocument.IsPasswordProtected(string fileName) method to determine whether a PDF file is password-protected. The detailed steps are as follows.

  • Specify the input and output file paths.
  • Use the PdfDocument.IsPasswordProtected(string fileName) method to check whether the PDF is password protected.
  • Save the verification result to a text file.
  • C#
using Spire.Pdf;
using System.IO;

namespace CheckIfPdfIsProtected
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Specify the input and output file paths
            string pdfPath = "sample.pdf";
            string resultFilePath = "verification_results.txt";

            // Check whether the PDF file is password-protected
            bool isProtected = PdfDocument.IsPasswordProtected(pdfPath);

            // Create a StreamWriter to write the result to a text file
            using (StreamWriter writer = new StreamWriter(resultFilePath))
            {
                // Write the verification result to the text file
                string resultMessage = isProtected ? "The PDF is password-protected." : "The PDF is not password-protected.";
                writer.WriteLine(resultMessage);
            }
        }
    }
}

Check Whether a PDF is Password Protected in C#

Determine the Correct Password of a PDF in C#

Spire.PDF for .NET does not have a direct method to verify if a password is correct, but this can be done by attempting to open the file with the given password. If the password is incorrect, an exception will be thrown. The detailed steps are as follows.

  • Specify the input and output file paths.
  • Check whether the PDF file is password-protected using the PdfDocument.IsPasswordProtected(string fileName) method.
  • Create an array of potential passwords to test.
  • Iterate through the array, and load the PDF with each password using the PdfDocument.LoadFromFile(string filename, string password) method.
  • If no exception is thrown, the password is correct. Otherwise, the password is incorrect.
  • Save the verification result to a text file.
  • C#
using Spire.Pdf;
using System;
using System.IO;

namespace DetermineTheCorrectPasswordOfPdf
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Specify the input and output file paths
            string pdfPath = "sample.pdf";
            string resultFilePath = "verification_results.txt";

            // Check whether the PDF file is password-protected
            bool isProtected = PdfDocument.IsPasswordProtected(pdfPath);

            // Create an array of potential passwords to test
            string[] passwords = new string[5] { "password1", "password2", "password3", "admin123", "test" };

            // Create a StreamWriter to write results to a text file
            using (StreamWriter writer = new StreamWriter(resultFilePath))
            {
                // If the PDF is protected, start testing passwords
                if (isProtected)
                {
                    // Iterate through each password in the array
                    for (int passwordcount = 0; passwordcount < passwords.Length; passwordcount++)
                    {
                        try
                        {
                            // Create a new PdfDocument object and try loading the document with the current password
                            PdfDocument doc = new PdfDocument();
                            doc.LoadFromFile(pdfPath, passwords[passwordcount]);

                            // If successful, write that the password is correct to the text file
                            writer.WriteLine("Password " + passwords[passwordcount] + " is correct");
                        }
                        catch
                        {
                            // If an exception occurs, write that the password is not correct to the text file
                            writer.WriteLine("Password " + passwords[passwordcount] + " is not correct");
                        }
                    }
                }
                else
                {
                    // If the PDF is not password protected, note this in the text file
                    writer.WriteLine("The PDF is not password protected.");
                }
            }

            Console.WriteLine("Verification results have been saved to: " + resultFilePath);
            Console.ReadKey();
        }
    }
}

Determine the Correct Password of a PDF in C#

Get a Free License

To fully experience the capabilities of Spire.PDF for .NET without any evaluation limitations, you can request a free 30-day trial license.

page 118