PDF layers allow users to selectively hide or show the content appearing on them in PDF documents. In this article, we will introduce how to add layers to a PDF document, draw content to the layers and delete a specific layer in Java using Free Spire.PDF for Java library.
Before getting started, please download Free Spire.PDF for Java package through this link, unzip the package and then import Spire.Pdf.jar from lib folder into our application.
Add layers to a PDF
在下面的示例中,我们将学习如何在PDF文档中添加两层,以及如何将PDF页面的内容和图像绘制到这些层。
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.graphics.*;
import com.spire.pdf.PdfPageSize;
import com.spire.pdf.graphics.layer.PdfLayer;
import java.awt.*;
import java.awt.geom.Point2D;
public class AddLayers