-
-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Form Flatten * Code review
- Loading branch information
Showing
14 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Assets } from '../index.ts'; | ||
|
||
// @deno-types="../dummy.d.ts" | ||
import { PDFDocument } from '../../../dist/pdf-lib.esm.js'; | ||
|
||
export default async (assets: Assets) => { | ||
const pdfDoc = await PDFDocument.load(assets.pdfs.form_to_flatten); | ||
|
||
const form = pdfDoc.getForm(); | ||
|
||
form.getTextField('Text1').setText('Some Text'); | ||
|
||
form.getRadioGroup('Group2').select('Choice1'); | ||
form.getRadioGroup('Group3').select('Choice3'); | ||
form.getRadioGroup('Group4').select('Choice1'); | ||
|
||
form.getCheckBox('Check Box3').check(); | ||
form.getCheckBox('Check Box4').uncheck(); | ||
|
||
form.getDropdown('Dropdown7').select('Infinity'); | ||
|
||
form.getOptionList('List Box6').select('Honda'); | ||
|
||
form.flatten(); | ||
|
||
const pdfBytes = await pdfDoc.save(); | ||
|
||
return pdfBytes; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Assets } from '..'; | ||
import { PDFDocument } from '../../..'; | ||
|
||
export default async (assets: Assets) => { | ||
const pdfDoc = await PDFDocument.load(assets.pdfs.form_to_flatten); | ||
|
||
const form = pdfDoc.getForm(); | ||
|
||
form.getTextField('Text1').setText('Some Text'); | ||
|
||
form.getRadioGroup('Group2').select('Choice1'); | ||
form.getRadioGroup('Group3').select('Choice3'); | ||
form.getRadioGroup('Group4').select('Choice1'); | ||
|
||
form.getCheckBox('Check Box3').check(); | ||
form.getCheckBox('Check Box4').uncheck(); | ||
|
||
form.getDropdown('Dropdown7').select('Infinity'); | ||
|
||
form.getOptionList('List Box6').select('Honda'); | ||
|
||
form.flatten(); | ||
|
||
const pdfBytes = await pdfDoc.save(); | ||
|
||
return pdfBytes; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { PDFDocument } from 'pdf-lib'; | ||
|
||
import { fetchAsset } from './assets'; | ||
|
||
export default async () => { | ||
const formToFlattenPdf = await fetchAsset('pdfs/form_to_flatten.pdf'); | ||
|
||
const pdfDoc = await PDFDocument.load(formToFlattenPdf); | ||
|
||
const form = pdfDoc.getForm(); | ||
|
||
form.getTextField('Text1').setText('Some Text'); | ||
|
||
form.getRadioGroup('Group2').select('Choice1'); | ||
form.getRadioGroup('Group3').select('Choice3'); | ||
form.getRadioGroup('Group4').select('Choice1'); | ||
|
||
form.getCheckBox('Check Box3').check(); | ||
form.getCheckBox('Check Box4').uncheck(); | ||
|
||
form.getDropdown('Dropdown7').select('Infinity'); | ||
|
||
form.getOptionList('List Box6').select('Honda'); | ||
|
||
form.flatten(); | ||
|
||
const base64Pdf = await pdfDoc.saveAsBase64({ dataUri: true }); | ||
|
||
return { base64Pdf }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta | ||
http-equiv="Content-Security-Policy" | ||
content=" | ||
default-src 'self' 'unsafe-inline' blob: resource:; | ||
object-src 'self' blob:; | ||
frame-src 'self' blob:; | ||
" | ||
/> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" type="text/css" href="/apps/web/index.css" /> | ||
<title>Test 18</title> | ||
<script type="text/javascript" src="/dist/pdf-lib.js"></script> | ||
<script type="text/javascript" src="/apps/web/utils.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div id="button-container"> | ||
<button onclick="window.location.href = '/apps/web/test17.html'"> | ||
Prev | ||
</button> | ||
<button onclick="test()">Run Test</button> | ||
<button disabled onclick="window.location.href = '/apps/web/test19.html'"> | ||
Next | ||
</button> | ||
</div> | ||
<div id="animation-target"></div> | ||
<iframe id="iframe"></iframe> | ||
</body> | ||
|
||
<script type="text/javascript"> | ||
startFpsTracker('animation-target'); | ||
|
||
const fetchBinaryAsset = (asset) => | ||
fetch(`/assets/${asset}`).then((res) => res.arrayBuffer()); | ||
|
||
const renderInIframe = (pdfBytes) => { | ||
const blob = new Blob([pdfBytes], { type: 'application/pdf' }); | ||
const blobUrl = URL.createObjectURL(blob); | ||
document.getElementById('iframe').src = blobUrl; | ||
}; | ||
|
||
async function test() { | ||
const { PDFDocument } = PDFLib; | ||
|
||
const formToFlattenPdf = await fetchBinaryAsset( | ||
'pdfs/form_to_flatten.pdf', | ||
); | ||
|
||
const pdfDoc = await PDFDocument.load(formToFlattenPdf); | ||
|
||
const form = pdfDoc.getForm(); | ||
|
||
form.getTextField('Text1').setText('Some Text'); | ||
|
||
form.getRadioGroup('Group2').select('Choice1'); | ||
form.getRadioGroup('Group3').select('Choice3'); | ||
form.getRadioGroup('Group4').select('Choice1'); | ||
|
||
form.getCheckBox('Check Box3').check(); | ||
form.getCheckBox('Check Box4').uncheck(); | ||
|
||
form.getDropdown('Dropdown7').select('Infinity'); | ||
|
||
form.getOptionList('List Box6').select('Honda'); | ||
|
||
form.flatten(); | ||
|
||
const pdfBytes = await pdfDoc.save(); | ||
|
||
renderInIframe(pdfBytes); | ||
} | ||
</script> | ||
</html> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.