Meine Frage ist zweifach.iTextg (für Android) wird Tabelle nicht wiedergeben und Schriftarteinstellungen ignorieren
Erstens, wenn ich ein Absatzobjekt erstellen, fügen Sie Text und ein benutzerdefiniertes Schriftobjekt hinzu, das Schriftobjekt wird vollständig ignoriert und hatte keine Auswirkungen auf den Text.
Zweitens, wenn ich eine PdfTable erstellen, fügen Sie eine einzelne Zeile nur zum Testen, es wird überhaupt nicht gerendert.
Übrigens, 90% dieses Codes stammt aus Tutorials von und here, die alle positive Rückmeldungen hatten. Dies ist der komplette Code:
PdfPTable table;
private void createPdf() throws FileNotFoundException, DocumentException {
Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
Font titleFont = new Font(Font.FontFamily.TIMES_ROMAN, 25, Font.BOLD, new BaseColor(0, 0, 0));
Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12);
File pdfFolder = new File(Environment.getExternalStorageDirectory()+ "/pdfdemo");
if (!pdfFolder.exists()) {
pdfFolder.mkdirs();
//Log.i(LOG_TAG, "Pdf Directory created");
}
//Create time stamp
Date date = new Date() ;
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date);
myFile = new File(pdfFolder, "testPDF.pdf");
OutputStream output = new FileOutputStream(myFile);
//Step 1
Document document = new Document();
document.setPageSize(PageSize.LETTER);
//Step 2
PdfWriter.getInstance(document, output);
//Step 3
document.open();
Paragraph top = new Paragraph("Quotation");
top.setAlignment(Element.ALIGN_CENTER);
top.setFont(titleFont);//completely ignored
document.add(top);
Chunk glue = new Chunk(new VerticalPositionMark());
Paragraph p = new Paragraph("Text to the left");
p.add(new Chunk(glue));
p.add("Text to the right");
document.add(p);
//specify column widths
float[] columnWidths = {1.5f, 6f, 2f, 2f, 2f, 2f};
//create PDF table with the given widths
table = new PdfPTable(columnWidths);
// set table width a percentage of the page width
table.setWidthPercentage(90f);
insertCell("Item No.", Element.ALIGN_CENTER, 1, bfBold12);
insertCell("Description", Element.ALIGN_CENTER, 1, bfBold12);
insertCell("Qty", Element.ALIGN_CENTER, 1, bfBold12);
insertCell("Discount(%)", Element.ALIGN_CENTER, 1, bfBold12);
insertCell("Unit Price", Element.ALIGN_CENTER, 1, bfBold12);
insertCell("Line Total", Element.ALIGN_CENTER, 1, bfBold12);
table.setHeaderRows(1);
document.add(table);
document.close();
}
private void insertCell(String text, int align, int colspan, Font font){
//create a new cell with the specified Text and Font
PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
//set the cell alignment
cell.setHorizontalAlignment(align);
//set the cell column span in case you want to merge two or more cells
cell.setColspan(colspan);
//in case there is no text and you wan to create an empty row
if(text.trim().equalsIgnoreCase("")){
cell.setMinimumHeight(10f);
}
//add the call to the table
table.addCell(cell);
}
Was ist falsch mit der offiziellen Dokumentation auf http://developers.itextpdf.com? Warum bevorzugen Sie die Dokumentation von Drittanbietern? Bitte antworten Sie, denn ich bin der Autor der meisten offiziellen Dokumente und möchte wissen, was ich falsch gemacht habe, die vielen Stunden, Tage, Wochen und Monate, an denen ich Dokumentation geschrieben habe. –
Ich entschuldige mich, mein Herr, ich suchte nach einem Beispiel speziell für Android (iTextG), nicht nur für Java, und für den anderen Link, wo ich Ihre * geniale * Bibliothek entdeckt habe. Erst nach der Implementierung (und der offiziellen Dokumentation für etwas anderes) habe ich festgestellt, wie austauschbar die Samples waren (zwischen iTextG und iText 5/7). Es wäre jedoch schön, plattformspezifische Beispiele auf Ihrer Website zu finden – BiGGZ