Hello,
i´m doing a wrap for the android.graphics.pdf.PdfDocument
Each Document is based on one or more android.graphics.pdf.PdfDocument.Page
The sample-code shown here: https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html
is just the following:
When using my wrap in b4a i now want to do similar... so i defined a document and then i started to create a Page. Then i tried to get the Canvas from the Page-object to draw on the Canvas.
But this does not work.
In b4a i got the message
pdf is the pdfDocument object.
How do i get access to the Canvas? Any hint is higly welcome
i´m doing a wrap for the android.graphics.pdf.PdfDocument
Each Document is based on one or more android.graphics.pdf.PdfDocument.Page
The sample-code shown here: https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html
is just the following:
B4X:
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create();
// start a page
Page page = document.startPage(pageInfo);
// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());
// close the document
document.close();
When using my wrap in b4a i now want to do similar... so i defined a document and then i started to create a Page. Then i tried to get the Canvas from the Page-object to draw on the Canvas.
But this does not work.
B4X:
public Canvas getCanvas() {
return getObject().getCanvas();
}
In b4a i got the message
java.lang.ClassCastException: android.graphics.pdf.PdfDocument$PdfCanvas cannot be cast to anywheresoftware.b4a.objects.drawable.CanvasWrapper
B4X:
pdf.Initialize("")
Dim info As PageInfo
Dim r As Rect
r.Initialize(50,50,450,780) ' Not sure about this values. Just a test
info.Initialize(595dip,842dip,1,r) ' same about the values here
Dim p As Page = pdf.startPage(info) ' startpage(info) returns a new Page object
Dim c As Canvas = p.Canvas
How do i get access to the Canvas? Any hint is higly welcome