a href is not working for dynamic url in mpdf - php

I am getting problem in anchor tag while export to PDF.Anchor tag is working for static url like http:google.com but it is not working for dynamic url.I am using mpdf module for PDF.
$url = $fullBaseUrl.'/designers/attachment/time/'.$value['filetime'].'/uploadTab/imgattach';
// http://localhost/msme_latest/designers/attachment/time/1394432246/uploadTab/imgattach
$html= ''.$value['filename'].'';
// echo $html; die;
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
When i echo my code $html it is giving my link properly.But when i export this code in PDF it is not giving any kind of link PDF.
Any help will be appriciated.

For solve this problem you have to make just i change in mpdf.php
Actual Code is in mpdf.php on line no.20146
if(isset($vetor[1]) and $vetor[1] != '') //LINK
{
if (strpos($vetor[1],".") === false && strpos($vetor[1],"#") !== 0) //assuming every external link has a dot indicating extension (e.g: .html .txt .zip www.somewhere.com etc.)
{
//Repeated reference to same anchor?
/*
while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
$this->internallink[$vetor[1]] = $this->AddLink();
$vetor[1] = $this->internallink[$vetor[1]];
*/
}
$this->HREF = $vetor[1]; // HREF link style set here ******
}
and you have just comment line of code (line number:20151 to 20153)
/*
while(array_key_exists($vetor[1],$this->internallink)) $vetor[1]="#".$vetor[1];
$this->internallink[$vetor[1]] = $this->AddLink();
$vetor[1] = $this->internallink[$vetor[1]];
*/
and your pdf will accept all link include "localhost" and other external links.

use Ip address instead of localhost or use Live server url it is working for me
<?php
$fullBaseUrl = "http://127.0.0.1/meme_latest";
$url = $fullBaseUrl.'/designers/attachment/time/'.$value['filetime'].'/uploadTab/imgattach';
//(http://localhost/msme_latest/designers/attachment/time/1394432246/uploadTab/imgattach)
$html= 'Test link';
//echo $html; die;
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>

Related

unable to print pdf (MPDF)

I am trying to print my content to PDF using Mpdf tool . The code is working in localhost , But when i tired same code in server its not working giving some eroor "mPDF error: Some data has already been output to browser, can't send PDF file".
My code is :
<?php
$address = "banglore rt nagar";
$template_data = " hello this is test ##ADDRESS## adress";
$template_data = str_replace('##ADDRESS##', $address , $template_data);
ob_end_clean();
include 'MPDF57/mpdf.php';
$mpdf=error_reporting(E_STRICT);
$mpdf=new mPDF('win-1252','A4','','',15,10,16,10,10,10);
$mpdf->Bookmark('Start of the document');
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($template_data);
$mpdf->Output();
exit();
?>
i have tried lot of solutions . but nothing works good . any help ?
Use ob_start(); after the <?php tags . hope it will helps you .
more ohttp://php.net/manual/en/function.ob-start.php

Google Calendar layout

I have been working with this php code, which should modify Google Calendars layout. But when I put the code to page, it makes everything below it disappear. What's wrong with it?
<?php
$your_google_calendar=" PAGE ";
$url= parse_url($your_google_calendar);
$google_domain = $url['scheme'].'://'.$url['host'].dirname($url['path']).'/';
// Load and parse Google's raw calendar
$dom = new DOMDocument;
$dom->loadHTMLfile($your_google_calendar);
// Change Google's CSS file to use absolute URLs (assumes there's only one element)
$css = $dom->getElementByTagName('link')->item(0);
$css_href = $css->getAttributes('href');
$css->setAttributes('href', $google_domain . $css_href);
// Change Google's JS file to use absolute URLs
$scripts = $dom->getElementByTagName('script')->item(0);
foreach ($scripts as $script) {
$js_src = $script->getAttributes('src');
if ($js_src) { $script->setAttributes('src', $google_domain . $js_src); }
}
// Create a link to a new CSS file called custom_calendar.css
$element = $dom->createElement('link');
$element->setAttribute('type', 'text/css');
$element->setAttribute('rel', 'stylesheet');
$element->setAttribute('href', 'custom_calendar.css');
// Append this link at the end of the element
$head = $dom->getElementByTagName('head')->item(0);
$head->appendChild($element);
// Export the HTML
echo $dom->saveHTML();
?>
When I'm testing your code, I'm getting some errors because of wrong method call:
->getElementByTagName should be ->getElementsByTagName with s on Element
and
->setAttributes and ->getAttributes should be ->setAttribute and ->getAttribute without s at end.
I'm guessing that you don't have any error_reporting on, and because of that don't know anything went wrong?

