Set title of pdf using mpdf file codeigniter - codeigniter

$this->load->library('m_pdf');
$pdf = $this->m_pdf->load();
$pdf->SetTitle('My Doc');
$pdf->WriteHTML($html);
$pdf->Output($pdfFilePath, "F");
Used SetTitle() function of mpdf but by default it is using name of file : "Untitled Document - _Test_Company_10120.pdf"
Also set the <title></title> tag but no use.

You used $pdf->SetTitle('My Doc');
Set the title for the document. The title is displayed at the top of the Adobe Reader screen when viewing the PDF file, and is include in the document metadata, which can be seen when inspecting the document properties in Adobe Reader.
So, Try this :
$pdfFilePath = "directory/your_pdf_name.pdf";
$pdf->Output($pdfFilePath, "F");

Related

svg images are not inserted in pdf while generating a pdf from html using itex7 html2pdf plugin

I am generating a pdf from multiple htmls. if any of the html consists img tag which refers to svg file like <img src="assets/6.svg" /> then in generated pdf doesnt have image included. If I keep jpg or png, then its included as part of generated pdf. Its happening only if I use below code but if I use HtmlConverter.convertToPdf() then svg files are showing fine in generated pdf.
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new File(pdfFileName)));
pdfDocument.setDefaultPageSize(PageSize.A4);
Document document = new Document(pdfDocument);
document.setMargins(40, 40, 40, 40);
for (String html : htmlFileList) {
List<IElement> elements = HtmlConverter.convertToElements(new FileInputStream(html), converterProperties);
System.out.println(elements.size());
for (IElement element : elements) {
System.out.println(element.getClass().getName());
document.add((IBlockElement)element);
}
}
document.close();
I am seeing error like below when generating a pdf from html using above code.
Unable to retrieve image with given base URI
(file:/C:/Projects/pdf_conversion/download/) and
image source path
(file:/C:/Projects/pdf_conversion/download/assets/cpc/img/icons/x_dont_gray.svg)
I am using above code because page content should be flown from page to page (dont want to create one pdf for one html). Any workaround is highly appreciated on this.

PHPOffice spreadsheet to PDF export

I have some spreadsheets in MS excell. Trying to convert them to PDF by using PHPOffice and mPDF class. I have a problem to create and display footers on every created PDF page
This is working code for creating a PDF from spreadsheet.
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($pe);
Is there any solution or method i can call after this to generate footers before use save() method?
Thanks in advance
You can use the footer methods e.g. generate a footer with linenumbers
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
$spreadsheet = $reader->load('<path>'); //Path of reader sheet
$sheet = $spreadsheet->getActiveSheet();
$sheet->getHeaderFooter()->setFirstFooter('&C&"-,Bold"Page &P from &N'); //generate Fristfooter
There are more header/footer possibility look documentation or class documentation

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.

Can't get the PHPExcel and CodeIgniter integration to work

This has been confusing me for days, I can't get the code below to work:
public function index (){
//load our new PHPExcel library
$this->load->library('excel');
$objPHPExcel = new PHPExcel();
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
//name the worksheet
$this->excel->getActiveSheet()->setTitle('test worksheet');
//set cell A1 content with some text
$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
//change the font size
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
//make the font become bold
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
//merge cell A1 until D1
$this->excel->getActiveSheet()->mergeCells('A1:D1');
//set aligment to center for that merged cell (A1 to D1)
$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$filename='just_some_random_name.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
}
}
All I get is a blank page. I tried tracing the codes to determine why it won't work and the line $this->load->library('excel');
is causing it.
I have created the excel.php file in /libraries, pasted the code from the example on the web.
Can someone help me on this one please?
Thanks in advance
The problem is how you install PHPExcel with CodeIgniter.
See you answer here:
PHPExcel error in CodeIgniter "Unable to load the requested class: iofactory"
Drop the phpexcel folder into application/third-party and create a library.
(for library use the class proviced by #devrooms in his answer)
Then do the following in controllers:
$this->load->library("excel");
$this->excel->load("/path/to/input.xls");
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->SetCellValue('B2', "whatever");
$this->excel->save("/path/to/output.xls");
If the above is not working see this answer to deactivate the php safe mode on your server
phpexel and codeigniter getting error

CKEditor 4: Image Properties dialog and custom preview image

Just to get you up to speed, I have set-up my CKEditor instance so that when viewing the WYSIWYG (live) mode [image:abc123] is replaced with the actual URL to the image.
So for example in the HTML source view, you see this:
<img src="[image:abc123]" />
But when you view the WYSIWYG (live) mode, it shows this:
<img src="/file/image/abc123" />
This is all working great. An issue I am now having is when you edit the image in Image properties. As the image does not exist, it show's the red x.
http://img405.imageshack.us/img405/104/jzny.png
My question is, is there a way to customise the Image Properties dialog so that if it matches [image:abc123], it loads a different image URL in the Preview window?
This code doesn't work but might make it a little clearer what I'm trying to achieve here.
CKEDITOR.on('dialogDefinition', function(evt) {
if (evt.data.name == 'image') {
var image_url = ???;
var preview_image = ???;
var file_id = image_url.value.match(/\[image:([a-zA-Z0-9-]+)\]/);
if (file_id)
preview_image.src = '/file/image/' + file_id[1];
}
});
Thanks in advance!

Resources