require_once 'Zend/Pdf.php';
$pdf = new Zend_Pdf();
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10);
$page->drawText("Bogus Russian: это фигня", 100, 400, "UTF-8");
$pdfData = $pdf->render();
header("Content-Disposition: inline; filename=output.pdf");
header("Content-type: application/x-pdf");
echo $pdfData;
I can't get the Russian characters to show up! I've managed to get them to show up as:
Russian: ???????????
Russian: ÐоммÑнÐ
Russian:
and
Russian: ><
This post explains it better:
How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework
Essentially the built-in fonts (eg. Zend_Pdf_Font::FONT_HELVETICA) don't contain enough info, so you need to attach a font ttf file with the pdf, and set your script to use that font.
$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times.ttf');
$pdfPage->setFont($font, 36);
Perhaps this will answer your question:
How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework
By the looks of it the default fonts do not have all the utf-8 characters...you may have to load external TTF...
Related
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.
I have some text files that contain either OK or FAIL written to a storage account. If I download the files to disk, the contents display as expected in notepad,
However, if I get the file contents to a variable and Write-Host that, I get �O K
I am doing this:
$storageContext = New-AzureStorageContext $storageAccountName $storageAccountKey
$storageContainer = "monitor"
$storageBlobs = Get-AzureStorageBlob -Container $storageContainer -Context $storageContext
foreach($storageBlob in $storageBlobs) {
$blobContents = $storageBlob.ICloudBlob.DownloadText()
$blobName = $storageBlob.Name
Write-Host $blobName
Write-Host $blobContents
Write-Host
}
I thought that maybe I could tell it to use UTF8 like this:
$encoding = [System.text.Encoding]::UTF8
foreach($storageBlob in $storageBlobs) {
$blobContents = $storageBlob.ICloudBlob.DownloadText($encoding)
$blobName = $storageBlob.Name
Write-Host $blobName
Write-Host $blobContents
Write-Host
}
However, that doesn't work.
I'm now trying getting it as a ByteArray with .DownloadToByteArray but my first attempt is throwing errors.
Why are there extra characters and spaces when retrieved via Powershell but not when viewed in notepad. Am I correct in thinking this is a simple encoding issue?
Yes, it is an encoding issue. If the file is encoding with UTF8, you should use UTF8 to decode it. If it's encoding with unicode, you should use unicode to decode it.
Then in your case, I think it's using unicode. You should use Unicode to decode it, like $encoding = [System.text.Encoding]::Unicode.
I can reproduce your issue, and test it with encoding UTF8(not work), but works with Unicode.
UTF8:
Unicode:
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 trying to insert Arabic text into a pdf using pdfbox
File myFile = new File("src/arabic/arial.ttf");
PDFont font = PDType0Font.load(doc, myFile);
PDPageContentStream contentStream = new PDPageContentStream(doc, page,true,true);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(30, 40);
String arabicText = "عطي يونيكود رقما فريدا لكل حرف" ;
// System.setProperty("ste.encoding", "UTF-8");
contentStream.showText(arabicText);
contentStream.endText();
contentStream.close();
The Arabic text appears as disconnected text in the resultant pdf.
(This applies for PDFBox 2.0, not for earlier versions)
You have to do this yourself. I can't explain it for Arabic, but for "western" glyphs:
stream.showText("film \uFB01lm");
Create a PDF with that one, then try to mark the "f" or the "l" in the second word - you can't, because it is one entity.
The first word has "f" and "i" as separate characters, the second one has the latin small ligature fi (U+FB01). So you'd have to do some preprocessing yourself to replace such combinations when your font supports them. Good luck!
When I tried to use the code to convert the file format files to PDF using itextsharp. The problem appears when converting texts written in Arabic. The result came without the written text in Arabic.
I hope you to help me overcome the problems.
Thank you very much
Here's a summary of the process:
Wrap Paragraph objects in one of the two iText IElement classes that support Arabic text: PdfPCell and ColumnText.
Use a font that has Arabic glyphs.
Set the text run direction and alignment.
Something like this:
using (Document document = new Document()) {
PdfWriter writer = PdfWriter.GetInstance(document, STREAM);
document.Open();
string arabicText = #"
iText ® هي المكتبة التي تسمح لك لخلق والتلاعب وثائق PDF. فإنه يتيح للمطورين تتطلع الى تعزيز شبكة الإنترنت وغيرها من التطبيقات مع دينامية الجيل ثيقة PDF و / أو تلاعب.
";
PdfPTable table = new PdfPTable(1);
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell();
cell.Border = PdfPCell.NO_BORDER;
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
Font font = new Font(BaseFont.CreateFont(
"c:/windows/fonts/arialuni.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED
));
Paragraph p = new Paragraph(arabicText, font);
p.Alignment = Element.ALIGN_LEFT;
cell.AddElement(p);
table.AddCell(cell);
document.Add(table);
}
Sorry if the example text above is poor, incorrect, or both. I had to use Google translate, since my native language is English.