I can generate a pdf to view and to download easily. I am trying to send an email with the pdf attached. I have browsed google for hours and hours for several days and nothing gets me any closer than this link, sending an email attachment using TCPDF . I am getting the same issue the asker had on the linked question. the email sends with the attachment just fine but the pdf is empty and "appears corrupted" according to adobe.
The consensus seems to be that phpmailer is the best way to go so I have installed phpmailer and I have the following code. Now I get this error, Fatal error: Call to a member function Output() on a non-object on line 122. If anyone can please help I would appreciate it!
<?php
include ('../../include/connect.php');
$action=$_GET['a'];
/*----------*/
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
//$image_file = K_PATH_IMAGES.'name_bar.gif';
//$this->Image($image_file, 30, 5, 150, '', 'GIF', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
//$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', '', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('TEST');
$pdf->SetTitle($title);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(10, 10, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (#file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', 'B', 20);
// add a page
$pdf->AddPage();
// set JPEG quality
$pdf->setJPEGQuality(300);
// Image method signature:
// Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Example of Image from data stream ('')
$imgdata = base64_decode('iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==');
// The '#' character is used to indicate that follows an image data stream and not an image file name
//$pdf->Image('#'.$imgdata);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Image example with resizing
//$pdf->Write(0, 'Example of HTML tables', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
// -----------------------------------------------------------------------------
$tbl = <<<EOD
test
EOD;
$pdf->writeHTML($tbl, true, false, false, false, '');
// -----------------------------------------------------------------------------
//Close and output PDF document
if($action=='I'){
$pdf->Output($title, 'I');
}elseif($action=='D'){
$pdf->Output($title, 'D');
}
//============================================================+
// END OF FILE
//============================================================+
if($action=='E'){
$attachment = $makepdf->Output($title, 'E');
SENDmail($attachment);
function SENDmail($pdf) {
require_once('../../include/class.phpmailer.php');
$mailer = new PHPMailer();
$mailer->AddReplyTo('reply#to.ca', 'Reply To');
$mailer->SetFrom('sent#from.ca', 'Sent From');
$mailer->AddReplyTo('reply#to.ca', 'Reply To');
$mailer->AddAddress('email', 'Send To');
$mailer->Subject = 'Message with PDF';
$mailer->AltBody = "To view the message, please use an HTML compatible email viewer";
$mailer->MsgHTML('<p>Message contents</p>');
if ($pdf) {$mailer->AddStringAttachment($pdf, $title);}
$mailer->Send();
}
}
?>
You can store a PDF as a string:
$attachment = $pdf->Output('hotel4cast.pdf', 'S');
And then attach it with PHPMailer by:
$mail->AddStringAttachment($attachment, 'filename.pdf', 'base64', 'application/pdf');
The reason you're getting that error is simply because you are referring to $makepdf instead of $pdf.
Related
How i can to crop image after upload and send edited response ulr to frontent?
I will be grateful for the answer
MY CODE:
const stream = cloudinary.uploader.upload_stream(
{
folder,
},
(error: UploadApiErrorResponse | undefined, result: UploadApiResponse | undefined): void => {
console.log(error, result)
if (result) {
resolve({
url: result.url,
size: Math.round(result.bytes / 1024),
height: result.height,
width: result.width,
})
} else {
reject(error)
}
}
)
streamifier.createReadStream(buffer).pipe(stream)
The most common method of integrating Cloudinary is that you upload the original file to your Cloudinary account and store the Upload API response to your database which contains the details for the image: https://cloudinary.com/documentation/image_upload_api_reference#sample_response
If you don't want to store the entire response, you should store at least the fields needed to create a URL for that image later: https://cloudinary.com/documentation/image_transformations#transformation_url_structure
(Which are public_id, resource_type, type, format, and timestamp) though strictly speaking, most of those are optional if your assets are images of type 'upload' - certainly you need the public_id though.
Then, in your frontend code, when adding the image to your page or to your application, you add transformation parameters when building the URL, asking that the image is returned with transformations applied to match it to where/how you're using the image.
A common option is to set the width and height to exactly match the image tag or image view, then apply automatic cropping if the aspect ratio of the original doesn't match, with the crop selection being automatic: https://cloudinary.com/documentation/resizing_and_cropping
A Javascript example to add those parameters, if the image should be 500x500 is:
cloudinary.url( public_id,
{
resource_type: 'image', //these are the defaults and can be ommitted
type: 'upload', //these are the defaults and can be ommitted
height: 500,
width: 500,
crop: 'lfill', // try to fill the requested width and height without scaling up, crop if needed
gravity: 'auto', // select which area to keep automatically
fetch_format: 'auto',
quality: 'auto',
format: 'jpg', // sets the file extension on the URL, and will convert to that format if needed, and no fetch_format was set to override that
});
The resulting URL will be something like: http://res.cloudinary.com/demo/image/upload/c_lfill,f_auto,g_auto,h_500,q_auto,w_500/sample.jpg
I'm building a small dialog.
I using Groovy from a gradle build script.
The dialog consists of a JList, a JTextField and a JButton.
The list is populated with names of files. There are many files so I only wanna show 5 files together with a scollbar to go thru the list.
I have tried to set visibleRowCount but it still shows all rows.
new SwingBuilder().edt {
dialog(modal: true, // Otherwise the build will continue running before you closed the dialog
title: 'Enter program name',// Dialog title
alwaysOnTop: true, // pretty much what the name says
resizable: true, // Don't allow the user to resize the dialog
locationRelativeTo: null, // Place dialog in center of the screen
pack: true, // We need to pack the dialog (so it will take the size of it's children
show: true // Let's show it
) {
vbox { // Put everything below each other
label(text: "Program Name:")
list(id:"programName", items: progNames, visibleRowCount: 8)
label(text: "Start Rule Name:")
input = textField(id: 'ruleName', text: startRuleName)
button(defaultButton: true, text: 'OK', actionPerformed: {
testProgram = programName.selectedValuesList
startRuleName = ruleName.text
dispose() // Close dialog
})
}
}
}
How can I limit the number of visible rows?
You just need to wrap the call to list in a scrollPane node, ie:
new groovy.swing.SwingBuilder().edt {
dialog(modal: true, // Otherwise the build will continue running before you closed the dialog
title: 'Enter program name',// Dialog title
alwaysOnTop: true, // pretty much what the name says
resizable: true, // Don't allow the user to resize the dialog
locationRelativeTo: null, // Place dialog in center of the screen
pack: true, // We need to pack the dialog (so it will take the size of it's children
show: true // Let's show it
) {
vbox { // Put everything below each other
label(text: "Program Name:")
scrollPane {
list(id:"programName", items: progNames, visibleRowCount: 8)
}
label(text: "Start Rule Name:")
input = textField(id: 'ruleName', text: startRuleName)
button(defaultButton: true, text: 'OK', actionPerformed: {
testProgram = programName.selectedValuesList
startRuleName = ruleName.text
dispose() // Close dialog
})
}
}
}
I'm trying to make a chart on Excel file via PHPExcel..
I can make the table for the datasource for the chart.. Look like this
and I've write code for the chart.. Look like this..
$values = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$1:$B$11', NULL, 11);
$categories = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$1:$A$11', NULL, 11);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($values)-1), // plotOrder
array(), // plotLabel
array($categories), // plotCategory
array($values) // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL,false);
$title = new PHPExcel_Chart_Title('Test Column Chart');
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
$chart = new PHPExcel_Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
$yAxisLabel // yAxisLabel
);
$objPHPExcel->getActiveSheet()->addChart($chart);
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->setIncludeCharts(TRUE);
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="aOSalesPerformance.xlsx"');
$objWriter->save('php://output');
And this is the error that excel give me when I'm trying to open the document that generated by that code
Why this error came ? Why Excel say Drawing Shape has been Removed ?
Any help appriciated
The primary reason you received that error is because you over-selected the plot values and included the header. For example with these two lines the range should start at A2 and B2, since A1 and B1 contain the header and NOT values you want plotted.
So these two lines:
$values = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$1:$B$11', NULL, 11);
$categories = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$1:$A$11', NULL, 11);
Should be:
$values = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$11', NULL, 11);
$categories = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$11', NULL, 11);
That will take care of the error, but your chart will still not be displayed since you also need to specify a location for said chart to be displayed. So these two extra lines will also need to be added:
$chart->setTopLeftPosition('A20');
$chart->setBottomRightPosition('L50');
That will take care of the error you are receiving and the lack of displayed graph. However I would recommend creating the array for $values and $categories outside of creating the $series object as that would allow for plotting more than just one column of data. This website has a good tutorial on creating charts using PHPExcel
Corrected code below:
$values = array();
$values[] = new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$11', NULL, 11);
$categories = array();
$categories[] = new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$11', NULL, 11);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($values)-1), // plotOrder
null, // plotLabel
$categories, // plotCategory
$values // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL,false);
$title = new PHPExcel_Chart_Title('Test Column Chart');
$k="y axis";
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
$chart = new PHPExcel_Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
$yAxisLabel // yAxisLabel
);
//Location where chart will be displayed
$chart->setTopLeftPosition('A20');
$chart->setBottomRightPosition('L50');
$objPHPExcel->getActiveSheet()->addChart($chart);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="aOSalesPerformance.xlsx"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
I have charts generated via HighCharts through a WP AdCenter plugin. I want users (admins and subscribers alike) to be able to download the raw data driving the chart as Excel or CSV, not just a PNG, JPG or PDF image of the chart. Is there a way to do this without too serious a modification of the code (I'm not a PHP programmer). Is this additional export option a feature that could be rolled out in the near future?
This jsfiddle help you to create excel from highchart.
The Download CSV option added to export menu works fine. just go through that and you will do your own better.
Here is the code:
/**
* A small plugin for getting the CSV of a categorized chart
*/
(function (Highcharts) {
// Options
var itemDelimiter = ',', // use ';' for direct import to Excel
lineDelimiter = '\n';
var each = Highcharts.each;
Highcharts.Chart.prototype.getCSV = function () {
var xAxis = this.xAxis[0],
columns = [],
line,
csv = "",
row,
col;
if (xAxis.categories) {
columns.push(xAxis.categories);
columns[0].unshift("");
}
each (this.series, function (series) {
columns.push(series.yData);
columns[columns.length - 1].unshift(series.name);
});
// Transform the columns to CSV
for (row = 0; row < columns[0].length; row++) {
line = [];
for (col = 0; col < columns.length; col++) {
line.push(columns[col][row]);
}
csv += line.join(itemDelimiter) + lineDelimiter;
}
return csv;
};
}(Highcharts));
// Now we want to add "Download CSV" to the exporting menu. We post the CSV
// to a simple PHP script that returns it with a content-type header as a
// downloadable file.
// The source code for the PHP script can be viewed at
// https://raw.github.com/highslide-software/highcharts.com/master/studies/csv-export/csv.php
Highcharts.getOptions().exporting.buttons.contextButton.menuItems.push({
text: 'Download CSV',
onclick: function () {
Highcharts.post('http://www.highcharts.com/studies/csv-export/csv.php', {
csv: this.getCSV()
});
}
});
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
$('#getcsv').click(function () {
alert(chart.getCSV());
});
You can do it outside the scope of HighCharts. You can always pull out what the series.data values are and iterate through them to make a CSV from within javascript on the page. Or you could do it ahead of time on the backend.
You can add export button (http://api.highcharts.com/highcharts#exporting.buttons.contextButton.onclick) and prepare function which will get all values from chart (kept in chart.series object) and push to string/array. Then you need to find a solution how to "produce" file in javascript, and fill it with array/string.
We are using extjs 3.4. The purpose is to replace a component in a Ext.Window. Even if
there is no error when we remove the old and add the new component, when trying doLayout() the error
Uncaught TypeError: Cannot read property 'offsetWidth' of undefined
occurs.
The code that creates the window is:
function createWindowConf(id, winconf, items) {
var conf = {
id: id,
title: winconf.title,
iconCls: winconf.icon,
x : winconf.xpos,
y : winconf.ypos,
width : parseInt(winconf.xsize),
height : parseInt(winconf.ysize),
layout : winconf.layout, //'border',
border : false,
resizable : winconf.resizable,
manager: windows,
shadow: false,
closable: true,
items: items
};
var win = new Ext.Window(conf);
win.render(desktopEl);
return win;
};
The items are a Ext.grid.GridPanel and a Ext.form.FormPanel.
According to user's current selection in grip (component in position 0) the old form should be removed and a new should be added (component in position 1).
The code that creates the form is:
var theConfig = {
id: config.yid,
bodyStyle: 'padding:5px 5px 0',
width: 370,
maxWidth: 370,//not resizable
minWidth: 370,
layout: 'form',
margins: '0 0 0',
region: 'east',
split: true,
colapsible : true,
trackResetOnLoad: true,
autoScroll: true,
fieldDefaults: {
msgTarget: 'side',
labelWidth: 75
},
items: [],
buttons: [scopeDetails.updateButton, scopeDetails.submitButton]
};
this.detailsForm = new Ext.form.FormPanel(theConfig);
and the items added afterwards.
The code that updates (adds/removes) components from the window is:
this.updateWin = function(moduleForRemoveId, form, idWin) {
var win = this.getWindow(idWin);
if (win != null) {
win.remove(moduleForRemoveId);
win.add(form);
win.doLayout();
}
}
and produces the error in win.doLayout().
By removing all components and add the add the new ones:
win.removeAll();
win.add(this.grid);
win.add(this.form);
win.doLayout();
we have the same error.
Any suggestion will be really helpful since more than 3 days spent for that error
I'm pretty sure the error comes from something else rather than the component remove/add.
I created a simple testcase which defines a window with a form and a grid, and a button which replaces everything with a panel. And it works.
Your code is incomplete. You should provide a full example.
Have you tried to debug it yourself? Enable "pause on uncaught exceptions" on your Chrome script debugger the reproduce the bug. You will get a stack trace of what happened, giving you hints on what is wrong. Of course include ext-all-debug.