VJ Vélan Solutions
VJ Vélan Solutions

Reputation: 6564

Generate pdf of a custom view using iTextPDF in Android

I have created a custom view (basically a chart). I instantiate the custom view in a layout file like this:

<com.package.customView android:visibility="visible" android:layout_width="match_parent" android:layout_height="wrap_content" other attributes .../>

I am able to see my view on a screen. Not a problem. I am able to dump this CustomView into a pdf via iTextView. Not a problem as well.

But if i set the visibility to gone, then i am unable to dump this CustomView into a pdf even when all steps remain the same as before. I want to be able to export a CustomView that's not visible on the screen. Is that possible? I tried setting visibility to invisible and it seems to work but then it takes up space (which appears blank on screen). So, ideally i would like it to be "gone" and still have my pdf report to be generated without a problem.

On a general note, i would really ideally want to instantiate the CustomView programatically like this (and not depend on a layout xml file per se)

CustomView myView = new CustomView(app_context_here, view_attrs_here);

and then set layout params on it and export it to pdf.

Is there a way to achieve what i want? Any pointers are greatly appreciated.

Thanks and Best Regards.

Upvotes: 1

Views: 400

Answers (1)

Ri d
Ri d

Reputation: 21

use FrameLayout as parent of your customview and other views that you want to display on screen, and make customview invisible. so that it wont take up space..

Upvotes: 2

Related Questions