How to output an image to pdf in table specific php code? - php

I am being asked to only add code to the following function. I want to output a logo and additional text if possible. And the content of the export document is $this->ExportDoc->Text. I am using the following but it's not working.
The original example is
function Page_Exporting() {
$this->ExportDoc->Text = "my header";
return TRUE;
}
I tried the following and they wouldn't work
function Page_Exporting() {
$this->ExportDoc->Text('logo.jpg');
return TRUE;
}
or
I tried to add additional lines, the second always replace the previous, they refuse to show at the same time....
function Page_Exporting() {
$this->ExportDoc->Text = "my header1";
$this->ExportDoc->Text = "my header2";
return TRUE;
}
I just want to add logo.jpg and couple lines to the top of the pdf I want to export from php code.

With this lib it seems easier !
https://github.com/PHPOffice/PHPWord
Example of the official documentation :
https://phpword.readthedocs.io/en/latest/elements.html#images
PHPWord can generate pdf !
In other hand, are you sure about your path ?
$this->ExportDoc->Text('logo.jpg');
logo.jpg is on the same path as your php script ?
For example to get the current path of your script use __DIR__.
https://secure.php.net/manual/en/language.constants.predefined.php
And finaly had the absolute path use realpath.
https://www.php.net/manual/en/function.realpath.php
Example of code :
$path = realpath(__DIR__ . '/../Resources/Asset/images/logo.png');
ExportDoc isn't a php native capability, so what are you using ?

Related

pass mysql value from php page to a joomla article and display relevant data inside of a joomla article

we are developing an application.website is being developed by joomla.Admin panel is being developed using a pure php.on index page(joomla), we are displaying some details from the backend.
my question is this, when we click on one of the records on that page can we display the relevant data inside of a article?
Hope i asked the question clearly.
please share your thoughts with us.
thanks in advance
Yes, you can do this, if I understand your question correctly.
Open up Joomla's main index.php. This is the index.php in the html root, not the index.php in one of the template folders.
Near the bottom of the file, or maybe the very last line you will see something like this:
// Return the response.
echo $app
Replace this line with the following:
// Return the response.
// parse $app for server side includes statements and execute them
// note: this will only work for executable code, it will not import text or html files
// we would need to check to see if the file were executable, then read it rather than execute it if it were not
$output = $app;
while(ereg('(<!--#include virtual="([^&]+)" -->)',$output,$groups)){ // extract the ssi command and the command
$i = 0;
while(!$inline){ // sometimes exec() fails for want of memory so we try a few times
exec($groups[2],$array); // get the output from the command
foreach ($array as $element) // concatenate the lines of output into a single string
$inline = $inline . $element . "\n"; // appending a new line makes the html source more readable
$i++;
if($inline | $i > 5)
break;
sleep(1);
}
$output = ereg_replace($groups[1],$inline,$output); // replace the ssi command with the output
}
echo $output;
This will allow you to place a standard server side includes statement in your article. Fore example if you want to execute a php file in the same directory as your index.php and the file is called dynamic_content.php you would type this in your article:
<!--#include virtual="dynamic_content.php"-->
The output of that script will then be included in the text of the article. You can have multiple ssi commands in the same article.

PHP : Get Icon from apk

finally i could get information about apk like version , package, name & ... with this source :
PHP APK Parser
icons path in apks are not unique in all apps, in some "icon.png" and other "ic_launcher.png" and in different folders. here is my problem , how i can get icon anyway, without error and bug and without tools like "apktool" and "appt" ?
actually i wanna get and view icons directly in my small site
sorry for my bad English
Use this with pclzip.lib.php Library..
<?php
require_once 'pclzip.lib.php';
$path = 'path/to/apk';
$default = 'path/to/default_icon.png';
$destination = 'path/to/destination.png';
$zip = new PclZip($path);
$data = $zip->extract(PCLZIP_OPT_BY_PREG, "/res\/drawable(|-ldpi|-mdpi|-hdpi|-xhdpi)\/(ic_launcher|icon|logo|icn|ic|i).(png|jpg|jpeg|gif)/isU", PCLZIP_OPT_PATH, './tmp', PCLZIP_OPT_REMOVE_ALL_PATH);
$icn = end($data);
$icn = $icn['filename'];
//now you have path to the icon in ./tmp folder
if(!empty($icn)){
copy($icn, $destination);
} else{
copy($default, $destination);
}
foreach($data as $dt){
#unlink($dt['filename']);
}
?>
I hope this will work for you..
EDIT:
At the time of my first answer, there wasn't a reliable method/library available. So, I created a temporary method. Which was working for me.
Now, we have a better library, you should use that.
Library: php-apk-parser by Tufan Barış YILDIRIM
Example: ApkResource.php

How do I find the filename of an image on a MediaWiki page using php?

