Knowledgebase (2345)
Children categories
How to Mannually Add Spire.Doc as Dependency in a .NET Core Application
2019-10-16 02:56:57 Written by KoohjiStep 1: Download the latest version of Spire.Doc Pack from the link below, unzip it, and you'll get the DLL files for .NET Core in the “netcoreapp2.0” folder. If you already have this folder in your disk, go straight to step two.

Step 2: Create a .Net Core application in your Visual Studio.

Step 3: Add all DLL files under the "netcoreapp2.0" folder as dependencies in your project.
Right-click "Dependencies" – select "Add Reference" – click "Browse" – selcet all DLLs under "netcoreapp2.0" folder – click "Add".

Step 4: Install the other three packages in your project via the NuGet Package Manager. They are System.Drawing.Common, System.Text.Encoding.CodePages and System.Security.Cryptography.Xml.
Right-click "Dependencies" – select "Manage NuGet Packages" – click "Browse" –type the package name – select the package from the search results – click "Install".

Step 5: Now that you've added all the dependences successfully, you can start to code. The following code snippet gives you an exmaple of how to create a simple Word document using Spire.Doc.
using Spire.Doc;
using Spire.Doc.Documents;
namespace SpireDocNetCore
{
class Program
{
static void Main(string[] args)
{
//Create a document object
Document doc = new Document();
//Add a section
Section section = doc.AddSection();
//Add a paragrah
Paragraph paragraph = section.AddParagraph();
//Append text to the paragraph
paragraph.AppendText("This article shows you how to mannually add Spire.Doc as dependency in a .NET Core application.");
//Save to file
doc.SaveToFile("Output.docx", FileFormat.Docx2013);
}
}
}
Getting the PDF page size, orientation and rotation angle are tasks that are often required when working with PDF documents. These parameters are important to ensure that the printout meets expectations and that the document content is displayed correctly on different devices. In this article, you will learn how to get the page size, orientation and rotation angle of PDFs in Java using Spire.PDF for Java.
- Get PDF Page Size in Java
- Detect PDF Page Orientation in Java
- Detect PDF Page Rotation Angle in Java
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>12.6.4</version>
</dependency>
</dependencies>
Get PDF Page Size in Java
Spire.PDF for Java offers the PdfPageBase.getSize().getWidth() and PdfPageBase.getSize().getHeight() methods to get the width and height of a PDF page in points. If you want to convert the default unit of measure to other units, you can use the PdfUnitConvertor class. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Get a specified page using PdfDocument.getPages().get() method.
- Get the width and height of the PDF page using PdfPageBase.getSize().getWidth() and PdfPageBase.getSize().getHeight() methods.
- Create a PdfUnitConvertor instance, and then convert the size units from points to other units of measure using PdfUnitConvertor.convertUnits() method.
- Add the page size information to a StringBuilder instance, and then save the result to a TXT file.
- Java
import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import java.io.*;
public class GetPDFPageSize {
public static void main(String[] args) throws IOException {
//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a PDF file from disk
pdf.loadFromFile("SamplePDF.pdf");
//Get the first page
PdfPageBase page = pdf.getPages().get(0);
//Get the width and height of the page in "point"
double pointWidth = page.getSize().getWidth();
double pointHeight = page.getSize().getHeight();
//Create PdfUnitConvertor to convert the unit
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
//Convert size units from points to pixels
float pixelWidth = unitCvtr.convertUnits((float) pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
float pixelHeight = unitCvtr.convertUnits((float) pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Pixel);
//Convert size units from points to inches
float inchWidth = unitCvtr.convertUnits((float) pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Inch);
float inchHeight = unitCvtr.convertUnits((float) pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Inch);
//Convert size units from points to centimeters
float centimeterWidth = unitCvtr.convertUnits((float) pointWidth, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);
float centimeterHeight = unitCvtr.convertUnits((float) pointHeight, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);
//Create StringBuilder to save
StringBuilder content = new StringBuilder();
//Add the page size information to the StringBuilder instance
content.append("The page size of the file in points is (width: " + pointWidth + "pt, height: " + pointHeight + "pt)." + "\r\n");
content.append("The page size of the file in pixels is (width: " + pixelWidth + "pixel, height: " + pixelHeight + "pixel)." + "\r\n");
content.append("The page size of the file in inches is (width: " + inchWidth + "inch, height: " + inchHeight + "inch)." + "\r\n");
content.append("The page size of the file in centimeters is (width: " + centimeterWidth + "cm, height: " + centimeterHeight + "cm)." + "\r\n");
//Write information to a txt file
FileWriter writer = new FileWriter("GetPageSize.txt");
writer.write(content.toString());
writer.flush();
writer.close();
pdf.close();
pdf.dispose();
}
}

Detect PDF Page Orientation in Java
To detect the orientation of a PDF page, you can compare the width and height of the page. If the page width is greater than the height, then the page orientation is landscape, otherwise it is portrait. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Get a specified page using PdfDocument.getPages().get() method.
- Get the width and height of the PDF page using PdfPageBase.getSize().getWidth() and PdfPageBase.getSize().getHeight() methods.
- Compare the values of page width and height to detect the page orientation.
- Print out the result.
- Java
import com.spire.pdf.*;
import java.io.*;
public class GetPDFPageOrientation {
public static void main(String[] args) throws IOException {
//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a PDF file from disk
pdf.loadFromFile("SamplePDF.pdf");
//Get the first page
PdfPageBase page = pdf.getPages().get(0);
//Get the width and height of the page
double width = page.getSize().getWidth();
double height = page.getSize().getHeight();
//Compare the value of page width and height
if (width> height){
System.out.println("The page orientation is Landscape");
}
else{
System.out.println("The page orientation is Portrait");
}
}
}

Detect PDF Page Rotation Angle in Java
The rotation angle of a PDF page can be obtained through the PdfPageBase.getRotation() method. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Get a specified page using PdfDocument.getPages().get() method.
- Get the rotation angle of the page using PdfPageBase.getRotation() method, and then convert it to text string.
- Create a PdfUnitConvertor instance, and then convert the size units from points to other units of measure using PdfUnitConvertor.convertUnits() method.
- Print out the result.
- Java
import com.spire.pdf.*;
import java.io.*;
public class GetPDFPageOrientation {
public static void main(String[] args) throws IOException {
//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a PDF file from disk
pdf.loadFromFile("Sample.pdf");
//Get the first page
PdfPageBase page = pdf.getPages().get(0);
//Get the rotation angle of the current page
PdfPageRotateAngle rotationAngle = page.getRotation();
String rotation = rotationAngle.toString();
//Print out the page rotation angle information
System.out.println("The rotation angle of the current page is: " + rotation);
}
}

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 demonstrates how to automatically shrink text to fit a shape or how to automatically resize a shape to fit text by using Spire.Presentation for Java.
import com.spire.presentation.*;
import java.awt.geom.Rectangle2D;
public class AutoFitTextOrShape {
public static void main(String[] args) throws Exception {
//create Presentation instance
Presentation presentation = new Presentation();
//get the first slide
ISlide slide = presentation.getSlides().get(0);
//add a shape to slide
IAutoShape textShape1 = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(50,50,200,80));
//add text to shape
textShape1.getTextFrame().setText("Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape.");
//set the auto-fit type to normal, which means the text automatically shrinks to fit the shape when text overflows the shape
textShape1.getTextFrame().setAutofitType(TextAutofitType.NORMAL);
//add another shape to slide
IAutoShape textShape2 = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(350, 50, 200, 80));
textShape2.getTextFrame().setText("Resize shape to fit text.");
//set the auto-fit type to shape, which means the shape size automatically decreases or increases to fit text
textShape2.getTextFrame().setAutofitType(TextAutofitType.SHAPE);
//save to file
presentation.saveToFile("output/AutoFit.pptx", FileFormat.PPTX_2013);
}
}
