Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener('documentLoaded', async() => {
  2.     const docViewer = readerControl.docViewer;
  3.     const annotManager = docViewer.getAnnotationManager();
  4.     await PDFNet.initialize();
  5.     const doc = readerControl.docViewer.getDocument();
  6.     const pdfDoc = await doc.getPDFDoc();
  7.     await pdfDoc.requirePage(1);
  8.     await PDFNet.runWithCleanup(async () => {
  9.       const document = docViewer.getDocument();
  10.       const pdfDoc = await document.getPDFDoc();
  11.  
  12.       const empFirstName = await pdfDoc.fieldCreateFromStrings('test', PDFNet.Field.Type.e_text, 'John', 'fg');
  13.       const annot1 = await PDFNet.WidgetAnnot.create(pdfDoc, await PDFNet.Rect.init(50, 550, 350, 600), empFirstName);
  14.  
  15.       const rotation = docViewer.getCompleteRotation(1) * 90;
  16.       annot1.setRotation(rotation);
  17.  
  18.  
  19.  
  20.       // draw the annotation the viewer
  21.       const page = await pdfDoc.getPage(1);
  22.       await page.annotPushBack(annot1);
  23.       await pdfDoc.refreshFieldAppearances();
  24.  
  25.       // import newly created form fields
  26.       const fdfDoc = await pdfDoc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_both);
  27.       const xfdf = await fdfDoc.saveAsXFDFAsString();
  28.  
  29.       await annotManager.importAnnotations(xfdf);
  30.  
  31.       // refresh viewer
  32.       docViewer.refreshAll();
  33.       docViewer.updateView();
  34.       document.refreshTextData();
  35.     });
  36.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement