Last active
August 29, 2015 14:02
-
-
Save gvsharma/540743ef1275df71be54 to your computer and use it in GitHub Desktop.
Generating pdf with qPDF(qoppa software) library(refer http://www.qoppa.com/android/pdfsdk/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void dataIntoPdf(int noOfLines, ArrayList<Info> bookInfosById, PDFCanvas canvasId){ | |
try { | |
float x = 40f; | |
float y = 60f; | |
for (int j = 0; j < bookInfosById.size();j++) { | |
int z = j; | |
Info myInfos = bookInfosById.get(j); | |
if (z < noOfLines) { | |
for (int v = 0; v <= z; v++) { | |
if (z == v) { | |
canvasId.drawText(localBookInfos.getSNo(), Color.BLACK, 10, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getId(), Color.BLACK, 60, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getdate(), Color.BLACK, 110, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.gettime(), Color.BLACK, 180, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getLocalDate(), Color.BLACK, 240, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getLocalTime(), Color.BLACK, 300, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getCity(), Color.BLACK, 360, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getStatus(), Color.BLACK, 420, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getStartDate(), Color.BLACK, 480, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getStartTime(), Color.BLACK, 540, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getComments(), Color.BLACK, 600, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getLongitude(), Color.BLACK, 680, (z - (noOfLines - 10)) * x, font); | |
canvasId.drawText(localBookInfos.getLatitude(), Color.BLACK, 720, (z - (noOfLines - 10)) * x, font); | |
} | |
for (int k = 0; k < 13; k++) { | |
canvas.drawText(ar.get(0), Color.BLACK, 0, 20, font); | |
canvas.drawText(ar.get(1), Color.BLACK, 60, 20, font); | |
canvas.drawText(ar.get(2), Color.BLACK, 110 , 20, font); | |
canvas.drawText(ar.get(3), Color.BLACK, 180, 20, font); | |
canvas.drawText(ar.get(4), Color.BLACK, 240 , 20, font); | |
canvas.drawText(ar.get(5), Color.BLACK, 300 , 20, font); | |
canvas.drawText(ar.get(6), Color.BLACK, 360, 20, font); | |
canvas.drawText(ar.get(7), Color.BLACK, 420, 20, font); | |
canvas.drawText(ar.get(8), Color.BLACK, 480, 20, font); | |
canvas.drawText(ar.get(9), Color.BLACK, 540, 20, font); | |
canvas.drawText(ar.get(10), Color.BLACK, 600, 20, font); | |
canvas.drawText(ar.get(11), Color.BLACK, 660, 20, font); | |
canvas.drawText(ar.get(12), Color.BLACK, 730, 20, font); | |
} | |
} | |
} | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intro: We can observe sample provided on offical web and i've done some R & D on it and i've generated PDF using it . The date is in bookInfosId that am getting from local database. | |
private void createPdfDoc(ArrayList<Info> bookInfosById) { | |
try { | |
ar = new ArrayList<String>(); | |
ar.add("SNo"); | |
ar.add("Id"); | |
ar.add("Date"); | |
ar.add("Time"); | |
ar.add("LocalDate"); | |
ar.add("LocalTime"); | |
ar.add("City"); | |
ar.add("Status"); | |
ar.add("StartTime"); | |
ar.add("EndTime"); | |
ar.add("Comments"); | |
ar.add("Longitude"); | |
ar.add("Latitude"); | |
StandardFontTF.mAssetMgr = getAssets(); | |
PDFDocument pdf = new PDFDocument(); | |
PDFFontStandard font = new PDFFontStandard(PDFFontFamily.HELVETICA,PDFFontStandard.Style.NORMAL, 10); | |
int noOfPages = bookInfosById.size() / 10; | |
PDFPaint paint = new PDFPaint(); | |
paint.setStyle(PDFPaint.Style.STROKE); | |
paint.setStrokeWidth(0.2f); | |
paint.setStrokeColor(Color.BLACK); | |
for (int i = 0; i <= noOfPages; i++) { | |
int var = 10; | |
int rep = i; | |
if (i == 0) { | |
PDFPage page = pdf.appendNewPage(800, 400); | |
canvas = page.createCanvas(); | |
dataIntoPdf(var + ((i) * var), bookInfosById, canvas); | |
}else if (rep == i) { | |
PDFPage page2 = pdf.insertNewPage(800, 400, i+1); | |
PDFCanvas canvas2 = page2.createCanvas(); | |
dataIntoPdf(var + ((i) * var), bookInfosById, canvas2); | |
} | |
} | |
pdf.saveDocument(localLOGBOOKPdfFile); | |
System.out.println("local LOGBOOK"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
here i am generating 13 columns in one page. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment