I would like to use jQuery to POST for a dynamically generated PDF and display it on the same page.
I have successfully been able to POST the data to a PDF generating script (PHP), create a randomly named PDF file, and return that for jQuery to put into an <object></object> however that generates two requests. I also don't want to have jquery set an <object> src to generate.php?data=DATA_HERE due to the fact that there is a lot of data and I would rather POST
I would like to fetch the binary PDF data with jQuery and embed it into the DOM. Is this possible?
Related
I have a PHP script that generates images. At this moment with every request PHP creates a temporary directory and fills it with the created images, then it sends the links to JS, which displays them in the browser in a special order.
Is there any way to pass these images directly from PHP to JS without a temporary directory?
I don't want to use temporary directories because it takes space and resources of server and I have to check that images download has been completed before deleting them.
I am thinking on using Json encoding and decoding but I don't like this because it's time consuming.
Is there another way to send images directly from PHP to JS?
There is a way to work with using src to php script with headers:
Using PHP to send a certain image
or
How to generate image file using this PHP function?
But this I could only work with one image per request.
I mean - if I have 5 or 6 divs with images I have to make 5 or 6 requests from JS to my php script.
Is there a way to send multiple images from PHP to JS?
My first idea would be to encode those images with base64_encode and pass that encoded data to your JavaScript. With this approach, you don't have to save those images anywhere.
More information on displaying base64 encoded images: Base64 Encoding Image
What you can do to not overload your server is to use an image hosting external website, like imgur, giphy, etc. This will scale the image for you in different size, see their api.
Here I am going to share a little hack, to host permanently contents into the internet archive. it is easy to implement from php.
Please don't use it for high traffic.
1/ Host your content on your site, create a url_link.
2/ Post your link to archive.org:
https://web.archive.org/save/*url_link*
3/ Response is a link on the form:
https://web.archive.org/web/20180XXXXXX626if_/*url_link*
4/ Modify the link, remove if_ this is the permanent link for the next centuries.
https://web.archive.org/web/20180XXXXXX626/*url_link*
5/ Delete content from your server
I have a dynamic pdf file which needs to be filled programmatically. I am using itext libraries to do so. Below are the steps I followed.
Extract the dynamic pdf and get the data xml file.
Fill the xml data file.
Call the itext apis to generate new pdf by passing the template pdf and xml data file.
The issue I face is if there is a repeater inside the container (which has a close button) in the template pdf, its not copied into the generated interactive pdf file. None of the javascript functionalities are triggered when creating the new pdf and because of which some of the fields become read only.
Is it possible to trigger the javascript in the pdf while generating the new pdf or while opening the new pdf?
Much appreciate any help.
I want to allow my users to save my page as a PDF. I have created a print stylesheet and I can generate the PDF by using Javascript's print function. Here's my problem:
In Chrome, the browser generates a preview and shows it to the user. The user can then either save it or print it.
However, in IE and FF, print calls up a complex menu, and while it can generate a PDF by "printing" to PDFCreator, it's a complex process that many users won't understand.
What I want to do is to somehow duplicate the Chrome functionality for non-Chrome users. Options I have considered:
Screenshot the HTML page and render that image into a PDF with Javascript. There are libraries that do this, but I want my PDF to have the print layout.
Generate the PDF on the server and send it to the user's browser. This can be done, but it seems difficult to use the same HTML as the standard page.
My server is running PHP and the Zend framework. I can't use NodeJS or any headless browser to render on the server. Do I have any options?
I've done exactly what you want to do before using a library called dompdf (https://github.com/dompdf/dompdf). Here is how I used it:
I dropped the dompdf library into the "library" folder in my ZF project. Then, in my application when I'm ready to render the page I created a new Zend_View() object and set it up with whatever view script variables it needed. Then I called the render() function and stored the rendered output into a variable I then provided to dompdf. The code looks like this:
$html = new Zend_View();
$html->setScriptPath(APPLICATION_PATH . '/views/scripts/action_name/');
$html->assign($data); //$data contains the view variables I wanted to populate.
$bodyText = $html->render('pdf_template.phtml');
require_once(APPLICATION_PATH."/../library/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($bodyText);
// Now you can save the rendered pdf to a file or stream to the browser:
$dompdf->stream("sample.pdf");
// Save to file:
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents($filename, $pdf);
I have html stored in a hidden input on a page and I want to get the user to download it inside of an html file (or if I change the stream format to doc the html can be inside that word doc).
Is there a way jQuery can write some headers then put the html inside of the request and have a person download it?
I can then avoid submitting it to a PHP function to download it.
Not possible without using flash really - unless you us base64 limited strings in links to encode it.
I was wondering if this is possible, I'm not looking for code, i just want to be pointed in the right direction - php, asp or javascript. I have an xml file:
<?xml version="1.0" encoding="utf-8"?>
<Groups>
<Group>
<groupNum></groupNum>
<purgeGroup></purgeGroup>
<DupeRecs>
<DupeRec>
<Name></Name>
<Duplicate></Duplicate>
</DupeRec>
<DupeRec>
<Name></Name>
<Duplicate></Duplicate>
</DupeRec>
</DupeRecs>
</Group>
</Groups>
I would like to be able to load this into a web page and have the Duplicate tag display as a checkbox the user can the check/uncheck whether the record is a duplicate and this is written back to the xml file
Broadly, Here are the steps I would suggest :
"Deserialize" the XML into a corresponding object
Display the editable fields in a HTML form on your Web Page
Process the HTML Form action and update your "Deserialized" object.
"Serialize" the result back into the XML file.
You have to take care of multiple edits on the file using some locking mechanism.
I think the best way would be to while parsing the XML file for display, save it into certain variables that can be easily edited, and set these to the new variables for your XML file. When you have everything how you want it in the variables, re-assemble it and use the fopen(), fwrite() and fclose() commands to re-write the whole file.
EDIT: You could also look into PHP's XMLWriter functions.
I'm not sure what you mean by "load this into a webpage" but to have the Duplicate tag display as a checkbox suggests you want to convert the XML to a UI, for this I'd recommend XSLT which can be used to convert XML to anything including ASPX, PHP or JavaScript.
As for writing this back to the XML again I don't know where the XML file is but it is likely you want to send the user response back to the server somehow and that could be done in many ways.
In conclusion if your XML content is on the server then use XSLT to create a web page to display the UI and send the data back to the server.
If your XML content is client side then try Silverlight.