Laravel multiple PDF generation - laravel

I am using Laravel-pdf package package to generate pdf. I want to generating two pdfs with different contents. But this package does not allow me to create second pdf with different content. I am getting first content in the second pdf.
This is my code
$pdf = PDF::loadView('pdf.bill', $data);
return $pdf->save('invoice.pdf');
$pdf = PDF::loadView('pdf.invoice', $data);
return $pdf->save('agreement.pdf');

I have solved the issue by changing PDFWrapper class's save method as below
public function save($filename) {
$mpdf=new \mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML($this->html);
return $mpdf->Output($filename, 'F');
}

Related

How to set customPaper for domPDF in laravel?

This is my code in Controller. Now I want to set CustomPaper for printing because A4 size is not Portable for large width file in domPDF.
$category = Category::where('id',$request->category_id)->first();
$file = 'Client Ledger Report - '.date('d-m-Y').'.pdf';
$pdf = PDF::loadView('admin.reports.client_statement_report',compact('records','category','type','from','to'));
return $pdf->download($file);
Just write custom dimension in an array variable and by using setPaper() method and chain it with PDF::loadView()->setPaper($dimension).
Example:
$category = Category::where('id',$request->category_id)->first();
/* Custom Dimensions */
$dimension= array(0,0,680,920);
$file = 'Client Ledger Report - '.date('d-m-Y').'.pdf';
$pdf = PDF::loadView('admin.reports.client_statement_report',compact('records','category','type','from','to'))->setPaper($dimension);
return $pdf->download($file);

Remove Header and Footer to add new extra page

I',m using Laravel 5.5 to create a PDF file using barryvdh/laravel-snappy.
I want to generate a PDF with and extra page without header and footer. It is to print terms and conditions at the end of my budget.
I can generate the first 2 page with the products , price, header , footer... but when I add the terms and contiditons I have the footer and header and the pdf options ( marging...)
I have tried to remove header and footer using javascript when I loadView removing header and footer with css but I have a white space in those places but I need all the page.
$presupuesto = ExpedientePresupuesto::findOrFail($id_presupuesto);
$now = Carbon::now('Europe/Madrid');
$header = \View::make('expedientes.pdf.cabeceraPresupuesto', compact('now', 'request', 'presupuesto') )->render();
$footerHTML = Footer::footerHtml($now);
$footer = \View::make('expedientes.pdf.piePresupuesto', compact( 'footerHTML', 'request', 'presupuesto') )->render();
$pdf= \PDF::loadView('expedientes.pdf.cuerpoPresupuesto', compact('presupuesto', 'request'));
return view('expedientes.pdf.cabeceraPresupuesto', compact('now', 'presupuesto', 'request'));
$pdf->setPaper('a4');
$pdf->setOption('header-html', $header );
$pdf->setOption('footer-html', $footer );
$pdf->setOption('footer-spacing', 10 );
My question is it possible to add other page with differents optios in the same PDF? I mean, the first part of the PDF has header footer and anything I want and the last part has no header, other spacing...
Somenting like that ( does not working)
$pdf.= \PDF::loadView('expedientes.pdf.terms', compact('presupuesto', 'request'));
$pdf->setPaper('a4');
$pdf->setOption('header-html', '' );
$pdf->setOption('footer-html', '');
$pdf->setOption('footer-spacing', 10 );
return $pdf->stream( $now . '-PresupuestoFP.pdf');

Cronjob in Laravel 5

I have the job table contains post_at,day_open,block properties
The post_at property is the day when user post the job (Ex:2015-11-24)
The day_open property is the day that job is open (Ex:10)
The block property can contain 2 values 0 or 1. If post_at + day_open > right now the block value will change from 0 to 1
So how can I do that using cronjob?
First check wheather the post_at,day_open are edit in current date
$date = date('Y-m-d');
$job= DB::table('job') ->select('post_at','day_open','block')->where('updated_at',$date) -first();
$id=$job->id;
if(isset($job) && !empty($job))
{
$finding=CronJobCotroller::pushNotify($id);
}
if it's true it go to function pushNotify under the CronJobCotroller,here we write the coding for changing block field value 0 to 1.
public function pushNotify($id) {
$job= DB::table('job') ->select('block')->where('id',$id) ->get();
if(isset($job) && !empty($job))
{
foreach ($job as $cb)
{
$job= DB::table('job')->update('block',1)->where('block',0);
}
}
}

why is Matlab slow in for loop with large number of iterations but fast with a small number of iterations?

