Any way to reduce pdf file size in mpdf? - mpdf

I am using mpdf with cakePhp and a pdf about 7 pages and no images is about 5.5MB, how can I have a little size?
Thanks.
The basisc example creates a 5.4MB PDF File
$content = "Hola soy el html";
$mpdf = new Mpdf(['format' => 'Letter',]);
$mpdf->WriteHTML($content);
$mpdf->Output("prueba.pdf", \Mpdf\Output\Destination::DOWNLOAD);

At the action in controller:
$this->autoRender = false;

Related

html2canvas, upload image to wordpress library

I'm making a holiday blessing generator for client.
The final output goes to a div with an id="BRHBresults".
From that div I'm making a canvas and converting it to image,
I've managed to make the onclick function to download the image(just to make sure the result was correct), however what I need the onclick to do is,
upload the image to wordpress library and make a new post with this image as post_thumbnail.
I get an error:
"414 (Request-URI Too Large)"
So far I have come up with this:
Link to the page: [http://www.benedict.co.il/%D7%9E%D7%97%D7%95%D7%9C%D7%9C-%D7%91%D7%A8%D7%9B%D7%95%D7%AA/
]
Javascript/JQuery
$(".BRHshareToFB1").click(function(){
html2canvas([document.getElementById('BRHBresults')], {
onrendered: function (canvas) {
var data = canvas.toDataURL('image/png');
var image = new Image();
image.src = data;
var alink = data ;
//$('.BRHshareToFB2').attr('href', alink);
//$('.BRHshareToFB2').attr('download', 'filename.jpg');
//dataUrl = canvas.toDataURL("image/png");
alink = data.replace(/^data:image\/(png|jpg);base64,/, "");
$.post("/send.php?data="+alink);
}
});
});
PHP from send.php file
<?php
$dir = getcwd();
$now = date("U");
$imgstring = $_POST['data'];
$imgstring = base64_decode($imgstring);
file_put_contents("$dir/wp-content/uploads/blessing-$now.png", $imgstring);
?>
What am I missing? Please help! :)

Wordpress Image Uploader As Thumbnail

How can I convert the uploaded image to a 125x166px thumbnail?
// jQuery
wp_enqueue_script('jquery');
// This will enqueue the Media Uploader script
wp_enqueue_media();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function (e) {
// This will return the selected image from the Media Uploader, the result is an object
var uploaded_image = image.state().get('selection').first();
// We convert uploaded_image to a JSON object to make accessing it easier
// Output to the console uploaded_image
console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
});
});
You could use the wp_get_image_editor function.
Examples of how to use is available at: https://codex.wordpress.org/Function_Reference/wp_get_image_editor
But this is using PHP

Custom image size in new media uploader

I am developing a relatively simple Wordpress plugin for a client. It is used to upload/select images which are then saved (as image path) in the option variables and used as full-background images for the website's different categories/pages/etc..
Since images are of "wallpapery nature" (i.e. big) I added a custom image size with a maximum width of 1920 pixels (height is set to "auto", i.e. no image cropping). And that part also works, upon upload, images are being resized to my custom 1920 px width.
Now, the thing is, for uploading/choosing the background image I'm using the new media uploader and it works except that the chosen image (path) is always for the original uploaded image, for example "my-background-image.jpg".
My question is: is there a way to enable users (or make the uploader do it automatically) to select the 1920 px sized version of the original image, for example "my-background-image-1920x1080.jpg"?
Thanks!
I managed to sort out my problem, a bit differently than I first approached it - but it is a solution I'm even more pleased.
So, when you use the new media uploader, you have a jquery code that looks something like this:
jQuery(document).ready(function($){
var custom_uploader;
$('.upload_image_button').unbind('click').click(function(e) {
e.preventDefault();
formfieldID=jQuery(this).prev().attr("id");
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Choose Image',
button: {
text: 'Choose Image'
},
multiple: false
});
//When a file is selected, grab the URL and set it as the text field's value
custom_uploader.on('select', function() {
attachment = custom_uploader.state().get('selection').first().toJSON();
$('.' + formfieldID).val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
Now, note the part of the code that gets the selected file's url:
$('.' + formfieldID).val(attachment.url);
This gets the ORIGINAL attachment's (image) url. So, to get some other image size, like thumbnail, large, etc. you use this:
$('.' + formfieldID).val(attachment.sizes.thumbnail.url);
AND in the end, you can even use your own custom image size like this:
$('.' + formfieldID).val(attachment.sizes.mysize.url);
BUT... I ran into one stupid but very time-consuming problem: DO NOT give your custom image size a name that is separated by a minus sign, like "background-image"; because while Wordpress part of it will work (the new image size will be visible and usable) the jquery for media uploader won't work with it.
If you need a separator, use underscore instead, e.g. "background_image" and it will work normally! This could be a beginner's error on my part, but I thought it could save someone some time! :)

Load local file through HTML page inside stage webview

I have to show local image file in html through stagewebview.
When I load url of html in flex application, text content displyaed correctly, but it doesn't show a images for that. Any way I can load local file through html in stage web view?
The solution involves copying all your necessary files (html, images, css) to a storage directory, and then call your html in there. The URLs to images and CSS will be relative to that directory.
This code shows how to copy the contents of an entire directory called html into that storage directory, and then load test.html into your StageWebView object.
var source:File = File.applicationDirectory.resolvePath("html/") ;
var destination:File = File.applicationStorageDirectory;
source.copyTo(destination, true);
var initialURL = new File(destination.resolvePath("test.html").nativePath).url;
webView.loadURL( initialURL );
Be aware that you will be responsible for cleaning up that directory though.
You can load a local HTML file using the File Class. So it would be something like this:
var _locaWebFile:File = File.documentsDirectory.resolvePath(pathToHTMLContent);
var _webview:StageWebView = new StageWebView();
_stage.scaleMode = StageScaleMode.NO_SCALE;
_webview.stage = _stage;
_webview.loadURL(_localWebFile.url);
_webview.addEventListener(flash.events.Event.COMPLETE, loadData);
function loadData(e:Event):void
{
_webview.viewPort = new Rectangle(0, 0, _stage.stageWidth, _stage.stageHeight);
}
Also, you might have to make sure your paths to your images are correct.

How to print PDF or an image from a page

I have an ASP.NET app (it uses DevExpress v 10.2). There is a button called PRINT on a page. When the button is clicked the application should:
1. extract a file from its DB. The file is either PDF or JPEG (the application knows its type in runtime only)
2. TO PRINT OUT the file. Some ‘preview’ should be shown to user during this
The question is – how to implement this (the item ‘2’)? There is a well-known method to print out an image using JavaScript like the following:
function DisplayPrintPopup(html) {
var win = window.open('', 'popup', 'toolbar=no,menubar=no,width=500,height=500,scrollbars=yes');
self.focus();
win.document.open();
win.document.write('<head><style></style></head><body>' + html + '<style></style></head><body>');
win.document.close();
win.print();
win.close();
}
This could be Ok for me. But what to do when a file is PDF?
This just print an element from you page where strid=id of the element you want to print,
before the print is possible to view a preview:
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
http://forums.asp.net/t/1034884.aspx/1

Resources