Zend PDF current page number in footer - zend-pdf

I use Zend PDF to generate PDF. I want to show a page number on each page in the footer. Is this possible?

This is a simple way to display a page number on the bottom right corner of each page :
$number_pages = sizeof($pdf->pages);
foreach($pdf->pages AS $key => $page) {
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(($key + 1) . "/$number_pages", 540, 15, 'UTF-8');
}

This is not a feature that is built into Zend PDF, so you will need to implement it yourself.

Related

How can give name for generate pdf using mpdf codeigniter

if anybody konws this,please help me.how to give name to pdf.
i generated pdf using mpdf codeigniter. on click of a button the pdf wil be viewed. but how can give name for that pdf? it shows 1 on the top of the pdf.how can i give name to that pdf?
My controller
public function viewpdf($key,$option) {
if($option=='1')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata1($key);
}
if($option=='2')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata2($key);
}
if($option=='3')
{
$searchdata['fetchproduct']=$this->b2bproduct_model->fetch_productdata3($key);
}
$html=$this->load->view('moderator/pdf_data', $searchdata,true);
//this the the PDF filename that user will get to download
$pdfFilePath = "shany.pdf";
//load mPDF library
$this->load->library('m_pdf');
//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "I");
}
Use this code.
$mpdf=new mPDF();
$mpdf->SetTitle('My Title');
$mpdf->WriteHTML('<p>Hallo World</p>');
$mpdf->Output('filename.pdf');
Set the title for the document. The title is displayed at the top of the Adobe Reader screen when viewing the PDF file
Use code as bellow
public function mypdf() {
$this->load->library('pdf');
$pdf = $this->pdf->load();
$html=$this->load->view('welcome_message',null,true);
$pdf->WriteHTML($html);
// write the HTML into the PDF
$output = 'your_given_name.pdf'; //You can give a name of your generated pdf file or you can create it auto on timestamp by using $output = time().'.pdf'.
$pdf->Output("$output", 'I');
}
If you send data to view page then replace the variable with null in line 4.
For more details please see the tutorial from here.
If you are interested on DOMPDF please see from here.

Image with live updating text

Need some help with images.
As the topic says, I want to create an image with live updating text on it.
This is mainly used by game servers and players to show off their stats and info. Server-wise, to show if the server is online and how many players are online and such.
I haven no idea how to do it and figured this would be the best place to find out. Since I don't have any idea what this is even called, i did not know what to search for.
Thanx in advance.
This is an html+css+ajax solution. Make the image an html element's background image. Let's use a div. Then position the text in the div. Use ajax to update the text. The image will remain the same while the text can be updated.
Was possible with the use of API. Created an API of the database I want to use, connected to the database and everything worked!
After using $API_GET to get the data, I set it into an array-format.
Used PHP for everything.
From there on I used imagecreatefrompng, obviously to select an image.
Set a few colors using imagecolorallocate and from there on it was purely adding the text on the image as to where I want them using imagettftext.
Creating an image, with live updating stats on it.
But we still have to tell the browser to load it as an image and not a page with an image on it, so therefor...
header( "Content-type: image/png" );
And imagesetthickness to 5, followed by imagepng and imagedestroy.
Code Extracts:
$API_GET = file_get_contents("API URL");
$API_GET = json_decode($API_GET);
$API = array();
foreach ($API_GET as $key => $value) {
$API[$key] = $value;
}
if (file_exists($imagefile)) {
$bg_img = imagecreatefrompng ( "IMAGE URL");
$color_red = imagecolorallocate( $bg_img, 250, 0, 0 );
imagettftext($bg_img, 20, 0, 19, 36, $color_red, 'FONT URL.tff',"Text On Image");
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
imagedestroy( $my_img );
} else {
echo 'Image does not exist.';
}
That is the basic structure of the code.
Thank You for your reply to the question.

Magento - Auto set base, small and thumbnail on upload