I am running a function to extract some information from 100,000+ patient xray dicom files. the files are stored within a veracrypt encryption container for security purposes.
when i run the function on a small sample of files it performs really quickly, however when i run the function on the entire dataset it is very slow in comparison, going from several files per second to 1 file per second (approximately).
i was wandering why this is happening? i have tried storing the data on an ssd and on a normal hard drive and get the same sort of slow down when using a larger dataset compared to a small one.
i have added the code below for reference but haven't commented it fully yet.. this is for my thesis so i will do it once i get the extraction finished..
thanks for any help.
function [ DB, corrupted_files ] = extract_from_dcm( folder_name )
%EXTRACT_FROM_DCM Summary of this function goes here
% Detailed explanation goes here
if nargin == 0
folder_name = 'I:\Find and Treat\MXU Old Backup\2005';
end
Database_Check = strcat(folder_name, '\DataBase.mat');
if exist(Database_Check, 'file')
load(Database_Check);
entry_start = length(DB) + 1;
else
entry_start = 1;
[ found_dicoms ] = recursive_search( folder_name );
end
mat_file_location = strcat(folder_name, '\DataBase.mat');
excel_DB_file = strcat(folder_name, '\DataBase.xlsx');
excel_Corrupted_file = strcat(folder_name, '\Corrupted_Files.xlsx');
% the recursive search creates a struct with the path for each
% dcm file found. the list is then recursivly used to locate
% the image and extract the relevant information from it.
fprintf('---------------------------------------------\n');
fprintf('Start Patient Data Extraction\n');
tic
h = waitbar(0,'','Name','Patient Data Extraction');
entry_end = length(found_dicoms);
if entry_end == 0
% set(handles.info_box, 'String', 'No Dicom Files Found in this Folder or its Subfolders');
else
% set(handles.info_box, 'String', 'Congratulations Dicom Files have been found Look Through the Data Base using the Buttons Below....Press Save Button to save the Database. (Database Save format is EXCEL SpreadSheet and MAT file');
for kk = entry_start : entry_end
progress = kk/entry_end;
progress_percent = round(progress * 100);
waitbar(progress,h, sprintf('%d%% %d/%d of images processed', progress_percent, kk, entry_end));
img_full_path = found_dicoms(kk).name;
% search_path = folder_name;
% img_full_path = strrep(img_full_path, search_path, '');
try %# Attempt to perform some computation
dicom_info = dicominfo(img_full_path); %# The operation you are trying to perform goes here
try %# Attempt to perform some computation
dicom_read = dicomread(dicom_info); %# The operation you are trying to perform goes here
old = dicominfo(img_full_path);
DB(kk).StudyDate = old.StudyDate;
DB(kk).StudyTime = old.StudyTime;
if isfield(old.PatientName, 'FamilyName')
DB(kk).Forename = old.PatientName.FamilyName;
else
DB(kk).Forename = 'NA';
end
if isfield(old.PatientName, 'GivenName')
DB(kk).LastName = old.PatientName.GivenName;
else
DB(kk).LastName = 'NA';
end
if isfield(old, 'PatientSex')
DB(kk).PatientSex = old.PatientSex;
else
DB(kk).PatientSex = 'NA';
end
if isempty(old.PatientBirthDate)
DB(kk).PatientBirthDate = '00000000';
else
DB(kk).PatientBirthDate = old.PatientBirthDate;
end
if strcmp(old.Manufacturer, 'Philips Medical Systems')
DB(kk).Van = '1';
else
DB(kk).Van = '0';% section to represent organising by different vans
end
DB(kk).img_Path = img_full_path;
save(mat_file_location,'DB','found_dicoms');
catch exception %# Catch the exception
fprintf('read - file %d corrupt.\n',kk);
continue %# Pass control to the next loop iteration
end
catch exception %# Catch the exception
fprintf('info - file %d corrupt.\n',kk);
continue %# Pass control to the next loop iteration
end
end
end
[ corrupted_files, DB ] = corruption_check( DB, found_dicoms, folder_name );
toc
fprintf('End Patient Data Extraction\n');
fprintf('---------------------------------------------\n');
fprintf('---------------------------------------------\n');
fprintf('Start Saving Extracted Data \n');
tic
save(mat_file_location,'DB','corrupted_files','found_dicoms');
if isempty(DB)
msg = sprintf('No Dicom Files Found');
msgbox(strcat(msg));
else
DB_table = struct2table(DB);
writetable(DB_table, excel_DB_file);
end
close(h);
toc
fprintf('End Saving Extracted Data \n');
fprintf('---------------------------------------------\n');
end
OK thanks for all the help..
My problem was the saving at the end of each iteration but the biggest problem was the line where i run the dicomread function. i changed the saving to occur for every 20 images processed.
I also removed the preallocation suggested in the comments to see what difference it made without the dicromread and saving a swell. it was considerably slower than with the preallocation.
... i just need to find a solution for dicomread (which i was using as a way to check if the file was corrupt or not).

how to update query in CI

i have update query problem in codeigniter.
$arrPartnerId = $partnerData['partner_id'];
print_r($partnerData['partner_id']);
if(is_array($arrPartnerId) > 0 ){
foreach( $arrPartnerId as $partnerId){
$this->db->set('partner_id', $partnerId );
$this->db->where('promotion_id', $promotionData['promotion_id'] );
$this->db->update('partner_promotion_relation');
}
}
my data is $aaPartnerId=([0]=>4,[1]=>5) and i have one id then how to update in database.
I think you confuse a where and set condition, you should rather have this :
$this->db->set('promotion_id', $promotionData['promotion_id']);
$this->db->where('partner_id', $partnerId);
$this->db->update('partner_promotion_relation');
It's just a hypothesis, because in your case you keep update 2 times the same line in your table, which is not logical.
If your array is like this,
$arrPartnerId = array(
0 => 4,
1 => 5
);
And
$promotionData['promotion_id'] = 123; //assumption
Then try this,
if(sizeof($arrPartnerId) > 0 )
{
foreach( $arrPartnerId as $partnerId)
{
$this->db->set('partner_id', $partnerId );
$this->db->where('promotion_id', $promotionData['promotion_id'] );
$this->db->update('partner_promotion_relation');
}
}
It will resolve the problem.

Resources