How do I find the filename of an image on a MediaWiki site?
I don't want to put the filename in manually. I need PHP code which will fetch me the filename.
I can use $f = wfFindFile( '$filename' ); but HOW DO I GET $filename?
I've been looking at the FILE class but I can't figure out how to use File::getFilename(); I keep getting an error call to undefined method.
What am I doing wrong?
Explaining in more detail:
I would like to add the pin it button to my site so when you click on the button it post it on the pin it board with the image and description of the image. I need to use php to send the image information so it works on every page on my site. I can't code the image name manually each time.
So far I have the code:
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
Which works great except I need to put in a value for $f (image name). My question is how do I get the value of $f without having to put in in eg $f = wfFindFile( 'Sunset.jpg' );
I would have thought this would be a really common request for anyone trying to add pinterest to their site.
Thanks
The $filename you are looking for is basically how it is named in MediaWiki when it got uploaded, for example Landscape-plain.jpg. You will just use the wfFindFile() helper function to get a File object. Then call the methods:
$ php maintenance/eval.php
> $file = wfFindFile( 'Landscape-plain.jpg' );
> print $file->getName();
Landscape-plain.jpg
> print $file->getPath();
mwstore://local-backend/local-public/b/b0/Landscape-plain.jpg
> print $file->getFullPath();
/path/to/images/b/b0/Landscape-plain.jpg
> print $file->getTitle();
File:Landscape-plain.jpg
> exit
API documentation:
http://svn.wikimedia.org/doc/classFile.html
http://svn.wikimedia.org/doc/classLocalFile.html
EDIT BELOW
The file informations are available through a File object, so you definitely need to use wfFindFile() to get such an object.
To actually find the filename for the page the user is browsing on, you want to use the query context and get its title:
$context = RequestContext::getMain();
$t = $context->getTitle();
if( $title->getNamespace == 'NS_FILE' ) {
$filename = $title->getPrefixedText;
// do your stuff.
}

Converting from server image URL to absolute address

I guess this is a simple question but I really can't find anything that would help me.
I'm using an image download script and for that I need an image URL that looks like:
"/home/clients/websites/w_apo/public_html/apo/wp-content/uploads/2012/05/Beautiful.jpg"
[type1]
but what I have is:
"http://www.apo.com/wp-content/uploads/2012/05/Beautiful.jpg"
[type2]
I tried to write a function that returns the URL of type 1 to the URL of type 2 but it doesn't work all that great.
This is how it looks:
function relativeToServerAddress($relativeURL) {
$paths = explode('wp-content/', $relativeURL);
$thePath = getcwd()."/wp-content"."/".$paths[1];
return $thePath;
}
Is there any better way to do this? I tried to find a predefined function but failed.
Thanks
$file = basename("http://www.apo.com/wp-content/uploads/2012/05/Beautiful.jpg");
return getcwd()."/wp-content/".$file;
?
you need to inform us with the directories you wish to keep/move from absolute url;
the above just copies the file.

TCPDF cant image because it is using a wrong directory path

I get my images in my pdf document on my localhost but on the production site i get the error TCPDF ERROR: [Image] Unable to get image i am using an html img tag to get the images and the src is the directory path to this image not a url, but i found out that TCPDF is adding the path i give it with the path to my www folder like:
path to picture i give to tcpdf: home/inc_dir/img/pic.jpg
tcpdf looks for it here: home/www/home/inc_dir/pic.jpg
can someone please help me find out tcpdf is concatenating the directories?
You can also change only the image path instead of main path use:
define('K_PATH_IMAGES', '/path/to/images/');
require_once('tcpdf.php');
This won't break fonts/ and other tcpdf paths.
TCPDF is using $_SERVER['DOCUMENT_ROOT'] as a root directory of all your images, and builds their absolute paths in relation to it. You can change it either in $_SERVER or with this PHP constant: K_PATH_MAIN:
define('K_PATH_MAIN', '/path/to/my-images/');
require_once 'tcpdf.php';
I use image data instead of paths. It can be passed to TCPDF using an # in the image's src-attribute, like so:
<img src="#<?php echo base64_encode('/path/to/image.png')?>" />
An img-tag in HTML takes a BASE64 encoded string, unlike the Image() function, which takes unencoded data.
I don't know if this is even documented, I found this by reading the code (tcpdf.php, line 18824 pp):
if ($imgsrc[0] === '#') {
// data stream
$imgsrc = '#'.base64_decode(substr($imgsrc, 1));
$type = '';
}
I have got the same problem. But it is now resolved.
I have change the code of TCPDF.php from
Old Code
if ($tag['attribute']['src'][0] == '/') {
$tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
}
$tag['attribute']['src'] = urldecode($tag['attribute']['src']);
$tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
New Code
if ($tag['attribute']['src'][0] == '/') {
$tag['attribute']['src'] = $_SERVER['DOCUMENT_ROOT'].$tag['attribute']['src'];
$tag['attribute']['src'] = urldecode($tag['attribute']['src']);
$tag['attribute']['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $tag['attribute']['src']);
}
Please try this.

Categories