Error generating PDF417 with TCPDF using 13 digits - php

well, I have a very strange problem generating 2D-Barcodes (PDF417) with PHP using TCPDF (TCPDF-Website). This is my small code:
<?php
require_once ("tcpdf/tcpdf_barcodes_2d.php");
$type = "PDF417";
$code="123456789012";
$barcodeobj = new TCPDF2DBarcode($code, $type);
$barcodeobj->getBarcodePNG();
?>
This code works well and generates the barcode. But when I change the line with the code in
$code="1234567890123";
it does not generate any output. I tried several strings and found out, that everytime I try to use a string with more than 12 digits following one after the other I get no output. It does not depend on which position the digits were.
For example:
$code="abcdefghijklmnopqrstuvwxyz123456789012abcdefghijklmnopqrstuvwxyz";
works finde, but
$code="abcdefghijklmnopqrstuvwxyz1234567890123abcdefghijklmnopqrstuvwxyz";
fails.
I use tcpdf 6.0.037 and also tried to download it from annother source. I even tried Version 6.0.020 - no change.
Server is openSuSE 12.2 64bit , PHP 5.3.15
Edit:
It's getting really strange: I tried annother barcode generator - and I get the same error. This one provides a online demo. When I fill in 1234567890123 online, I get the appropreate barcode. But on my own server the same string does not work.
"123456-7890123" works
"1234567890123" does not work
"123456789012" works
"12e34567890123" works
"123456789012sometext123456789012" works
"123456789012sometext1234567890123" does not work
Every string with more than 12 numbers in a row does not work - no matter how long the string is.
U see what I mean with "strange" ?
Any help would be highly appreciated.

I too had this problem. We are using PDF417 & QR Code barcodes. I have not found a great solution for this, but I have found a solution that works for now. If anyone has a better solution, please advise.
Problem:
In our barcodes we have phone numbers that are stored and sometimes they are 13 digits or longer. The 13 digit phone number was causing the barcode to not print correctly.
Solution:
Since the barcode would not print due to this we just add a space every 10 digits and this keeps the barcode intact and our software can read in the phone number without spaces so we should be A-OK!
Example Phone Number:
123456789012345 (15 digits)
PHP Code to run on phone number:
$phone = chunk_split($phone, 10, ' ');
Example Phone Number after split:
1234567890 12345
The libraries for these barcodes (Google/TCPDF) don't like numbers longer than 12 so it's definitely strange, but maybe I"m missing something easy to see.
Thanks and hope this helps someone.

Related

Is it possible to read a certain number of characters after a certain number of digits from the start of the file

I'm setting up a web app, where users can choose the starting point and the number of characters to read from a text file containing 1 billion digits of pi.
I have looked, but I can't find any similar problems. Because I don't know what the starting digit is, I can't use other solutions.
Here is the function written in Python:
def pi(left : int, right : int):
f.seek(left+1)
return f.read(right)
For example, entering 700 as the starting point and 9 as the number of characters should return "Pi(700,9): 542019956".
Use fseek to move the file pointer to the position you need, and fread to read the amount of characters you need - just like your Python sample code.
Actually, this capability is built in to file_get_contents.
$substr = file_get_contents('pi_file.txt', false, null, 700, 9);
A handy feature of that function that I learned about just now after using it for the past 7 years.

PHPSpreadsheet generates an error "Wrong number of arguments for INDEX() function: 5 given, between 1 and 4 expected"

I tried to enter the following code in my excel formula bar directly
=INDEX($E$4:$E$132,AGGREGATE(15,6,ROW($1:$30) / ($J$4:$J$132=M4), COUNTIF($M$4:M4, M4))) and works perfectly fine (the left column on the pic below).
But if I'm using my web application to generate an excel report file (PHP, using CodeIgniter and Laravel). It displays an error "'Wrong number of arguments for INDEX() function: 5 given, between 1 and 4 expected'"
Here's my sample code snippet:
$code = "=INDEX(\$E\$4:\$E\$$occurance, AGGREGATE(15,6,ROW(\$1:\$$occurance) / (\$J\$4:\$J\$$occurance=M$top_cell), COUNTIF(\$M\$4:M$top_cell, M$top_cell)))";
$ews2->setCellValue("L$top_cell", $code);
I also have tried to use the setValueExplicit method but causes the excel file to NOT precalculate the code, it reads the code as a string
$ews2->setCellValueExplicit("L$top_cell", $code, DataType::TYPE_STRING);
NOTE TYPE_STRING is provided because if TYPE_FORMULA is also used, the same output mentioned at the top occurs
Here's what it looks like using the setCellValueExplicit
May I know the right solution or quick fix for this? Thank you very much in advance!
I have found out that the PHPSpreadsheet library for PHP is yet to allow the usage of the AGGREGATE() and complicated formulas/functions, so I had found another way around
By using this excel code
=INDEX(E$2:E$38,IF(M4=M3,MATCH(L3,E$2:E$38,0),0)+MATCH(M4,OFFSET(J$2,IF(M4=M3,MATCH(L3,E$2:E$38,0),0),0,COUNT(J$2:J$38)-IF(M4=M3,MATCH(L3,E$2:E$38,0),0),1),0))
I was able to traverse through my entire range and make sure that no duplicate publication names would appear
This is in relation with the my other question -> Excel - Getting the 2nd or nth matched string from your corresponding data

Getting different output for same PHP code

