I am using a barcode generator php code to generate barcodes. But when I want to write barcode to an existing pdf file using fpdi+fpdf the written string is not the generated barcode! It is written obscure words. The code that I used is below:
<?php
session_start();
#----- gets serialnumber from page form ------
$serialnumber = $_SESSION['serialnumber'];
#---------------------------------------------
include 'lib/barcode/barcode128.php';
$bar_code= bar128($serialnumber);
#echo $serialnumber;
include('lib/FPDI-2.3.6/src/autoload.php');
require('lib/fpdf184/fpdf.php');
require('lib/FPDI-2.3.6/src/fpdi.php');
$pdf = new Fpdi();
#$pdf->AddPage();
$pagecount= $pdf->setSourceFile("lib/test3.pdf");
$tpl = $pdf->importPage(1);
$pdf->AddPage();
$pdf->useTemplate($tpl);
$pdf->SetFont('arial');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(0, 5);
$pdf->Write(0, $bar_code);
$pdf->Cell(20,10,$bar_code,1,1,'C');
$pdf->Output();
?>
also barcode128.php works fine no problem with that. I downloaded it from https://jinujawad.com/create-simple-barcode-using-php/
I used both write and cell but the result is the same.
Related
use ZanySoft\LaravelPDF\PDF;
$mpdf = new PDF();
$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile(storage_path() . '/app/public/applications/test.pdf');
// test.pdf have 2 pages $pagecount have value 2.
for($i=1; $i <= $pagecount ; $i++) {
$tplId = $mpdf->ImportPage($i);
$mpdf->addPage();
$mpdf->UseTemplate($tplId);
// store each page as pdf file
$new_file_name = "new-".$i.".pdf";
$mpdf->Output($new_file_name, \Mpdf\Output\Destination::FILE);
}
I am getting an error Class 'Mpdf\Output\Destination' not found. I have tried below things as second argument of Output();
$mpdf->Output($new_file_name, \PDF\Output\Destination::FILE);
$mpdf->Output($new_file_name, \Mpdf\Mpdf\Output\Destination::FILE);
But, it is not working. Please help to store fetch page store as PDF file direct on directory.
ZanySoft\LaravelPDF\PDF uses mPDF in version 6.1 which does not have output destination class constants yet.
Use a plain string:
$mpdf->Output($new_file_name, 'F');
Or use composer package mpdf/mpdf in version >=7 directly.
I'm having this PHP-script:
<?php
$old_path = getcwd();
chdir('/var/www/html/SEARCHTOOLS/');
$term1 = $_POST['query1'];
$term2 = $_POST['query2'];
$var = "{$term1} {$term2}";
$outcome = shell_exec("searcher $var");
chdir($old_path);
echo "<pre>$outcome</pre>";
?>
On a searchpage two searchwords are written and the searchbutton is pushed. The search result turns up as a webpage like this:
/var/www/html/SEARCHTOOLS/1974-1991.pdf:1
/var/www/html/SEARCHTOOLS/1974-1991.pdf:3
/var/www/html/SEARCHTOOLS/1974-1991.pdf:7
/var/www/html/SEARCHTOOLS/1974-1991.pdf:7
/var/www/html/SEARCHTOOLS/1974-1991.pdf:9
/var/www/html/SEARCHTOOLS/1974-1991.pdf:13
/var/www/html/SEARCHTOOLS/1974-1991.pdf:13
The result shows links to individual PDF-files and pagenumber in that file, but are not clickable.
Is there a way to make these links clickable so that it opens up for instance in Evince or Acrobat at the correct page number?
Many thanks in advance.
/Paul
I found a correct answer to my problem. It took some time, but here it is:
<?php
// Get current working directory and put it as variable
$old_path = getcwd();
// Change directory
chdir('/var/www/html/SEARCHTOOLS/');
// Create first variable as result of first searchword on searchpage
$term1 = $_POST['query1'];
// Create second variable as result of second searchword on searchpage
$term2 = $_POST['query2'];
// Create a variable combining first AND second variable
$var = "{$term1} {$term2}";
// Create a variable as the result of the executed search using command "sokare" and variable "$var"
$outcome = shell_exec("sokare $var");
// Return to starting directory
chdir($old_path);
// Split the varible "$outcome" per line representing every page in PDF-file where variable "$var" is found
foreach(preg_split("/((\r?\n)|(\r\n?))/", $outcome) as $line){
// Create a variable out of the given pagenumber in PDF-file
$end = substr($line, strpos($line, ":") + 1);
// Trim the line by removing leading directories from line
$line2 = str_replace('/var/www/html', '', $line);
// Change a string from lower to upper case
$line2 = str_replace('searchtools', 'SEARCHTOOLS', $line2);
// Remove the colon and anything behind it from line
$line2 = array_shift(explode(':', $line2));
// Add suffix to line to facilitate linking to pagenumber in PDF-file
$line3 = str_replace(" ", "_", $line2).'#page=';
// Add pagenumber from the variable "$end"
$line3 = str_replace(" ", "_", $line3).$end;
// Print each line as a correct URL-link
echo "<pre><a href=$line3>$line3</a></pre>";
}
?>
The search results will now turn up as (and are clickable):
/SEARCHTOOLS/1974-1991.pdf#page=1
/SEARCHTOOLS/1974-1991.pdf#page=3
/SEARCHTOOLS/1974-1991.pdf#page=7
Just a small edit. The line ....
// Add suffix to line to facilitate linking to pagenumber in PDF-file
$line3 = str_replace(" ", "_", $line2).'#page=';
...works better with:
// Add suffix to line to facilitate linking to pagenumber in PDF-file
if (substr($line2, -3) == 'pdf') {
$line3 = $line2.'#page=';
}
I have many websites that use some of the same content snippets and instead of manually updating all the different websites, I thought it would be a good idea to have the content stored in a database as to only have one copy instead of multiple. It works great except for one issue which is the images that are in the article are sometimes left aligned and other times right aligned.
My solution was to add the following code to the article's image CSS tag that is in the database and use a variable on each of the individual pages to add the custom classes to the image.
class="<?php echo $ImgClass01; ?>"
EDIT: here is more of the content from what is stored in the database field to make my question a little more understandable.
<p><img src="img/charleston.jpg" class="<?php echo $ImgClass01; ?>">Is it the delightful year-round climate? The almost-European feel of its downtown city streets? The overwhelming...</p>
However, the webpage is only showing the text when viewing the source code and not using the variable. Almost anything is possible, but I'm not sure how to make this work.
Here is the code on the page...
// value for the class within the article to be printed on the page
$ImgClass01 = 'img-responsive img-rounded pull-right';
//Start a while loop to process all the rows
while ($row = mysql_fetch_assoc ($result_set))
{
$article = $row['article'];
echo $article;
} //END WHILE
EDIT: Just in case the entire page will be helpful, here is it.
<?php
$PageTitle = "Charleston, South Carolina | Local Towns";
$PageDescription = "Charleston is rated the first most popular vacation destination in the United States, and it surely must rank in...";
// 1. Create a database connection
$link = mysql_connect ("localhost", "root", "");
if (!$link) die("Could not connect: " . mysql_error());
// 2. Select a database to use
if (!mysql_select_db ("articleBank"))
die("Problem with the database: " . mysql_error());
// 3. Set up query for items to display
$query = "SELECT article FROM `articles` WHERE ID = 1";
// 4. Execute the query
$result_set = mysql_query ($query);
include ("theme/header.php");
// value for the class within the article to be printed on the page
$ImgClass01 = 'img-responsive img-rounded pull-right';
//Start a while loop to process all the rows
while ($row = mysql_fetch_assoc ($result_set))
{
$article = $row['article'];
echo $article;
} //END WHILE
// 5. Close Connection
mysql_close();
include ("theme/footer.php");
?>
while ($row = mysql_fetch_assoc ($other_result_set))
{
$ImgClass01 = $row['ImgClass01'];
}
not sure what you wanted, but you could use left, right in some row like place..
hello
i have a simple file upload with just one extra post parameter which is imgtitle.
it's used to rename the image after it's been transferred to the upload location on the server.
PHP:
<?php
$imgtitle = $_POST['title'];
$current_image=$_FILES['file']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
$new_image = $imgtitle. "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['file']['tmp_name'], $destination);
echo "--".$imgtitle."--";
?>
the upload works fine here.
http://tnsatchat.heliohost.org/tnsatchat/upload/upload.html
/upload/uploads/abcd.jpg
what i want to do is make a simple vb.net app which would allow me to upload the file/image
i'm using WebClient to do so.
but i'm having some difficulties passing the imgtitle parameter.
here's my code
Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php?title=testname")
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")
the upload is working i.e the file is there .. but with an empty name !!
/upload/uploads/.jpg
".jpg" is supposed to be "testname.jpg" but i guess the PHP is not getting that parameter.
any hints please !
edit:
i used the QueryString property
Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php")
Dim col = New Collections.Specialized.NameValueCollection
col.Add("title", "testname")
wc.QueryString = col
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")
but with no better luck !!
I've got a strange problem connected with content rendering.
I use following code to grab the content:
lib.otherContent = CONTENT
lib.otherContent {
table = tt_content
select {
pidInList = this
orderBy = sorting
where = colPos=0
languageField = sys_language_uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.wrap = <h2>|</h2>
20 = TEXT
20.field = bodytext
20.wrap = <div class="article">|</div>
}
}
and everything works fine, except that I'd like to use also predefined column-content templates other than simple text (Text with image, Images only, Bullet list etc.).
The question is: with what I have to replace renderObj = COA and the rest between the brackets to let the TYPO3 display it properly?
Thanks,
I.
The available cObjects are more or less listed in TSRef, chapter 8.
TypoScript for rendering Text w/image can be found in typo3/sysext/css_styled_content/static/v4.3/setup.txt at line 724, and in the neighborhood you'll find e.g. bullets (below) and image (above), which is referenced in textpic line 731. Variants of this is what you'll write in your renderObj.
You will find more details in the file typo3/sysext/cms/tslib/class.tslib_content.php, where e.g. text w/image is found at or around line 897 and is called IMGTEXT (do a case-sensitive search). See also around line 403 in typo3/sysext/css_styled_content/pi1/class.cssstyledcontent_pi1.php, where the newer css-based rendering takes place.