-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[suggested sample code] PyMuPDF online web console #3984
Labels
Comments
here is a more complete/polished example: <h2>Scrub a document and add a button to save the result</h2>
<div id="pythonScript" class="e">
<pre>
<code>import pyodide.http</code>
<code>r = await pyodide.http.pyfetch('https://raw.githubusercontent.com/bpampuch/pdfmake/0.2.14/examples/pdfs/links.pdf')</code>
<code>data = await r.bytes()</code>
<code>doc = pymupdf.Document(stream=data)</code>
<code>doc.scrub(reset_responses=False)</code>
<code></code>
<code>import base64</code>
<code>bytes = doc.tobytes(garbage=3, deflate=True)</code>
<code>data_uri = 'data:application/octet-stream;base64,' + base64.b64encode(bytes).decode('ascii')</code>
<code></code>
<code>import js</code>
<code>save_button = js.document.getElementById('fileSaveButton')</code>
<code></code>
<code>if not save_button:</code>
<code> open_button = js.document.getElementById('fileOpenButton')</code>
<code> if open_button:</code>
<code> save_button = js.document.createElement('button')</code>
<code> save_button.setAttribute('id', 'fileSaveButton')</code>
<code> save_button.style.display = 'inline-block'</code>
<code> save_button.style.marginLeft = '1em'</code>
<code> open_button.style.display = 'inline-block'</code>
<code> open_button.parentNode.appendChild(save_button)</code>
<code></code>
<code>if save_button:</code>
<code> save_button.innerHTML = '<a href="' + data_uri + '" download="result.pdf">Save</a>'</code>
<code> save_anchor = save_button.childNodes[0]</code>
<code> save_anchor.style.color = 'inherit'</code>
<code> save_anchor.style.textDecoration = 'none'</code>
</pre>
<button onClick="parseScript('e')">RUN ></button>
</div> notes:
|
Thanks for the suggestion, unfortunately the codebase on pymupdf.io is closed source so we are unable to accept code suggestions or 3rd party contributions at this time. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discover the PyMuPDF online web console includes several blocks of sample code..
to illustrate cool things that can be done from within the console.
The console provides a File Loader button to input a PDF file.
However, the page doesn't show any way to output the PDF file after it has been modified by PyMuPDF.
May I suggest a new sample that shows how to do so?
I'm thinking something along the lines of:
The text was updated successfully, but these errors were encountered: