Export div content to PDF using javascript

jquery code to generate pdf from div with automatic height and width –

Its can be easily done with html2canvas and jspdf. So, to generate pdf, first of all we have to include html2canvas and jspdf library.

For example –

Let’s say we have a div with id content and on a button(say Generate pdf) click, we want to export its content as a pdf.

First, write the code for creating button and include the required libraries(html2canvas and jspdf) –

<button id=”generatePDFbtn”>Generate PDF</div>
<div id=”content”>hello</div>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js”></script>
Then, create an event handler function to handle button click(Generate pdf button in our example) and write the code to generate the pdf –
<script>
$(document).on(“click”, “#generatePDFbtn”, function() {
        html2canvas(document.getElementById(“content”)).then(function(canvas) {
            var imgData = canvas.toDataURL(“image/jpeg”, 1.0);
            var pdf = new jsPDF(‘p’, ‘mm’, [400, 480]);
            pdf.addImage(imgData, ‘JPEG’, 0, 0, 400, 480);
            pdf.save(“search-result.pdf”);
        });
    });
</script>

For more related queries, please VISIT.

In case, if you did not find your solution or have any query/question, please contact us.

How to redirect http site to https using htaccess

Code to redirect http site to https using htaccess –

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

How to change controller and model directory path in codeigniter ?

Change controller and model directory path(in Codeigniter) –

You can changed it by using HMVC extension.
First of all download the extension code from –
https://github.com/skjain5793/codeigniter-modular-extensions-hmvc

Extract it and
i.) put /third_party  folder files in application/third_party folder
ii.) put /core folder files in application/core folder

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

Puzzles Interview Questions

Puzzles Interview Questions :

Ques: There are 3 persons in a room(say you and 2 others). From other 2 persons one speaks truth and another lies but you don’t know who speaks truth and who lies. There are 2 doors in the room(say door 1 and door 2) out of which 1 door opens. You have to ask only 1 question from 1 guy and have to find out which door opens.

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

How to check that current page is a blog page in wordpress ?

Code to confirm that current page is a blog page in wordpress

Make a function in functions.php –
if(is_archive || is_author() || is_home() || is_single() || is_home() || is_tag() && post= ‘get_post_type’){
echo “this is a blog page”;
}

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

Laravel Interview Questions 2020

Ques: What is artisan ?

Ans: Artisan is command-line interface that is used in laravel to develop an application. It provides some commands that may be helpful during development of an app.

Ques: What is composer ?

Ans: It is a dependency manager tool. Laravel also uses it to manage it’s dependencies.

Ques: What is middleware ?

Ans: As the name indicates, it acts as interface or middle layer between request and response. General example of middleware is authentication. If a user is authenticated then user will send to profile page otherwise, he/she will be redirected to login page.
There are 2 types of middleware in Laravel –
Global – It will run on every request.
Route – It will run with that route to which it is assigned.

Ques: What is dd() function ?

And: dd() stands for “Dump and Die”. It is Laravel’s helper function that can be used to dump the variable’s contents and to stop the further execution of script.

Ques: What are bundles ?

Ans: Bundles are packages that is a way to extend or add more functionality to Laravel.  These packages can have views, configuration, migrations, routes, and tasks which are mainly used to enhance the functionality.

Ques: Which database are supported by Laravel ?

Ans: Laravel supports the following databases:

– MySQL

– Postgres

– SQLite

– SQL Server

Ques: What is Lumen ?

Ans: It is a micro-framework of Laravel. It is smaller, faster an is a perfect solution for creating Laravel based  services and Restful APIs.

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

HTML Interview Questions 2020

Ques: What is root element ?

Ans:<html> is the root element.

Ques: What is difference between div and span tag ?

Ans: div is block level element and span is content level element.

Ques: What are listing elements ?

Ans: <ol> and <ul> are listing elements.

Ques: Tell me name of any block level element, inline-block level element and inline element.

Ans: Block Level Elements – <div>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>
Inline Block Level Element –
<span>
Inline Element – <button>

Ques: What is difference between bold and strong tag in HTML ?

Ans: <b> makes only look as bold while <strong> tag emphasize the text as important. Text in <strong> tag will have more importance.

Ques: What is optgroup ?

Ans: This tag is used to group related options in drop down.
For Example –
<select id=”cars”>
<optgroup label=”Maruti Cars”>
<option value=”swift”>Swift</option>
<option value=”spresso”>Spresso</option>
</optgroup>
<optgroup label=”Honda Cars”>
<option value=”city”>City</option>
<option value=”brio”>Brio</option>
</optgroup>
</select>

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

How to encode base64 in jQuery ?

Encode base64 in jQuery –
btoa() function is used for it.
For Example –
var str = ‘Hello’;
var encrypted_str = btoa (str);
alert( encrypted_str );

Output – SGVsbG8=

For more related queries, please VISIT.

In case, if you did not find your solution or have any query/question, please contact us.

Copy files to other server(ftp)

How to copy all files of a directory to a directory on other server ?
Suppose, we have to copy all files in a directory(dir/subdir) to other server directory(dir/sub) and we also have to create directory there(in case, if directory does not exist), then –

First of all make connection with Remote(other) FTP (from where we are copying the files) like –
$ftp_host = ‘host’;
$ftp_username = ‘ftp_username’;
$ftp_password = ‘ftp_password’;
$ftp_connection = ftp_connect($ftp_host);

Then, login to Remote or other ftp using –
$ftp_login = ftp_login($ftp_connection,$ftp_username,$ftp_password);

function isdir_ftp($ftp_connection,$dir){
$pushed = ftp_pwd($ftp_connection);
if($pushed!=false && @ftp_chdir($ftp_connection,$dir)){
ftp_chdir($ftp, $pushed);
return true;
}
return false;
}

Suppose, we have to copy the directory and files in public_html directory –
$server_path = “./public_html/”;
$file_path_server = “dir/subdir” ;
$server_file_path = $server_path. $file_path_server ;
$is_dir = isdir_ftp($ftp_connection, $file_path_server);
if(!$is_dir){
$dir = $file_path_server;
$dd = ”;
$d=explode(“,”,$dir);
for($i=0;$i<count($d);$i++){
$dd.=$d[$i].”/”;
//try to create dir
$dir = $dd;
$is_dir = isdir_ftp($ftp_connection, $dir);
if(!$is_dir){
if(ftp_mkdir($frp_connection, $dir)){
echo “Dir created successfully”;
}else{
echo “Error”;
}
}
}
}

Now read the files from local ftp from where we have to copy the files and the copy it –
$local_ftp_dir = ” dir/subdir “;
if ($handle = @opendir($ local_ftp_dir )) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”) {
$source= $ local_ftp_dir .’/’.$file;
$dest = “public_html/”.$ local_ftp_dir .’/’.$file;
$upload = ftp_put($ftp_connection, $dest, $source, FTP_BINARY);
if (!$upload) {
echo ‘FTP upload failed!’;
} else {
echo “uploaded successfully”;
}
}
}
}

ftp_close($ftp_connection);

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.