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

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

This article demonstrates how to split a worksheet into several Excel documents by using Spire.XLS for Java.

import com.spire.xls.CellRange;
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class SplitWorksheet {

    public static void main(String[] args) {

        //Create a Workbook object to load the original Excel document
        Workbook bookOriginal = new Workbook();
        bookOriginal.loadFromFile("C:\\Users\\Administrator\\Desktop\\Emplyees.xlsx");

        //Get the first worksheet
        Worksheet sheet = bookOriginal.getWorksheets().get(0);

        //Get the header row
        CellRange headerRow = sheet.getCellRange(1, 1, 1, 5);

        //Get two cell ranges
        CellRange range1 = sheet.getCellRange(2, 1, 6, 5);
        CellRange range2 = sheet.getCellRange(7, 1, 11, 5);

        //Create a new workbook
        Workbook newBook1 = new Workbook();

        //Copy the header row and range 1 to the new workbook
        sheet.copy(headerRow, newBook1.getWorksheets().get(0), 1, 1, true, false);
        sheet.copy(range1, newBook1.getWorksheets().get(0), 2, 1, true, false);

        //Copy the column width from the original workbook to the new workbook
        for (int i = 0; i < sheet.getLastColumn(); i++) {

            newBook1.getWorksheets().get(0).setColumnWidth(i + 1, sheet.getColumnWidth(i + 1));
        }

        //Save the new workbook to an Excel file
        newBook1.saveToFile("Sales.xlsx", ExcelVersion.Version2016);

        //Copy the header row and range 2 to another workbook, and save it to another Excel file
        Workbook newBook2 = new Workbook();
        sheet.copy(headerRow, newBook2.getWorksheets().get(0), 1, 1, true, false);
        sheet.copy(range2, newBook2.getWorksheets().get(0), 2, 1, true, false);
        for (int i = 0; i < sheet.getLastColumn(); i++) {

            newBook2.getWorksheets().get(0).setColumnWidth(i + 1, sheet.getColumnWidth(i + 1));
        }
        newBook2.saveToFile("Technicians.xlsx", ExcelVersion.Version2016);
    }
}

Split a Worksheet into Several Excel Files in Java

page 35