How to retrieve a script tag source content?

I have a small problem with my code..I accessed the src value in the script tag to get the content of the JavaScript page that is found at the server side..It is ok as i get what i wanted but the problem is that i am getting the html code also..I dont want the html code. Here below is what i have done..Please help?
<?php
//simple_html_dom.php caters for malformed html
include('simple_html_dom.php');
$html = new simple_html_dom();
//load the All code file
$html->load_file("test.txt");
$file = fopen("externalScript.txt","w");
$Script=$html->find("script");
$temp="";
$url="http://www.xyz.com";
foreach($Script AS $Spt){
$src=$Spt->src;
//check if the script src has "http://" prefix
if(strpos($src,'http://')!==0){
$src=$url."/".$src;
}
$get_script=file_get_contents($src);
$temp.=$get_script.PHP_EOL;
}
fwrite($file,($temp));
fclose($file);
?>

PHP Image not showing in HTML using img element

Hello there i have a php file with the included:
The image shows properly when i access the PHP file, however when I try to show it in the HTML template, it shows as the little img with a crack in it, so basically saying "image not found"
<img src="http://konvictgaming.com/status.php?channel=blindsniper47">
is what i'm using to display it in the HTML template, however it just doesn't seem to want to show, I've tried searching with next to no results for my specific issue, although I'm certain I've probably searched the wrong title
adding code from the OP below
$clientId = ''; // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png'; // Set online image here
$offline = 'offline.png'; // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
echo "<img src='$online' />";
} else {
echo "<img src='$offline' />";
}
The url is not an image, it is a webpage with the following content
<img src='offline.png' alt='Offline' />
Webpages cannot be displayed as images. You will need to edit the page to only transmit the actual image, with the correct http-headers.
You can probably find some help on this by googling for "php dynamic image".
Specify in the HTTP header that it's a PNG (or whatever) image!
(By default they are interpreted as text/html)
in your status.php file, where you output the markup of <img src=... change it to read as follows
$image = file_get_contents("offline.png");
header("Content-Type: image/png");
echo $image;
Which will send an actual image for the request instead of sending markup. markup is not valid src for an img tag.
UPDATE your code modified below.
$clientId = ''; // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png'; // Set online image here
$offline = 'offline.png'; // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);
header("Content-Type: image/png");
$image = null;
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
$image = file_get_contents($online);
} else {
$image = file_get_contents($offline);
}
echo $image;
I suppose you change the picture dynmaclly on this page.
Easiest way with least changes will just be using an iframe:
<iframe src="http://konvictgaming.com/status.php?channel=blindsniper47"> </iframe>

MPDF No Output (Blank Page)

