generating multiple pdf document and merge into one - codeigniter

This is my controller function where i am running a loop to create multiple document pdf
and merge into one.
public function tick_pdf(){
$tt='';
$name="iftekhar";
$title="Event Football";
$num=4;
for($i=0;$i<4;$i++){
$this->pdfHeader($row->EventId);
$this->pdf->fontpath = 'font/';
//$this->pdf->AddPage();
$this->pdf->Ln(10);
$this->pdf->SetFont('Arial','B',12);
$this->pdf->Cell(10);
$this->pdf->Cell(60,10,"Name",0,0,'L');
$this->pdf->Cell(10,10,":",0,0,'L');
$this->pdf->MultiCell(60,10,$name,0,1);
$this->pdf->SetFont('Arial','B',12);
$this->pdf->Cell(10);
$this->pdf->Cell(60,10,"Title",0,0,'L');
$this->pdf->Cell(10,10,":",0,0,'L');
$this->pdf->MultiCell(60,10,$title,0,1);
$this->pdf->SetFont('Arial','B',12);
$this->pdf->Cell(10);
$this->pdf->Cell(60,10,"Number",0,0,'L');
$this->pdf->Cell(10,10,":",0,0,'L');
$this->pdf->MultiCell(60,10,$num,0,1);
$this->pdf->SetFont('Arial','B',12);
$this->pdf->Cell(10);
$this->pdf->Cell(60,10,"Date",0,0,'L');
$this->pdf->Cell(10,10,":",0,0,'L');
$this->pdf->MultiCell(60,10,$date,0,1);
$tt.=$this->pdf->Output('', 'S');
}
echo $tt;
}
but I am gettiin an error in browser
"Undefined index: data
Filename: libraries/fpdf.php
Line Number: 1659" I am using fpdf for generating pdf

If you need to create multiple PDF documents you will need several class instances. Actually you're working with only one instance.
Also it is not possible to concatenate a PDF document by simply concatenating their bytes ($tt .= ...). Generally it is not possible to send multiple PDF documents to the client in a single request.
If you want to create multiple pages, just remove the comment before AddPage(), delete the variable $tt and move the Output() call outside of the loop.

Related

i want to arrange the data as in text file but its format has been changed when i tried to get the file from directory and displayed in an app

I want to arrange the data as in a text file but its format has been changed when I tried to get the file from a directory and displayed it in an app the problem for me is it has no reference point at the line ending so I don't know how can I explode it Here is the file format:
This is how data should look
and this is how I am getting data:
This is how m getting the data now
one more thing from these lines I want to pick some data to be stored how can I pick data without reference points?
I mean as you see here:
PIDF***HEMP ZONE ULTRA THIN ROLLING PAPERS 1.25" 25CT~
we have * and ~ to explode and get the data in array format but how can we pick data when the data is like that:
B84921501625VSSE ALTO MENT 463405005397BX00090500360078000
"as I want to pick the name "ALTO MENT" 4, "63405005397
how can I pick that data?
Here is what I did till now:
public function read_confirmation(){
$cpath = public_path('confirmations\pending');
$c_allfiles = scandir($cpath);
$c_allfiles = array_diff(scandir($cpath), array('.', '..'));
foreach ($c_allfiles as $fname) {
$file= File::get(public_path('confirmations\pending/'.$fname));
return $file;}
}

Laravel 5.1 translate an array pass to blade

