I need to create a PDF from HTML inside a react-js app.
Many packages I have found prompt a download button in the browser ( like jsPDF ), but I actually need the PDF as a binary string. I need this string to be send to a private API that stores this PDF ( binary string ) in S3 as a PDF file. This private API call already exists, and I can not change anything from this code.
I am struggeling to understand why this is so hard. How would you go about converting HTML to PDF binary string? Thanks for any suggestions, packages, ... It can be javscript, if I can implement it inside my reactJS app.
Bonus points if the solution can accept HTML tags, since the input is done inside an WYSIWYG editor.
This server side solution works with any HTML framework.
https://github.com/PDFTron/web-to-pdf
This is from the company I work for, but is AGPL-3.0 so you should be able to use no problem.
Related
I'm new to Excel Web Add-Ins and want to figure out if it's possible to make an add-in that can export a custom file.
I've looked around and all I find are Excel specific commands like Workbook.SaveAs() but I can't find anything on making custom export functions. I need to convert the file into XML but a specific XML setup and so, I could just work the data before I save it to XML. But again, can't find much of anything to suggest that this is supported.
How would I go about writing a file to disk from Excel that isn't just the Workbook?
There's no such API to support exporting custom file to disk. It seems we can have workaround to do this work, this workaround just works for excel online.
Please see this link:
How to create a file in memory for user to download, but not through server?
The closest thing there is for what you want to do is:
Office.context.document.getFileAsync(Office.FileType.Compressed, (result) => {
const file = result.value;
// do whatever ...
});
The file variable in this case contains the entire document in Office Open XML (OOXML) format as a byte array.
Problem
I would like to know is there any PHP/NodeJS API available to convert editable PDF to non-editable PDF online. We have a client application where we need a scenario where the user downloads the PDF should not able to modify it thought any software (eg. Foxit reader, Adobe)
Basically, we are using PDF-LIB right now and it seems there is no solution for the non-editable pdf API to set access privileges, I have search a lot but does not found any API for that, Am not using the pdf-flatten because we want everything selectable, Appreciate your help.
List of libraries tried and fail to achieve the results
bpampuch/pdfmake issue can't load an existing pdf
PDF-LIB issue can't support permissions
nrhirani/node-qpdf issue File restrictions not working properly
I think flattening the PDF might help you to make it un-editable in case your target is
Just the form fields then you might use this from the PDF-LIB github repo
The entire PDF then, see if pdf-flatten package helps for Node.js
After a lot of research work and tried multiple libraries in PHP/Node. I don't found any library that is mature enough to proceed with that, so I decided to make an API that will build in different technology C# and Java
Solution
we post the PDF URL through API, the API download that file, and apply for multiple permission according to the dataset.
Library
the library we choose is ASPOSE
// These can be true/false
config.IsPrint = true;
// Document is allowed to be changed.
config.IsModify = false;
// Annotation is allowed.
config.IsAnnot = true;
// Form filling is allowed.
config.IsFillForm = true;
// Content extraction is allowed.
config.IsExtract = true;
I have an HTML file with JavaScript that I am running without any Webserver/host so I am just opening the file in a browser local to my windows PC. In that HTML file I would like to be able to read a text file in the same folder as the html file. That file will contain data in rows and columns separated with tabs. i.e
1 a
2 b
3 c
I want to keep this as simple as possible so all I have to do is share the HTML and Text file to others so the can open it up local to their computer without any webserver/host and without having to also copy of external libraries like node.js or jquery.
I have searched and tested everything I can find but either I need to reference an external library or I have to run it in a webserver or I need to click a button to load the file through the browser, none of what I want.
Does native JavaScript support the function to read a text file and save it to an array? If so, any code direction would be great.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
XMLHttpRequest() exists in native JavaScript, I think it will help you.
You also can send a request to the file. Or use library: axios.js because when you use XMLHttpRequest() you lose many time to write code which just get content from file, with axios I got file content with one line: `axios.get('file.txt').then(result => console.log(result.data));
To connect Axios: <script src="https://unpkg.com/axios#0.18.0/dist/axios.min.js"></script>
You can read official documentation about axios.js and XMLHttpRequest() in the net.
I have an application that generates a HTML page with data which the user can edit.
At the end I generate a .pdf file with jsPDF.
Is there any way that I can save this generated .pdf on my server-side database?
I'm using PrimeFaces.
Thanks in advance
Updating my solution for other users:
I found the .output('datauristring') method of the jsPDF which returns me a BASE64 String.
Then the String is sent via JSON to my backed bean and converted as my will.
Thanks all for the help! I've found my solution:
Once the user presses on the button to generate the .pdf, I'll save all the data he filled on the database, just the data.
When the user wants to see the pdf he generated back, I'll generate a new one with the data collected on his first submit.
Thank you all for the answers, they were helpful.
I suggest to use wkhtmltopdf.
It is a open source cross platform command line tool to generate pdf files from html content.
So to your requirement what you can do is, you need to send the html content to the server and save this content into a html file.
Once you saved html content into html you can call wkhtmltopdf like you execute MS-DOS commands in java.
Example: new ProcessBuilder("wkhtmltopdf.exe", htmlFilePath, pdfFilePath);
Once pdf file is generated you can read and store into database.
I'm building a user dashboard in Django for a python based web service. This web service creates emails, and the HTML strings of these emails are saved in a file (and could theoretically also be saved in a db table). As part of the dashboard functionality I want to be able to preview the email, essentially rendering the html string of the email within the Django html view. Is it possible to do this? Will I need to work with a Javascript library to achieve this? Which one? Any help would be very appreciated!
EDIT
To clarify, the html string when put into a text editor is about 360+ lines. It has its own styling and it's own <head>, <body>, etcetera, tags. I want to display it like a webpage within a webpage, if that makes sense, so that it looks like a proper preview. I just have no idea how to do this, my experience hasn't really been with js or front end dev.
make the email html available like any other page and display it inside of an iframe.
be warned - email clients don't use the same rendering engines as browsers. its hell. (we use this - https://litmus.com)
Nothing more but:
document.getElementById('IDofDisplayContainer').innerHTML = 'your mail HTML string';