Printing a chart into PDF on Android


#1

Hi

I am printing views inflated from a layout-file into a PDF-Document by using the PrintedPDFDocument-API. This works with all kinds of views so far, including the ChartViews except one thing: The series I have added are not shown. I heard this could be caused by OpenGL, but I have no idea to fix this.

// Invoked to create an configure the view of the desired page
View view = p.createView(this.data, width, height);
pageBuilder = new PdfDocument.PageInfo.Builder(width, height, i);
page = document.startPage(pageBuilder.create());
view.draw(page.getCanvas());
document.finishPage(page);

Has anybody an idea how to get the series printed?


#2

Hi Moony,

This isn’t something that we have tried ourselves but I think that you are right and it is probably something to do with rendering the series in OpenGL. You may be able to use our screenshot capabilities to capture your chart as a bitmap and then draw that to your PDF canvas. To handle requested snapshots you will need to implement our OnSnapshotDoneListener (http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiChartsAndroid/1.7.1/Premium/Normal/apidocs/docs/reference/com/shinobicontrols/charts/ShinobiChart.OnSnapshotDoneListener.html)  which will provide a bitmap of your chart.

I hope this gives you some ideas for moving forward and if you have any other questions then feel free to ask.

Joel


#3

Has there been any update to this? Moony, did you end up using the snapshot feature instead?

I’m running into the exact same issue and would like to be able to directly draw a chart to a PDF canvas.


#4

A bug of the Android PDF-API forced us to switch to a different PDF-API. However creating a screenshot and print it to the PDF should do the job. For all i know we use this feature in the iOS-Version of our app.

The difficulty is to render the charts in the background, out of the user’s view. Unfortunately i do not know the exact procedure.

Finally I could solve the problem, by developing a small, simple diagram-framework on my own, that uses the primitive drawing-functions of the respective PDF-framework. Since there is no need of any user-interaction, like zooming and swiping, and no dynamic behaviour is required, this can be done easily.

Hope this answer helps You to find a solution smiley wink


#5

Hi Idsather.

I’d just like to advise that our snapshot api method (link in Joel’s post above) is still our recommended way of capturing a snapshot of a shinobichart. We have not tried to use shinobi with any specific Android pdf api, but we certainly think that it is feasible to capture a snapshot of a chart as a bitmap and then draw it to a pdf canvas. One noteworthy point is on the subject of capturing off-screen snapshots. Our snapshots api was never designed for this purpose and as such I do not believe it is possible. We certainly have not tried it. I beleive the way Android and open GL interact, the GL will not draw if the View in which it resides is not visible.

I hope that this helps,

Thanks, Kai.


#6

Thanks for the repsonses. I did end up getting the snap shots working with the Android pdf API. Thankfully all of the charts that I need are in view when I need to make the PDF. Just had to loop through the callbacks of each chart snapshot. 

Thanks,

Louis