Open action
setopenzoom
JAVA
JAVA
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
/**
* Formerly OpenAt100pct sample in iText 5
*/
package com.itextpdf.samples.sandbox.annotations;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.navigation.PdfExplicitDestination;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import java.io.File;
public class SetOpenZoom {
public static final String DEST = "./target/sandbox/annotations/open_at_100pct.pdf";
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new SetOpenZoom().manipulatePdf(DEST);
}
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc, new PageSize(612, 792));
doc.add(new Paragraph("Hello World"));
// Set the height of a page to 842 points and zoom value to 1 (which means 100% zoom)
PdfExplicitDestination zoomPage = PdfExplicitDestination.createXYZ(pdfDoc.getPage(1),
0, 842, 1);
pdfDoc.getCatalog().setOpenAction(zoomPage);
doc.close();
}
}
C#
C#
using System;
using System.IO;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Navigation;
using iText.Layout;
using iText.Layout.Element;
namespace iText.Samples.Sandbox.Annotations
{
public class SetOpenZoom
{
public static readonly String DEST = "results/sandbox/annotations/open_at_100pct.pdf";
public static void Main(String[] args)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new SetOpenZoom().ManipulatePdf(DEST);
}
protected void ManipulatePdf(String dest)
{
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc, new PageSize(612, 792));
doc.Add(new Paragraph("Hello World"));
// Set the height of a page to 842 points and zoom value to 1 (which means 100% zoom)
PdfExplicitDestination zoomPage = PdfExplicitDestination.CreateXYZ(pdfDoc.GetPage(1),
0, 842, 1);
pdfDoc.GetCatalog().SetOpenAction(zoomPage);
doc.Close();
}
}
}