I'd installed the MPDF utility in order to convert HTML&CSS to PDF reports.
So far things have been working just fine, until I've tried converting certain page to PDF ,and there's no output.
I have to mention that i'm able to display the page regularly through browser - the problem only comes up when i'm trying to convert it to PDF - then I receive blank page. Moreover, there are no encoding problems (part of the output is written in Hebrew, but I've already overcame this obstacle)
Here's part of the code :
if($customer!=$tempCustomer)
{
if($tempCustomer!="")
{
$html.=("</table>");
$html.=("</BR>סהכ".$sumTotal."</BR>");
$html.=("</BR>משטחים".$sumPallets."</BR>");
}
$sumTotal=0; //RESET SUM OF EACH CUSTOMER
$sumPallets=0; //RESET PALLETS COUNT
$html.=("</div>");
$html.=("<div class='subTable'>");
// $html.=("לקוח: ".$customerName."</br>");
$sumTotal=0;
$sumPallets=0;
$tempCustomer=$customer;
$html.=("<table border='3'
<tr><td>מגדל</td><td>תאריך</td><td>תעודה</td><td>פריט</td><td>סוג</td><td>גודל</td><td>כמות</td><td>משקל</td><td>מחיר
מכירה</td><td>סכום</td><td>משטחים</td></tr>");
$html.=("<tr>");
$html.=("<td>".$grower."</td>");
$html.=("<td>".$date."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$item."</td>");
$html.=("<td>".$type."</td>");
$html.=("<td>".$size."</td>");
$html.=("<td>".$quantity."</td>");
$html.=("<td>".$weight."</td>");
$html.=("<td>".$price."</td>");
$html.=("<td>".$total."</td>");
$html.=("<td>".$pallet."</td>");
$html.=("</tr>");
$sumTotal+=$total;
$sumPallets+=$pallet;
}
else
{
$html.=("<tr>");
$html.=("<td>".$grower."</td>");
$html.=("<td>".$date."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$item."</td>");
$html.=("<td>".$type."</td>");
$html.=("<td>".$size."</td>");
$html.=("<td>".$quantity."</td>");
$html.=("<td>".$weight."</td>");
$html.=("<td>".$price."</td>");
$html.=("<td>".$total."</td>");
$html.=("<td>".$pallet."</td>");
$html.=("</tr>");
$sumTotal+=$total;
$sumPallets+=$pallet;
}
/*
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("</tr>");
*/
}
$html2='אבדרכדכגכגכגכג';
$html3='אבדרכדכגכגכגכג';
//==============================================================
//MPDF SETTINGS - CONTINUE
$mpdf->SetAutoFont();
$mpdf->autoFontGroupSize = 1;
$mpdf->SetDirectionality('rtl');
$mpdf->useLang = true;
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
Any suggestions?
Thanks in advance
Have you tried debugging it? Per mpdf's site: If you get nothing but a blank screen on your browser, it may be because there is a script error. Turn on debugging at the start of your script.
<?php
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->debug = true;
$mpdf->WriteHTML("Hallo World");
$mpdf->Output();
?>
If the above works, then it's something with your code. Sometime, even a single space before any html output can throw off MPDF
First of all, If you get nothing but a blank screen on your browser, it may be because there is a script error. Turn on debugging at the start of your script.
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
try {
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
$mpdf->WriteHTML("Hello World");
$mpdf->Output();
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception
// name used for catch
// Process the exception, log, print etc.
echo $e->getMessage();
}
After that if there is any error like
Data has already been sent to output, unable to output PDF file
This means before creating pdf with mPDF some data is stored in the buffer which is sended to the browser. Therefore it is unable to create PDF.
Just do this..
Add this below php built-in function at the first line of your page were you are preparing data for pdf.
op_start();
And add this php built-in function before mPDF code (before where you are calling mpdf)
ob_end_flush();
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();
So that it will clear all buffer output before processing mPDF.
Make sure if you use any functions then keep it in the same page.
<?php
include_once("mpdf-master/mpdf.php");
include_once('../../../../wp-load.php');
$htm = get_template_directory_uri().'/admin/_invoice.php?id='.$_GET['id'];
$html = file_get_contents("$htm");
$mpdf=new mPDF('c');
$mpdf->WriteHTML($html);
$mpdf->Output();
?>
You can try link this.but you will get seconde page blank but in first page you will get the detail.
Thanks
Sanket.

Categories