Skip to content

Instantly share code, notes, and snippets.

View mrnirva's full-sized avatar
:electron:
Coding

Harun Adıgüzel mrnirva

:electron:
Coding
View GitHub Profile
// Separator tanımlama ve renklendirme
LineSeparator lineSeparator = new LineSeparator();
lineSeparator.setLineColor(new BaseColor(0, 0, 0, 68));
// Ekleme
pdfDosyam.add(new Chunk(lineSeparator));
// 2 Sütunlu tablo oluşturma
PdfPTable tablo_1 = new PdfPTable(2);
// Hücre oluşturma kısmı
PdfPCell hucre_1 = new PdfPCell(new Paragraph(new Chunk("Satır - 1")));
PdfPCell hucre_2 = new PdfPCell(new Paragraph(new Chunk("Satır - 2")));
// Hücrelere iç boşluk verme
hucre_1.setPadding(5);
hucre_2.setPadding(5);
Chapter bolum1 = new Chapter("Bölüm", 1);
Paragraph bolum1_icerik = new Paragraph("Bölüm 1 İçerik");
bolum1.add(bolum1_icerik);
pdfDosyam.add(bolum1);
Chapter bolum2 = new Chapter("Bölüm", 2);
bolum2.add(new Paragraph("Bölüm 2 İçerik"));
pdfDosyam.add(bolum2);
List liste1 = new RomanList();
liste1.add(new ListItem("Item 1"));
liste1.add(new ListItem("Item 2"));
pdfDosyam.add(liste1);
List liste2 = new List();
liste2.add(new ListItem("İtem 1"));
liste2.add(new ListItem("İtem 2"));
try { //******************* iText Resim EKLEME *******************
// Logoyu bitmap'e çevirip stream ile baytlara ayırıp pdfe basıyoruz
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
R.drawable.home);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
// Fontu Çekip Türkçe Karakter Sorununu Atlatmak İçin Ayarladığımız Kısım
BaseFont arial = null;
try {
arial = BaseFont.createFont("assets/arial.ttf",
BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
} catch (Exception e) {
Log.e("hata","Font Çekme Hatası "+e.toString());
package com.harun.pdfolusturucu;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import com.itextpdf.text.BaseColor;
// Bu kodları MainActivity İçerisine Yazabilirsiniz
// İlgili resimleri kendi resimlerinizin adıyla değiştiriniz
ArrayList<Integer> resimId = new ArrayList<>();
resimId.add(R.drawable.harun_xyz);
resimId.add(R.drawable.harun_xyz_opacity_25);
// Context ve Resim idlerini yolluyoruz
new PDFOlusturucu().pdfOlustur(MainActivity.this,resimId);
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.util.Properties;