Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working after updating view problematically #4

Closed
gaurav844 opened this issue Oct 12, 2020 · 3 comments
Closed

Not working after updating view problematically #4

gaurav844 opened this issue Oct 12, 2020 · 3 comments
Labels
good first issue Good for newcomers not-generated-further Not generated in newer versions

Comments

@gaurav844
Copy link

only static view is printing

@Gkemon
Copy link
Owner

Gkemon commented Oct 20, 2020

Actually, I tried to regenerate your issue but can't but I can recommend you my way to update the view programmatically before print.

Step 1: First create an inflated view object from your XML. For example -
View content = inflater.inflate(R.layout.layout_myl, null);

Step 2: Suppose, you wanna update a TextView inside the content object ( That means a TextView inside layout_my.xml)
then you make an instance of that object and update the content of that TextView. For example -
TextView textView = content.findViewById(R.id.tv_text);
textView.setText("Updated content");

Step 3: Finally follow my step, how to print pdf from java view instance . My full example is -

                View content = inflater.inflate(R.layout.layout_print, null);
                TextView textView = content.findViewById(R.id.tv_text);
                textView.setText("Updated content");

                  PdfGenerator.getBuilder()
                        .setContext(MainActivity.this)
                        .fromViewSource()
                        .fromView(content)
                        .setDefaultPageSize(PdfGenerator.PageSize.A4)
                        .setFileName("TestPDF")
                        .setFolderName("Test-PDF-folder")
                        .openPDFafterGeneration(true)
                        .build() 

If you found any problem with this approach then knock me. Thank you.

@Gkemon Gkemon closed this as completed Oct 20, 2020
@maxx2478
Copy link

maxx2478 commented Mar 13, 2021

@Gkemon Thanks for the solution but when I'd updated an Imageview using the same way as you wrote about for other views, It didn't reflected in generated pdf. Here is my code:

View content = getLayoutInflater().inflate(R.layout.id_card_print, null);
 TextView textView = content.findViewById(R.id.name);
 TextView textView2 = content.findViewById(R.id.designation);
 TextView textView3 = content.findViewById(R.id.phonenumber);
 ImageView profile = content.findViewById(R.id.profile);


if (sessionManager.getUserDetails()!=null)
{
textView.setText("Name: "+sessionManager.getUserDetails().getName());
textView2.setText(Designation: "+sessionManager.getUserDetails().getDesignation());
textView3.setText("Mobile Number: "+sessionManager.getUserDetails().getMobile_number());
				
//Updating profile (imageview)
Glide.with(context).load(sessionManager.getUserDetails().getProfileImage()).
	placeholder(context.getResources().getDrawable(R.drawable.ic_user)).
	error(context.getResources().getDrawable(R.drawable.ic_user)).into(profile);

}

How can I resolve this?
Thanks for the awesome library !

@Gkemon
Copy link
Owner

Gkemon commented Apr 9, 2021

Hi @maxx2478,You are welcome. If you face any trouble to print docs then you can see my example of How to print an Invoice or Report?

@Gkemon Gkemon added documentation Improvements or additions to documentation good first issue Good for newcomers not-generated-further Not generated in newer versions and removed documentation Improvements or additions to documentation labels Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers not-generated-further Not generated in newer versions
Projects
None yet
Development

No branches or pull requests

3 participants