(Can't paste the exact question as the contest is over and I am unable to access the question. Sorry.)
Hello, recently I took part in a programming contest (PHP). I tested the code on my PC and got the desired output but when I checked my code on the contest website and ideone, I got wrong output. This is the 2nd time the same thing has happened. Same PHP code but different output.
It is taking input from command line. The purpose is to bring substrings that contact the characters 'A','B','C','a','b','c'.
For example: Consider the string 'AaBbCc' as CLI input.
Substrings: A,a,B,b,C,c,Aa,AaB,AaBb,AaBbC,AaBbCc,aB,aBb,aBbC,aBbCc,Bb,BbC,BbCc,bC,bCc,Cc.
Total substrings: 21 which is the correct output.
My machine:
Windows 7 64 Bit
PHP 5.3.13 (Wamp Server)
Following is the code:
<?php
$stdin = fopen('php://stdin', 'r');
while(true) {
$t = fread($stdin,3);
$t = trim($t);
$t = (int)$t;
while($t--) {
$sLen=0;
$subStringsNum=0;
$searchString="";
$searchString = fread($stdin,20);
$sLen=strlen($searchString);
$sLen=strlen(trim($searchString));
for($i=0;$i<$sLen;$i++) {
for($j=$i;$j<$sLen;$j++) {
if(preg_match("/^[A-C]+$/i",substr($searchString,$i,$sLen-$j))) {$subStringsNum++;}
}
}
echo $subStringsNum."\n";
}
die;
}
?>
Input:
2
AaBbCc
XxYyZz
Correct Output (My PC):
21
0
Ideone/Contest Website Output:
20
0
You have to keep in mind that your code is also processing the newline symbols.
On Windows systems, newline is composed by two characters, which escaped representation is \r\n.
On UNIX systems including Linux, only \n is used, and on MAC they use \r instead.
Since you are relying on the standard output, it will be susceptible to those architecture differences, and even if it was a file you are enforcing the architecture standard by using the flag "r" when creating the file handle instead of "rb", explicitly declaring you don't want to read the file in binary safe mode.
You can see in in this Ideone.com version of your code how the PHP script there will give the expected output when you enforce the newline symbols used by your home system, while in this other version using UNIX newlines it gives the "wrong" output.
I suppose you should be using fgets() to read each string separetely instead of fread() and then trim() them to remove those characters before processing.
I tried to analyse this code and that's what I know:
It seems there are no problems with input strings. If there were any it would be impossible to return result 20
I don't see any problem with loops, I usually use pre-incrementation but it shouldn't affect result at all
There are only 2 possibilities for me that cause unexpected result:
One of the loops iteration isn't executed - it could be only the last one inner loop (when $i == 5 and then $j == 5 because this loop is run just once) so it will match difference between 21 and 20.
preg_match won't match this string in one of occurrences (there are 21 checks of preg_match and one of them - possible the last one doesn't match).
If I had to choose I would go for the 1st possible cause. If I were you I would contact concepts author and ask them about version and possibility to test other codes. In this case the most important is how many times preg_match() is launched at all - 20 or 21 (using simple echo or extra counter would tell us that) and what are the strings that preg_match() checks. Only this way you can find out why this code doesn't work in my opinion.
It would be nice if you could put here any info when you find out something more.
PS. Of course I also get result 21 so it's hard to say what could be wrong

Rename filenames

I use Uploadifive to upload big files. That's working fine, except for Firefox on Android.
When selecting an uploadfile from Google Drive, that file is first downloaded to the tablet and then uploaded using uploadifive.
But Firefox is renaming this filename; and puts in tmp_ before and some numbers behind the filename.
So, if test-1.mp3 is my filename; i get tmp_20950-test-1-5487457458.mp3.
I don't think i can overcome the renaming done by Firefox.
But i can rename it via the script.
So far i can remove the 'tmp_', but not the numbers.
There could be 4 or 5 numbers in the start, or 8 or 10 numbers in the end.
if (preg_match('/tmp_/',$destination_file)){
$destination_file = str_replace('tmp_','',$destination_file);
}
So i search for commands to clear those numbers. The difficulty is not knowing how many numbers to clear. The only 'fixed' element is the stripe '-' after and before the number. Maybe can i use that in my command ? But don't know how.
You can try something like this pattern to get the filename:
/^tmp_\d+-(.*?)-\d+\.(.*?)$/
the first match will be the filename and the second the extension.
regex tester

Is there a limit on the length of command passed to exec in PHP?

Currently I need to merge that 50+ PDF files into 1 PDF. I am using PDFTK. Using the guide from: http://www.johnboy.com/blog/merge-multiple-pdf-files-with-php
But it is not working. I have verified the following:
I have tried the command to merge 2 pdfs from my PHP and it is working.
I have echo the final command and copied that command and paste into command prompt and run manually and all the 50 PDFs are successfully merged.
Thus exec in my PHP and the command to merge 50 PDFs are both correct but it is not working when done together in PHP. I have also stated set_time_limit(0) to prevent any timeout but still not working.
Any idea what's wrong?
You can try to find out yourself:
print exec(str_repeat(' ', 5000) . 'whoami');
I think it's 8192, at least on my system, because it fails with strings larger than 10K, but it still works with strings shorter than 7K
I am not sure if there is a length restriction on how long a single command can be but I am pretty sure you can split it accross multiple lines with "\" just to check if thats the problem. Again I dont think it is... Is there any error output when you try to run the full command with PHP and exec, also try system() instead of exec().
PDFTK versions prior to 1.45 are limited to merge 26 files cuz use "handles"
/* Collate scanned pages sample */
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
as you can see "A" and "B" are "handles", but should be a single upper-case letter, so only A-Z can be used, if u reach that limit, maybe you script outputs an error like
Error: Handle can only be a single, upper-case letter
but in 1.45 this limitation was removed, changelog extract
You can now use multi-character input handles. Prior versions were
limited to a single character, imposing an arbitrary limitation on
the number of input PDFs when using handles. Handles still must be all
upper-case ASCII.
maybe you only need update your lib ;)

Categories