I have this in my controller
public function editProfile(Request $request){
$question1 = Question::where('group',1)->lists('question', 'id');
$question2 = Question::where('group',2)->lists('question', 'id');
return view('user', compact(''question1', 'question2'));
}
$question = {\"1\":\"What is the first name of your best friend in high school?\",\"2\":\"What was the name of your first pet?\",\"3\":\"What was the first thing you learned to cook?\",\"4\":\"What was the first film you saw in the theater?\"}
$question2 = {\"5\":\"Where did you go the first time you flew on a plane?\",\"6\":\"What is the last name of your favorite elementary school teacher?\",\"7\":\"In What city or town does your nearest sibling live?\"}
I would like to translate the value in both question 1 and question 2 and pass it to user blade without changing the key, Any suggestions?
As specified at the localization doc, you need to populate a lang file with translation strings. So, let's say you want to show both Spanish and English strings. In this case you'd need to create two files: /resources/lang/en/messages.php and /resources/lang/es/messages.php. The content of one of those files would be somewhat like this:
<?php
// resources/lang/es/messages.php
return [
'welcome' => 'Bienvenido'
];
This way, you could access the strings in there with the following method: __('messages.welcome'), which would return the string for the language set on your config/app.php -- the default entry is en, by the way, but you can set it to whatever you want. The value in there will define which language will be chosen when selecting strings.
Another method to create translation strings is using the string itself as key, storing them in a JSON file instead of PHP. For example, the following translation string:
{
"I love programming.": "Me encanta programar."
}
would be accessible through this: __('I love programming.').
Having said that, you may solve your problem through the two methods presented above. You could store in your DB keywords for the questions instead of the whole text, and create translation for as many languages as you want. Also, you could keep the questions in your database and create translation strings for those questions. Finally, you'd need to iterate over the fetched entries and translate each one of them, or use some Collection helper to do the hard work for you, like transform or map.

Feed images 1by 1 from folder into function

I have an INPUT_IMAGE_CHECK_ALL function that takes image. In INPUT_IMAGE_CHECK_ALL there are 7 functions that image is passed to.
How do I feed images from folder 1 by 1 to the INPUT_IMAGE_CHECK_ALL function?
image = imread('6-Capmissing/capmissing-image078.jpg');
INPUT_IMAGE_CHECK_ALL(image);
INPUT_IMAGE_CHECK_ALL code:
function [ ] = INPUT_IMAGE_CHECK_ALL( image )
CHECK_FOR_CAP(image);
CHECK_FOR_NOLABEL(image);
CHECK_FOR_NOLABELPRINT(image);
CHECK_FOR_OVERFILLED(image);
CHECK_FOR_LABELNOTSTRAIGHT(image);
CHECK_FOR_UNDERFILLED(image);
end
Images that I want to feed into INPUT_IMAGE_CHECK_ALL are in folder "All" named image001 to image141.
Since you know how the name of the images you want to read (image001, image002, ... from 1 to 141) the easiest way is to use a loop in which:
build the names using the function sprintf
read the image whith the name you've build
feed your function with the image data
A possible implementation could be
for img_idx=1:141
img_name=sprintf('All/image%3.3d.jpg',img_idx)
disp(['Reading ' img_name])
the_image=imread(img_name);
INPUT_IMAGE_CHECK_ALL(the_image);
end
In the above code:
notice the format used in the call to sprintf: %3.3d: this allows padding with 0 the number in the buildoing of the filename, so that you can have 001, 002, ... 013 and so on
if the folder All in which your images are stored is not in the MatlLab path you have to specify the folder in building the filename
I've used the_image as name of the variable in which to store the data of the image because image (the varaible you are using) is a MatLab function.
the call to the disp function is used only to print on the CommandWindow a message about what the script is dooing (which image is processing); you can remove it
If the folder All only the images you you want to process, another possibility could be to get the list of images using the function dir to get the filenames of the
The function dir returns a struct in which the information about the files are stored.
In this case you have to loop over the list returned by dir
% Get the filenames of all the images in the folder "All"
img_list=dir('All/image*.jpg')
% Loops over the list of images
for img_idx=1:length(img_list)
img_name=['All/' img_list(img_idx).name]
disp(['Reading ' img_name])
the_image=imread(img_name)
INPUT_IMAGE_CHECK_ALL(the_image);
end
Hope this helps,
Qapla'

Accessing temporary file from upload in django view

Just as the title says, I want to know how to access the data from the temporary file stored by Django, when a file is uploaded, inside a view.
I want to read the data uploaded values so I can make a progress bar. My methodology is to perform a jquery getJSON request:
function update_progress_info() {
$progress.show();
$.getJSON(progress_url, function(data, status){
if (data) {
var progress = parseInt(data.uploaded) / parseInt(data.length);
var width = $progress.find('.progress-container').width()
var progress_width = width * progress;
$progress.find('.progress-bar').width(progress_width);
$progress.find('.progress-info').text('uploading ' + parseInt(progress*100) + '%');
}
window.setTimeout(update_progress_info, freq);
});
};
where progress_url is the view I have that handles the uploaded file data:
# views.py (I don't know what to do here):
def upload_progress(request):
for line in UploadedFile.temporary_file_path
response = (line)
return response
Django handles uploaded files with UploadHandler defined in settings.py with this name FILE_UPLOAD_HANDLERS that defaults to this tuple:
FILE_UPLOAD_HANDLERS =
("django.core.files.uploadhandler.MemoryFileUploadHandler",
"django.core.files.uploadhandler.TemporaryFileUploadHandler",)
The behavior with file uploads is that if the file is less than 2.5 mg then it will be kept on memory, hence, they will not be written in disk as temporary files.
If the file weights more, it will be written in chunks in the FILE_UPLOAD_TEMP_DIR in the settings.py. That's the file you'll have to query to know how many bytes have been uploaded.
You can access the uploaded/uploading files through your request variables in views like this: file = requests.FILES['file'] . There, file variable will have the type UploadedFile which contains a method temporary_file_path with the address of the file in the disk being uploaded. (Note: only files larger than 2.5 mg will have this methods) so there you may get the size of the file being uploaded.
Another way to do this is create your own UploadHandler like a ProgressBarUploadHandler and add it to your file upload handlers. This is the way the docs recommend it. Here are some snippets and tutorials for doing it.
If you need any more info the doc is really well documented.
I hope you find this helpful. Good luck.

Read image IPTC data

I'm having some trouble with reading out the IPTC data of some images, the reason why I want to do this, is because my client has all the keywords already in the IPTC data and doesn't want to re-enter them on the site.
So I created this simple script to read them out:
$size = getimagesize($image, $info);
if(isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
print '<pre>';
var_dump($iptc['2#025']);
print '</pre>';
}
This works perfectly in most cases, but it's having trouble with some images.
Notice: Undefined index: 2#025
While I can clearly see the keywords in photoshop.
Are there any decent small libraries that could read the keywords in every image? Or am I doing something wrong here?
I've seen a lot of weird IPTC problems. Could be that you have 2 APP13 segments. I noticed that, for some reasons, some JPEGs have multiple IPTC blocks. It's possibly the problem with using several photo-editing programs or some manual file manipulation.
Could be that PHP is trying to read the empty APP13 or even embedded "thumbnail metadata".
Could be also problem with segments lenght - APP13 or 8BIM have lenght marker bytes that might have wrong values.
Try HEX editor and check the file "manually".
I have found that IPTC is almost always embedded as xml using the XMP format, and is often not in the APP13 slot. You can sometimes get the IPTC info by using iptcparse($info['APP1']), but the most reliable way to get it without a third party library is to simply search through the image file from the relevant xml string (I got this from another answer, but I haven't been able to find it, otherwise I would link!):
The xml for the keywords always has the form "<dc:subject>...<rdf:Seq><rdf:li>Keyword 1</rdf:li><rdf:li>Keyword 2</rdf:li>...<rdf:li>Keyword N</rdf:li></rdf:Seq>...</dc:subject>"
So you can just get the file as a string using file_get_contents(get_attached_file($attachment_id)), use strpos() to find each opening (<rdf:li>) and closing (</rdf:li>) XML tag, and grab the keyword between them using substr().
The following snippet works for all jpegs I have tested it on. It will fill the array $keys with IPTC tags taken from an image on wordpress with id $attachment_id:
$content = file_get_contents(get_attached_file($attachment_id));
// Look for xmp data: xml tag "dc:subject" is where keywords are stored
$xmp_data_start = strpos($content, '<dc:subject>') + 12;
// Only proceed if able to find dc:subject tag
if ($xmp_data_start != FALSE) {
$xmp_data_end = strpos($content, '</dc:subject>');
$xmp_data_length = $xmp_data_end - $xmp_data_start;
$xmp_data = substr($content, $xmp_data_start, $xmp_data_length);
// Look for tag "rdf:Seq" where individual keywords are listed
$key_data_start = strpos($xmp_data, '<rdf:Seq>') + 9;
// Only proceed if able to find rdf:Seq tag
if ($key_data_start != FALSE) {
$key_data_end = strpos($xmp_data, '</rdf:Seq>');
$key_data_length = $key_data_end - $key_data_start;
$key_data = substr($xmp_data, $key_data_start, $key_data_length);
// $ctr will track position of each <rdf:li> tag, starting with first
$ctr = strpos($key_data, '<rdf:li>');
// Initialize empty array to store keywords
$keys = Array();
// While loop stores each keyword and searches for next xml keyword tag
while($ctr != FALSE && $ctr < $key_data_length) {
// Skip past the tag to get the keyword itself
$key_begin = $ctr + 8;
// Keyword ends where closing tag begins
$key_end = strpos($key_data, '</rdf:li>', $key_begin);
// Make sure keyword has a closing tag
if ($key_end == FALSE) break;
// Make sure keyword is not too long (not sure what WP can handle)
$key_length = $key_end - $key_begin;
$key_length = (100 < $key_length ? 100 : $key_length);
// Add keyword to keyword array
array_push($keys, substr($key_data, $key_begin, $key_length));
// Find next keyword open tag
$ctr = strpos($key_data, '<rdf:li>', $key_end);
}
}
}
I have this implemented in a plugin to put IPTC keywords into WP's "Description" field, which you can find here.
ExifTool is very robust if you can shell out to that (from PHP it looks like?)

Resources