How to access an Image in PDF using JavaScript? - php

I added an image to PDF using $p->load_image (http://www.php.net/manual/en/function.pdf-fit-image.php). Now, I want to write JavaScript in it so that the user can manipulate image in the PDF. How can I get access to the image in PDF using Javascript?

Using PdfLib, add the following option to the load_image call:
"iconname=HelloImage" where HelloImage is the name of the image. The complete call would be,
$p->load_image('jpeg', 'C:/hello.jpg', "iconname=HelloImage");
In Javascript code, you can access it. For example,
var hello_image = this.getIcon("HelloImage");
Now hello_image points to the HelloImage.

Related

How to get image source from HTML to PHP?

I want to get image source from user uploaded image and save it to my sql table.
I am using a Wordpress site and the Ultimate Member plugin. Uploaded images are saved in public_html/wp-content/uploads/ultimatemember, but I need image source, so that an admin can view the image in a browser.
What I would like to do is to get the image source and save it to my sql table.
I got an image source in HTML and jQuery with the following code:
<div hidden id="image_1"></div>
<div hidden id="image_2"></div>
<script>
var $ = jQuery;
$(document).ready(function(){
var passport_url = $('img[alt="I_1"]').attr("src");
document.getElementById("image_1").innerHTML = image_1_url;
var proof_url = $('img[alt="I_2"]').attr("src");
document.getElementById("image_2").innerHTML = image_2_url;
});
</script>
I want to write PHP code that gets content of <div id="image_1>" and <div id="image_2>" and saves it to mysql table. I know how to save the path to the sql table, I just don't know how to get the div content in PHP from HTML. What is the proper way to do it?
I don't know why you're trying saving data using manually created script.
Because in wordpress you can easily save meta data (that can be image src) using add_user_meta();
<?php add_user_meta( $user_id, $meta_key, $meta_value, $unique ); ?>
You don't even need to add src using js/innerHtml (as I don't think you want to save src using AJAX)
As you asked a proper way
So, I suggest you,
create a simple form
submit hidden feilds ie 'src'
use $_POST, and save data using add_user_meta();
Full article for add_user_meta
Thanks

PHP image upload and crop with url

I am using the below upload class for image upload and manipulating.
class.upload.php samples, a files uploading and images manipulation PHP class
Now I want to change form input type="file" to a text field where I will give a Image URL.
How can I make this uploading class to work.
Thanks In Advance.
this class seems to accept url's as arguments as well so just change the input type to text, name to for example image_url and use this line to manipulate the image as you wish after submitting the form:
$handle = new upload($_POST['image_url']);
Get the file name through text box and in background use php curl function to upload the file in the server and your uploading class will work fine
PHP Curl to upload file

Replace image with javascript

I'm very new to coding on the web and I'm trying to make something work.
I'm trying to make a little webpage with an easy function to replace an existing image on the page with an image that the users chooses from his own computer. All of this is expected to be done offline. I have however, no idea how..
How do I tackle this?
p.s. With offline I mean, I am expected that this can be done locally without uploading to a server or anything. I am supposed to put this little page on a usb stick so it can be used as a little tool.
Well. you will need to implement file upload functionaility.
you could uses http://www.uploadify.com/
if so then you would use the onUploadSuccess method, to change the image.
when you say offline? do u mean no internet connection, or will the webpage live on a server like a intranet?
............Just to add to my own answer ........
OK, So you need it on a USB. why not install a standalone Server on the USB that way you can run PHP.
http://www.server2go-web.de/index.html
http://www.uwamp.com/en/
$("#file_upload").uploadify({
height : 30,
width : 120,
swf : 'include/fileuploader/uploadify.swf',
uploader : 'include/fileuploader/uploadify.php',
'onUploadSuccess' : function(file, data, response) {
console.log('The file was saved to: ' + data);
$("#img-preview").html("<img src='"+data+"' />");
}
});
I thought I'd show a code example, as this is the idea of StackOverflow. I hope it illustrates how this thing works.
Instead of relying on a set of plugins and libraries you will find out that it is perhaps even easier with native javascript. You can add jQuery to the mix for event handling, etc if you want, it is pretty much standard in the web-dev toolkit anyway.
HTML
First lets add the html for the input and a placeholder img element. You could of course dynamically add the img file with jQuery or native js.
<input id='ourfile' type='file' />
<!-- The image placeholder for our preview -->
<img id='preview' src='' />
Javascript
// Lets cache our two elements of interest.
ourfile = document.getElementById('ourfile');
preview = document.getElementById('preview');
// Create an instance of the 'native' FileReader.
fr = new FileReader();
// When our input triggers change (i.e. image is selected) load the file using the file reader.
ourfile.onchange = function () {
file = ourfile.files[0];
fr.readAsDataURL(file);
}
// Bind to the `onload` event of our FileReader and set the src of the image to the result (base64 of the image).
fr.onload = function(){
preview.src = fr.result;
}
Details
The link in #Akki619's answer shows about details for checking validity of the image, etc.
Fiddle
Here is a link to a working example:
http://jsfiddle.net/rUvUX/4/
This (readAsDataURL) is what you are looking for.
See working example here
In the example attached, you can send the base64 data of your selected image for uploading also.
OUT OF TOPIC HERE: Most of the client are looking for a mobile web app, an app to take picture from phone and send to the server. Not entirely feasible in web apps.
you can use the below javascript to do this:
<script>
function changeImage(newimage)
{
image = document.getElementById('oldimage');
image.src = newimage;
}
</script>

Save as pdf in print window javascript code

HELP.. how to Save as pdf in print window in javascript code
How to change this code ?
PDF
I need to make my link open the print window but automatically set the destination to "Save as pdf" instead of "print"?
You cannot do this via javascript.
You can do this:
PDF
In getpdf form pdf file via TCPDF or other

Upload an image with PHP using JQUERY Object

I have an image (a captcha specifically) that I want to upload to my server using PHP (or if possible and better, only JQUERY)
I created an object with this code:
var newIMG = $("img[name='captchaImage']").clone();
But I cannot send it via jQuery's ajax method or else. (Even tried to manually add but no idea how to send an object as file)
What should be the simplest PHP / jQuery code to send this object?
Thanks in advance,
You can use jsupload plugin for this purpose.
One cannot upload files using AJAX..
You can also use an iframe to simulate uploading the files..
only jquery file upload is not possible you need php
and you can use the jQuery File Upload to upload file via ajax and jquery

Categories