Morning,
We have literally searched all over Stackoverflow and Google to find this solutions but still don't have the right answer.
We're trying to auto-set the Base, Small and Thumbnail options on the first uploaded image, so when uploading multiple images the first image will always have all three options checked.
If anyone has tried and succeeded with find this answer and advice, Thank you.
It is very easy. Example's here. Replace in root/js/mage/adminhtml/product.js in the end of handleUploadComplete around 120 row code
this.container.setHasChanges();
this.updateImages();
},
updateImages : function() {
with
this.container.setHasChanges();
this.updateImages();
$$('tr#media_gallery_content-image-1 td.cell-image.a-center input')[0].setAttribute('checked','checked');
$$('tr#media_gallery_content-image-1 td.cell-small_image.a-center input')[0].setAttribute('checked','checked');
$$('tr#media_gallery_content-image-1 td.cell-thumbnail.a-center input')[0].setAttribute('checked','checked');
},
updateImages : function() {
And enjoy autoselect first image after upload
If you have already uploaded your images and need to set the first one as thumb/base/small try the sql command in this post:
Just follow the instructions given by stereo_world and nhahtdh and then refresh your cache.
Thanks to Fabian and Doug for the groundwork. I just published an extension, which does exactly what you are trying to achieve in a clean way: https://github.com/customgento/CustomGento_AutoSelectImages
It simply adds a JS file on the admin product edit page. In the JS file, the mentioned method Product.Gallery.createImageRow is wrapped, so that the radio buttons can be selected after the first image has been uploaded. Here is the JS "magic":
if (typeof Product.Gallery !== 'undefined') {
Product.Gallery.prototype.createImageRow = Product.Gallery.prototype.createImageRow.wrap(function (parentMethod, image) {
// first call the parent method
parentMethod(image);
// auto-select the radio buttons for the first uploaded image
$H(this.imageTypes).each(function (pair) {
if (this.images.length === 1) {
this.getFileElement(image.file, 'cell-' + pair.key + ' input').checked = true;
}
}.bind(this));
this.setProductImages(image.file);
});
}

Creating image with hyperlink using google-apps-script

I have been trying to put an image with a hyperlink on it into a google apps script ui. I first thought of using createAnchor(), but that only allows text. Then I thought of using a button, but as far as I know you cannot open a new tab/window and redirect in a callback function.
I also tried createHTML(), but the element is not handled by it as yet.
I have seen people overlay transparent buttons over images, but still have same issue in callback.
My research has not found an answer to this. Does anyone have any solutions/examples?
Thanks
This worked for me on Chrome20 and IE9
// Container for box and results
var imageContainer = app.createFlexTable();
// Setup the button
var button = app.createButton("ImageButton");
button.setStyleAttribute("background", "url(dontshowimagehere.JPG) no-repeat");
button.setStyleAttribute("position", "absolute");
button.setStyleAttribute("color", "transparent");
button.setStyleAttribute('zIndex','1');
button.setStyleAttribute("border", "0px solid black");
imageContainer.setWidget(0, 0, button);
// image to click
var image = app.createImage("image.jpg").setId(imageId);
imageContainer.setWidget(1,0, image);
The image has a slight (3px) offset. If important, this looks to fix it http://www.w3schools.com/css/css_positioning.asp (use relative for the flex table and top etc for the image and button)
Did you try a transparent Anchor overlaying the image?
function doGet() {
var app = UiApp.createApplication().setTitle("Image Anchor");
var panel = app.createAbsolutePanel().setWidth('50%').setHeight('50%');
var image = app.createImage().setUrl("https://lh6.googleusercontent.com/-v0Q3gPQz03Q/T_y5gcVw7LI/AAAAAAAAAF8/ol9uup7Xm2g/s512/GooglePlus-512-Red.png").setStyleAttribute("width", "28px").setStyleAttribute("height", "28px");
var anchor = app.createAnchor("?", "https://plus.google.com/u/1/116085534841818923812/posts").setHeight("28px").setWidth("28px").setStyleAttribute("opacity", "0.1").setTarget("blank");
panel.add(image,100,50);
panel.add(anchor,100,50);
app.add(panel);
return app.close();
}
app.createAbsolutePanel()
.add(app.createImage('https://www.google.com/images/logos/google_logo_41.png'))
.add(app.createAnchor('','https://www.google.co.uk/intl/en/about/')
.setStyleAttributes({position:'absolute',top:'0px',left:'0px',width:'201px',height:'47px',opacity:'0'}))
This is a tested one. It works fine.
It doesn't work with positioning the image (as 'absolute').
It doesn't work with .setHorizontalAlignment(UiApp.HorizontalAlignment.CENTER)
I don't believe this is possible with the widgets available. I would suggest altering your UI's design to utilize an Anchor widget instead.
Use HTML Box if you are coding directly on your page. Click "Edit" to edit your page and go to "Insert>HTML Box" in your menu. It will accept javascript too! There are a few caveats - when using javascript, HTML Box will not accept links...too bad, but too many exploits there.
If you are coding in apps script, you could try to place the image on a panel and use absolute panel and position your link over your image. Another method could be to use the .setStyleAttribute for CSS styling and utilize the zIndex parameter to place a panel over top of your image....like so:
var panel = app.createSimplePanel();
// add your image to the simple panel or whatever panel you wish to choose in your GUI
var popPanel = app.createSimplePanel()
.setStyleAttribute('top','Y')
.setStyleAttribute('left','X')
.setStyleAttribute('zIndex','1')
.setStyleAttribute('position','fixed');
// add your anchor to the popPanel
app.add(panel).add(popPanel);
Not 100% sure if you can make this panel transparent, but you could try something like:
.setStyleAttribute('background',transparent')
or change the opacity via:
.setStyleAttribute('opacity','.5')
Hopes this gives you a few ideas!
I managed to do it with a single Anchor object and using CSS3.
It works on Chrome, I did not test it in other Browsers.
gui.createAnchor("", false, "$DESTINATION_URL$")
.setStyleAttributes({ "display":"block",
"width":"$IMAGE_WIDTH_IN_PIXEL$",
"height":"$IMAGE_HEIGHT_IN_PIXEL$",
"background":"url($URL_OF_THE_IMAGE$)",
"background-size":"100% 100%",
"background-repeat":"no-repeat" })
Of course you have to replace the $......$ with your data.
Thierry
If you first create all your HTML in a string, you can then replace the content of a page with the HTML you want like this:
var myString = 'the html you want to add, for example you image link and button';
var page = SitesApp.getSite('example.com', 'mysite').getChildByName('targetpage');
var upage = page.setHtmlContent('<div>' + myString + '</div>');

Resizing magento gallery images

i am trying to display product gallery images in my custom cms home page. If i use the code from media.phtml to display the gallery images, it does not work. I found this piece of code and it worked.
<div id="thumbs" class = "thumbs-home">
<?php
$obj = new Mage_Catalog_Block_Product_View_Media();
$_product1 = new Mage_Catalog_Model_Product();
// Load all product information of a particular product
$Products_one = Mage::getModel('catalog/product')->load($productId);
// Use your Product Id instead of $id
$countt = count($Products_one->getMediaGalleryImages());
if($countt>0){
foreach ($Products_one->getMediaGalleryImages() as $_image)
{
// For the Original Image
$thumb_img = "<img src=".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)." alt=''width='60' height='60' />";
echo "<a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)."'rel='lightbox[gallery]'>".$thumb_img."</a>";
//For gallery Image
//$resizeimage = $obj->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->backgroundColor(242,242,243)->resize(400,300);
//echo "<img src=".$resizeimage."alt='' />";
}
}
?>
This gets the actual images and gets resized by the width and height attributes. But i want to resize the image through magento. The last piece of code $resizeimage is not working for some reason. How can i make this work? The problem is that i am using a lightbox to display the gallery images which displays the actual high resolution images that are too large. The light box takes in width and height of image provided and i am not able to figure out as to how i set a standard dimensions for the light box. So the only other option is the have the images resized by magento before passing them to the lightbox. Thanks.
You just need to call proper object, instead of $obj->helper you should use Mage::helper, so your call should look like this:
print Mage::helper('catalog/image')
->init($product, 'thumbnail', $image->getFile())
->backgroundColor(255,255,255)
->resize(100,100);
And that's it! :)

Resources