Java를 사용하여 PDF 레이어 작업
Contents
[
Hide
]
Aspose.PDF for Java는 각 페이지의 Layer API를 통해 PDF 레이어를 노출합니다. 선택적 콘텐츠 그룹을 생성하고, 해당 동작을 수정하고, 필요할 때 해당 콘텐츠를 내보내거나 평면화할 수 있습니다.
PDF 페이지에 레이어 추가
public static void addLayers(Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
Layer layer = new Layer("oc1", "Red Line");
layer.getContents().add(new SetRGBColorStroke(1, 0, 0));
layer.getContents().add(new MoveTo(500, 700));
layer.getContents().add(new LineTo(400, 700));
layer.getContents().add(new Stroke());
page.getLayers().add(layer);
document.save(outputFile.toString());
}
}
전체 예제에서는 빨간색, 녹색, 파란색 선 콘텐츠가 포함된 세 개의 개별 레이어를 만듭니다.
레이어 잠그기
- 원본 PDF
Document를 여세요. - 대상
Page에 액세스하고 해당Layer컬렉션을 가져오세요. - 대상
Layer를 잠그세요. - 업데이트된 PDF
Document를 저장하세요.
public static void lockLayer(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
Page page = document.getPages().get_Item(1);
if (!page.getLayers().isEmpty()) {
Layer layer = page.getLayers().getFirst();
layer.lock();
document.save(outputFile.toString());
}
}
}