Rect

Sample Java code for using Apryse SDK to change a page's MediaBox using Rect class. Learn more about our Android SDK and PDF Editing & Manipulation Library.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6package com.pdftron.android.pdfnetsdksamples.samples;
7
8import com.pdftron.android.pdfnetsdksamples.OutputListener;
9import com.pdftron.android.pdfnetsdksamples.PDFNetSample;
10import com.pdftron.android.pdfnetsdksamples.R;
11import com.pdftron.android.pdfnetsdksamples.util.Utils;
12import com.pdftron.pdf.PDFDoc;
13import com.pdftron.pdf.PageIterator;
14import com.pdftron.pdf.Rect;
15import com.pdftron.sdf.SDFDoc;
16
17import java.util.ArrayList;
18
19public class RectTest extends PDFNetSample {
20
21 private static OutputListener mOutputListener;
22
23 private static ArrayList<String> mFileList = new ArrayList<>();
24
25 public RectTest() {
26 setTitle(R.string.sample_rect_title);
27 setDescription(R.string.sample_rect_description);
28 }
29
30 @Override
31 public void run(OutputListener outputListener) {
32 super.run(outputListener);
33 mOutputListener = outputListener;
34 mFileList.clear();
35 printHeader(outputListener);
36
37 try (PDFDoc input_doc = new PDFDoc((Utils.getAssetTempFile(INPUT_PATH + "tiger.pdf").getAbsolutePath()))) // Test - Adjust the position of content within the page.
38 {
39 mOutputListener.println("_______________________________________________");
40 mOutputListener.println("Opening the input pdf...");
41
42 input_doc.initSecurityHandler();
43
44 PageIterator pg_itr1 = input_doc.getPageIterator();
45
46 Rect media_box = pg_itr1.next().getMediaBox();
47
48 media_box.setX1(media_box.getX1() - 200); // translate the page 200 units (1 uint = 1/72 inch)
49 media_box.setX2(media_box.getX2() - 200);
50
51 media_box.update();
52
53 input_doc.save(Utils.createExternalFile("tiger_shift.pdf", mFileList).getAbsolutePath(), SDFDoc.SaveMode.NO_FLAGS, null);
54 mOutputListener.println("Done. Result saved in tiger_shift...");
55 } catch (Exception e) {
56 mOutputListener.printError(e.getStackTrace());
57 }
58
59 for (String file : mFileList) {
60 addToFileList(file);
61 }
62 printFooter(outputListener);
63 }
64
65}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales