page 118

This article will demonstrate how to set the zoom factor/percentage (such as default, 100 percent or any other zoom factors as required) and the viewer preference by using Spire.PDF for Java in Java applications.

Set the zoom factor

import com.spire.pdf.*;
import com.spire.pdf.actions.*;
import com.spire.pdf.general.*;

import java.awt.geom.*;

public class setZoomFactor {
    public static void main(String[] args) {

        //Load the sample document
        PdfDocument doc = new PdfDocument();
        doc.loadFromFile("Sample.pdf");

        //Get the first page of PDF
        PdfPageBase page = doc.getPages().get(0);

        //Set pdf destination
        PdfDestination dest = new PdfDestination(page);
        dest.setMode(PdfDestinationMode.Location);
        dest.setLocation(new Point2D.Float(-40f, -40f));

        //Set zoom factor
        dest.setZoom(0.8f);

        //Set action
        PdfGoToAction gotoAction = new PdfGoToAction(dest);
        doc.setAfterOpenAction(gotoAction);

        //Save pdf document
        String output = "output/setZoomFactor.pdf";
        doc.saveToFile(output);
    }
}

Output:

Java set the viewer preference and zoom factor for PDF

Set the viewer preference

import com.spire.pdf.*;

public class viewerPreference {
    public static void main(String[] args) {

        //Load the sample document
        PdfDocument doc = new PdfDocument();
        doc.loadFromFile("Sample.pdf");

        //Set viewer reference
        doc.getViewerPreferences().setCenterWindow(true);
        doc.getViewerPreferences().setDisplayTitle(false);
        doc.getViewerPreferences().setFitWindow(false);
        doc.getViewerPreferences().setHideMenubar(true);
        doc.getViewerPreferences().setHideToolbar(true);
        doc.getViewerPreferences().setPageLayout(PdfPageLayout.Two_Column_Left);

        //Save pdf document
        String output = "output/viewerPreference.pdf";
        doc.saveToFile(output);
    }
}

Output:

Java set the viewer preference and zoom factor for PDF

A workbook containing multiple worksheets helps to centrally manage relevant information, but sometimes we have to split the worksheets into separate Excel files so that individual worksheets can be distributed without disclosing other information. In this article, you will learn how to split Excel worksheets into separate workbooks in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

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

PM> Install-Package Spire.XLS

Split Excel Sheets into Separate Files

The following are the main steps to split Excel sheets into separate workbooks using Spire.XLS for .NET.

  • Create a Workbook object
  • Load a sample Excel file using Workbook.LoadFromFile() method.
  • Declare a new Workbook variable, which is used to create new Excel workbooks.
  • Loop through the worksheets in the source document.
  • Initialize the Workbook object, and add the copy of a specific worksheet of source document into it.
  • Save the workbook to an Excel file using Workbook.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Xls;
using System;

namespace SplitWorksheets
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook object
            Workbook wb = new Workbook();

            //Load an Excel document
            wb.LoadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

            //Declare a new Workbook variable
            Workbook newWb;

            //Declare a String variable
            String sheetName;

            //Specify the folder path which is used to store the generated Excel files
            String folderPath = "C:\\Users\\Administrator\\Desktop\\Output\\";

            //Loop through the worksheets in the source file
            for (int i = 0; i < wb.Worksheets.Count; i++)
            {

                //Initialize the Workbook object
                newWb = new Workbook();

                //Remove the default sheets
                newWb.Worksheets.Clear();

                //Add the specific worksheet of the source document to the new workbook
                newWb.Worksheets.AddCopy(wb.Worksheets[i]);

                //Get the worksheet name
                sheetName = wb.Worksheets[i].Name;

                //Save the new workbook to the specified folder
                newWb.SaveToFile(folderPath + sheetName + ".xlsx", ExcelVersion.Version2013);
            }
        }
    }
}

C#/VB.NET: Split Excel Sheets into Separate Files

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

This article will show you how to use Spire.PDF for Java to draw superscript and subscript text to PDF file in Java applications.

Draw Superscript Text

import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import java.awt.*;
import java.awt.geom.*;

public class PdfSuperscriptText {
    public static void main(String[] args) {

        //Create a new PdfDocument instance
        PdfDocument doc = new PdfDocument();
        //Add a page to pdf
        PdfPageBase page = doc.getPages().add();

        //Set the font
        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", Font.PLAIN,14),true);
        PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));

        //Set initial (x, y) coordinate
        float x = 120f;
        float y = 100f;

        //Draw text string
        String text = "Sample Text";
        page.getCanvas().drawString(text, font, brush, new Point2D.Float(x, y));

        //Measure the string
        Dimension2D size = font.measureString(text);
        x += size.getWidth();

        //Draw the text string and set the format as Superscript
        PdfStringFormat format = new PdfStringFormat();
        format.setSubSuperScript(PdfSubSuperScript.Super_Script);
        text = "Superscrip";
        page.getCanvas().drawString(text, font, brush, new Point2D.Float(x, y), format);

        //Save the document to file
        String result="output/superScript.pdf";
        doc.saveToFile(result);
    }
}

Effective screenshot:

Java draw Superscript and Subscript Text in PDF

Draw Subscript Text

import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import java.awt.*;
import java.awt.geom.*;

public class PdfSubscriptText {
    public static void main(String[] args) {

        //Create a new PdfDocument instance
        PdfDocument doc = new PdfDocument();
        //Add a page to pdf
        PdfPageBase page = doc.getPages().add();

        //Set the font
        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", Font.PLAIN,14),true);
        PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));

        //Set initial (x, y) coordinate
        float x = 120f;
        float y = 100f;

        //Draw text string
        String text = "Sample Text";
        page.getCanvas().drawString(text, font, brush, new Point2D.Float(x, y));

        //Measure the string
        Dimension2D size = font.measureString(text);
        x += size.getWidth();

        //Draw the text string and set the format as Subscript
        PdfStringFormat format = new PdfStringFormat();
        format.setSubSuperScript(PdfSubSuperScript.Sub_Script);
        text = "Subscrip";
        page.getCanvas().drawString(text, font, brush, new Point2D.Float(x, y), format);

        //Save the document to file
        String result="output/subScript.pdf";
        doc.saveToFile(result);
    }
}

Output:

Java draw Superscript and Subscript Text in PDF

page 118

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details