I am currently using xepOnline to generate a pdf of my page.
This is working perfectly , but i now want a button next the download button which opens the mail program on your pc and attaches the generated pdf file.
My code so far: (not much)
function emailCurrentPage(){
window.location.href="mailto:?subject="+document.title+"&body="+escape(window.location.href);
}
<button onClick="javascript:emailCurrentPage()">Doormailen</button>
<button href="#" onclick="return xepOnline.Formatter.Format('content',{render:'download'},{pageWidth:'216mm', pageHeight:'279mm'}, {filename:'Test'});">Opslaan als PDF</button>
The syntax of mailto does not accept attachments. See the following as one description.
https://yoast.com/dev-blog/guide-mailto-links/
You would only be able to open the email itself with the TO, CC, BCC, Subject and Body filled out and the user would have to manually attach the PDF downloaded.
In #cloudformatter, the PDF is returned and is stored in the response. You could override the response handler to resend that PDF to a server-side application that sends the email for you.
As one of the authors of the xepOnline script and the server-side application that is handling the requests and formatting the PDFs, we already developed and have such functionality in the server itself. It is not available in the free-to-use version as we cannot support tens of thousands of emails sent daily by the users.
Related
I am using Laravel/Jquery with barryvdh/laravel-snappy to create a pdf on the fly from database data.
In the controller I have:
if ($request->ajax())
{
$document = Document::url($id)->first();
$pdf = PDF::loadView('app.documents.whitepapers.pdf', compact('document'));
return $pdf->download('filename.pdf');
// return response()->send($pdf->download('filename.pdf'), 200, $headers);
}
How can I push this PDF to the browser so that is available as a download?
When I do it without Jquery it is working perfectly. The reason that it is behind a Jquery function is that I use a Modal with a form to collect a persons data before the download can be initiated. This has ajax validation.
You will not be able to present the file as a regular download via JavaScript. In order to show a download prompt to the user, you'll need an extra step in your workflow.
I would suggest the following workflow:
User submits modal form
Form is validated via AJAX. If validation passes, respond with a URL to download the user's PDF from, instead of the PDF itself.
Your JavaScript redirects the user to this URL. Note that this is a redirect, rather than another AJAX request (see top.location.href)
When the user accesses that URL, you are able to deliver the PDF using the code snippet you provided in your original question. This snippet sets the content-disposition of the response appropriately, forcing the download prompt to appear in the user's browser.
If you need to customise the PDF generation for each user, make sure to include the user's ID (or another piece of identifying information) through to step 4.
I have a PDF that has a button with field name ctaButton.
ctaButton currently has a url pointing to https://mywebsite.com.
I want to host the PDF on my server at https://mywebsite.com/hosted.pdf.
And when I send someone a link to the PDF, I want to attach a UTM_term parameter ?utm_term=customer1 and then have the PDF read this parameter and update the ctaButton url to https://mywebsite.com/?utm_term=customer1.
I've been messing around with the Javascript actions in Acrobat for a couple of hours trying to make this happen. Any help greatly appreciated.
You can get the full url to the document using...
var myURL = this.url;
"this" in Acrobat JavaScript is the document context.
I did hours of research and came to this conclusion – Javascript in Acrobat is like trying to code in 1985 AND browsers will not execute whatever code you come up with.
So I used this workaround:
When I send the PDF to someone, I send it as a link with a base64
encoded stringified JSON package that contains a bunch of tracking
data but importantly, the name of the file to access as well as utm
parameters specific to the recipient
The link hits a server handler (NodeJS) that extracts the encoded
JSON package, and uses the data in the package to serve up an HTML
redirect page pointing to the right PDF file
Importantly, the HTML page also saves the JSON package to the
browser's localStorage . . . this comes in handy in subsequent
steps
The PDF file opens in browser (it doesn't have to, could be opened on
desktop) and the call to action link has a link to a get request
handler
The get request handler serves up ANOTHER redirect page
This second redirect page accesses the browser's local storage, looks
for the utm parameters I set for that user, and then redirects to the
sale page, with nice utm parameters attached
So to sum up, you don't add the utm parameters to the call to action link in the PDF (because that would make the world too easy to live in) and instead you do all these acrobatics (no pun intended) to attach utm parameters in the link clicks (via JSON strings saved in localStorage) during the process (i.e. when user opens email to extract file via link, and then when user clicks call to action in the PDF).
Any questions or clarifications please let me know in the comments and I will do my best to address.
Caveats
Only works if user uses same browser in all steps (i.e. if Susan opens the email in Safari, saves the PDF, then clicks the call to action in the PDF, and the link opens in Chrome, utm parameters will not be passed).
Assumes browser is modern and has localStorage
UPDATE: I came across another solution. It's a bit more convoluted. Diagram below.
Porky.io is a Javascript extension for Adobe Indesign. So flow is:
send Porky.io the customer data you need (e.g. utm's for links)
Porky.io generates PDF from a template you provide with the customer data you provided
Listen for a new file save from Porky
Do something with the file (e.g. email it to customer)
I believe you need to run an instance of Windows somewhere in the cloud (e.g. on Azure) to run Indesign with the Porky.io. Unless you want to rely on your laptop.
My project's not big enough yet to warrant setting this up . . . but good alternative if I need to make my current solution more robust.
What I want to do is to have a set of editable Excel files on my webpage:
I give links to what for the user represents an Excel file
With a click, the user's default program for editing Excel files (say, MS Excel) should open
After finishing editing, the file should be uploaded to my server transparently for the user, and next time the user visits my page, they should see their edited file and be able to edit it again
What I have considered:
JavaScript Excel-like grid. However, I did not find a JavaScript library with sufficient features, such as easily moving rows (any advice of a good JavaScript Excel component?)
Saving to DropBox / Google Docs /... using their APIs. However, it requires the user to have an account, and it will probably require me to manage user's DropBox passwords (and not all users will want to share passwords with me). Also, I will need to have interfaces to Google Drive, Miscrosoft OneDrive, and who knows how many other services.
Allow the user to download the file and rely on the user to upload it back again. However, this is too complicated for the user, and the users will forget to upload the files, which means losing their edits. Any way or uploading the file automatically upon closing?
A macro in my Excel files that would contact my server before exiting. However, this requires the user to enable macros (security alarm) and may be unreliable if the connection breaks. I did not evaluate whether this is technically possible.
Or what is the best / simplest way to achieve this?
(I know how to generate Excel files and how to open them from the webpage; my problem is how to get the user's edits back to the server transparently for the user.)
I think the easiest way to do this ("get the user's edits back to the server transparently for the user") is to use AJAX (JS) requests to PHP scripts.
AJAX is great for doing things in the background (asynchronously), but it can't edit the server. Just add an event listener in JS (an onchange or onblur, perhaps) and send an AJAX request every time the user edits the file.
PHP is a great server-side scripting language, and you can edit files with it.
EDIT: Example (on request)
Assuming that the Excel file is stored in a string in a <textarea> for simplicity (for now), you can set a listener to get the data from it (in jQuery), and send an AJAX request:
HTML:
<textarea id="excel"></textarea>
JS:
$("#excel").change(function() {
var excelFile = $(this).val();
$.ajax({
url: "updateFile.php",
method: "post",
data: { data: excelFile }
});
});
PHP (updateFile.php):
<?php
$data = $_POST["data"];
$file = fopen("FILENAME.xlsx", "w+");
fwrite($file, $data);
fclose($file);
?>
Any idea how to launch lotus notes from javascript and attach a document to a new mail programmatically. I know many will find it absurd.. but my stake holders seem to have a fascination with impossible feats!
could it be done via an xPage?
You can actually extend the mailto url abit and get a subject, body text and an attachment too
mailto:someone#example.com?subject=my new email&body=attachment below&attachment=c:\temp\thefile.txt
The attachment must be stored on a drive that the machine can access it's not and url.
And you might need double slashes.
If Lotus Notes is the default mail client (which it usually is if its an enterprise environment), then all you need to do is create a mailto: link.
For example:
Send email
This can be customised to include a subject or a body, and when clicked in a webpage will launch the default mail client and which should then populate form.
I have a html page with a form ,with few input fields, check box,radio buttons.
User can fill up the forms.
Is there any way , the user will be able to download the form (with the filled in data) in pdf format ?
1 more question, Any way to save the filled in form in html format or image format (of course File-> save of browser and screenshot are there) using java script code or html code , on a button click ?
I have tried http://code.google.com/p/jspdf/ , didnot able to get through it.
Thanks
[Adding a few more points]
if generating a pdf file using JS/HTML is not possible then ....
A bit more into it
Currently I am creating a server using C# application and when user requests a html page , I am sending the same to user.
that html page contains a form , which is needed to be filled
and I want the user to save the filled form in pdf format.
For now , I am able to process the static html form -> convert to pdf and provide the download to user ,
But can't get a way to enable the user to save the filled in form.
When the user presses the submit button , I can get all the filled in data using httpResponce object(GET/Post Method)!! , is there a way I can generate a pdf file using this httpResponce object parameters?
Or any way I can send the current html page content (e.g. getting all the contents in a div using jquery/javascript) and send it back, when user presses the submit button, in that way I can generate the pdf file at server side and provide a download - PDF format
Please ask , if I am not able to describe my question !!
jsPDF is an open-source library written by our lead developer, James,
for generating PDF documents using nothing but Javascript. You can use
it in a Firefox extension, in Server Side Javascript and with Data
URIs in some browsers. http://snapshotmedia.co.uk/blog/jspdf
Using only javascript to generate the PDF is not possible at this time. Using server-side scripting, it is possible to send the data to a server and let the server generate the PDF which is then sent to the user.
(Update): Using PHP, you can generate PDFs in the server-side using dompdf - HTML to pdf converter. Here is a demo: http://eclecticgeek.com/dompdf/docs_0-6-0/demo.php
In Google Chrome, there is a "Print to PDF" option. If you don't want to do any programming on the server side, you can just ask your users to access the page using Google Chrome. After filling out the form, they print the page as PDF.