<?php
require_once('tcpdf/tcpdf.php');
require_once('phpqrcode/qrlib.php');

class PDFGenerator extends TCPDF {
private $templateData;

public function __construct($templateData) {
parent::__construct(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$this->templateData = $templateData;
}

public function generatePDF() {
// PDF döküman ayarları
$this->SetCreator('Your Company');
$this->SetAuthor('System');
$this->SetTitle('Generated Document');

// Sayfa ayarları
$this->AddPage();
$this->SetFont('dejavusans', '', 10);

// Şablon verilerini yerleştir
$this->placeTemplateData();

// QR kod oluştur ve yerleştir
$this->generateAndPlaceQRCode();

// PDF'i kaydet
return $this->Output('generated_document.pdf', 'S');
}

private function placeTemplateData() {
// Başlık
$this->SetFont('dejavusans', 'B', 16);
$this->Cell(0, 10, $this->templateData['title'], 0, 1, 'C');

// İçerik alanları
$this->SetFont('dejavusans', '', 10);
$y = 50;

foreach ($this->templateData['fields'] as $label => $value) {
$this->SetXY(20, $y);
$this->Cell(50, 10, $label . ':', 0);
$this->SetXY(70, $y);
$this->Cell(0, 10, $value, 0);
$y += 10;
}
}

private function generateAndPlaceQRCode() {
// QR kod için benzersiz tanımlayıcı oluştur
$documentId = uniqid();
$qrData = "https://yourcompany.com/verify/" . $documentId;

// Geçici QR kod dosyası oluştur
$tempDir = sys_get_temp_dir();
$qrFile = $tempDir . '/qr_' . $documentId . '.png';
QRcode:ng($qrData, $qrFile, QR_ECLEVEL_L, 3);

// QR kodu PDF'e yerleştir
$this->Image($qrFile, 160, 20, 30);

// Geçici dosyayı sil
unlink($qrFile);
}
}

// Kullanım örneği
function createDocumentFromData($data) {
// Veritabanından veri çekme örneği
$db = new PDO("mysql:host=localhost;dbname=your_database", "username", "password");
$stmt = $db->prepare("SELECT * FROM documents WHERE id = ?");
$stmt->execute([$data['id']]);
$documentData = $stmt->fetch(PDO::FETCH_ASSOC);

// Şablon verilerini hazırla
$templateData = [
'title' => 'Belge Başlığı',
'fields' => [
'Ad Soyad' => $documentData['full_name'],
'TC Kimlik No' => $documentData['identity_number'],
'Belge No' => $documentData['document_number'],
'Düzenleme Tarihi' => $documentData['issue_date'],
// Diğer alanlar...
]
];

// PDF oluştur
$pdfGenerator = new PDFGenerator($templateData);
$pdfContent = $pdfGenerator->generatePDF();

return $pdfContent;
}

// API endpoint örneği
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requestData = json_decode(file_get_contents('php://input'), true);
$pdfContent = createDocumentFromData($requestData);

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="document.pdf"');
echo $pdfContent;
}
?>

Size PHP ile otomatik PDF oluşturma sistemi için bir çözüm sunacağım. TCPDF kütüphanesi kullanarak PDF oluşturacağız ve QR kod için de PHP QR Code kütüphanesinden yararlanacağız.



```php
<?php
require_once('tcpdf/tcpdf.php');
require_once('phpqrcode/qrlib.php');

class PDFGenerator extends TCPDF {
private $templateData;

public function __construct($templateData) {
parent::__construct(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$this->templateData = $templateData;
}

public function generatePDF() {
// PDF döküman ayarları
$this->SetCreator('Your Company');
$this->SetAuthor('System');
$this->SetTitle('Generated Document');

// Sayfa ayarları
$this->AddPage();
$this->SetFont('dejavusans', '', 10);

// Şablon verilerini yerleştir
$this->placeTemplateData();

// QR kod oluştur ve yerleştir
$this->generateAndPlaceQRCode();

// PDF'i kaydet
return $this->Output('generated_document.pdf', 'S');
}

private function placeTemplateData() {
// Başlık
$this->SetFont('dejavusans', 'B', 16);
$this->Cell(0, 10, $this->templateData['title'], 0, 1, 'C');

// İçerik alanları
$this->SetFont('dejavusans', '', 10);
$y = 50;

foreach ($this->templateData['fields'] as $label => $value) {
$this->SetXY(20, $y);
$this->Cell(50, 10, $label . ':', 0);
$this->SetXY(70, $y);
$this->Cell(0, 10, $value, 0);
$y += 10;
}
}

private function generateAndPlaceQRCode() {
// QR kod için benzersiz tanımlayıcı oluştur
$documentId = uniqid();
$qrData = "https://yourcompany.com/verify/" . $documentId;

// Geçici QR kod dosyası oluştur
$tempDir = sys_get_temp_dir();
$qrFile = $tempDir . '/qr_' . $documentId . '.png';
QRcode:ng($qrData, $qrFile, QR_ECLEVEL_L, 3);

// QR kodu PDF'e yerleştir
$this->Image($qrFile, 160, 20, 30);

// Geçici dosyayı sil
unlink($qrFile);
}
}

// Kullanım örneği
function createDocumentFromData($data) {
// Veritabanından veri çekme örneği
$db = new PDO("mysql:host=localhost;dbname=your_database", "username", "password");
$stmt = $db->prepare("SELECT * FROM documents WHERE id = ?");
$stmt->execute([$data['id']]);
$documentData = $stmt->fetch(PDO::FETCH_ASSOC);

// Şablon verilerini hazırla
$templateData = [
'title' => 'Belge Başlığı',
'fields' => [
'Ad Soyad' => $documentData['full_name'],
'TC Kimlik No' => $documentData['identity_number'],
'Belge No' => $documentData['document_number'],
'Düzenleme Tarihi' => $documentData['issue_date'],
// Diğer alanlar...
]
];

// PDF oluştur
$pdfGenerator = new PDFGenerator($templateData);
$pdfContent = $pdfGenerator->generatePDF();

return $pdfContent;
}

// API endpoint örneği
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requestData = json_decode(file_get_contents('php://input'), true);
$pdfContent = createDocumentFromData($requestData);

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="document.pdf"');
echo $pdfContent;
}
?>

```

Bu sistem şunları yapabilir:

1. Veritabanından veri çeker
2. Önceden tanımlanmış bir şablona göre PDF oluşturur
3. Her belge için benzersiz QR kod üretir
4. Türkçe karakter desteği için dejavusans fontu kullanır
5. Belgeleri dinamik olarak oluşturur ve indirilmesini sağlar

Sistemi kullanmak için:

1. TCPDF ve PHP QR Code kütüphanelerini kurmanız gerekiyor:
```bash
composer require tecnickcom/tcpdf
composer require phpqrcode/phpqrcode
```

2. Veritabanı bağlantı bilgilerinizi güncellemelisiniz
3. Şablon verilerini (`templateData`) kendi ihtiyaçlarınıza göre düzenleyebilirsiniz
4. QR kod URL'sini kendi doğrulama sisteminize göre ayarlayabilirsiniz

İsterseniz şu özelliklerle sistemi geliştirebilirim:
- Çoklu sayfa desteği
- Farklı şablon tipleri
- Özel font desteği
- PDF şifreleme
- Farklı veri kaynakları desteği

Claude ai ile yazıldı
Düzenleyip kullanabilirsiniz