Media Box Manipulation - Sample code

Requirements

Sample JavaScript code for using Apryse SDK to change a page's MediaBox using Rect class. This sample works with Full-API for WebViewer.

Learn more about our Web SDK and PDF Editing & Manipulation Library.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6(exports => {
7 exports.runRectTest = () => {
8 const PDFNet = exports.Core.PDFNet;
9
10 const main = async () => {
11 let ret = 0;
12 try {
13 console.log('Beginning Rect Test. This test will take the rect box of an image and move/translate it');
14
15 const inputPath = '../TestFiles/';
16 const doc = await PDFNet.PDFDoc.createFromURL(inputPath + 'tiger.pdf');
17 doc.initSecurityHandler();
18 doc.lock();
19 console.log('PDF document initialized and locked');
20
21 const pgItr1 = await doc.getPageIterator();
22 const mediaBox = await (await pgItr1.current()).getMediaBox();
23 mediaBox.x1 -= 200; // translate page 200 units left(1 uint = 1/72 inch)
24 mediaBox.x2 -= 200;
25
26 await mediaBox.update();
27
28 const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_linearized);
29 saveBufferAsPDFDoc(docbuf, 'tiger_shift.pdf');
30 console.log('Done.');
31 } catch (err) {
32 console.log(err);
33 ret = 1;
34 }
35 return ret;
36 };
37 // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
38 PDFNet.runWithCleanup(main);
39 };
40})(window);
41// eslint-disable-next-line spaced-comment
42//# sourceURL=AnnotationTest.js

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales