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

padding support for android #313

Open
thiagomachado1998 opened this issue May 17, 2024 · 2 comments
Open

padding support for android #313

thiagomachado1998 opened this issue May 17, 2024 · 2 comments

Comments

@thiagomachado1998
Copy link

i need each page of my pdf to have a padding top and padding bottom, but this feature is exclusive to ios, is there any alternative or change to the source code to change this?

@thiagomachado1998
Copy link
Author

thiagomachado1998 commented May 22, 2024

I managed to solve this lack of padding support for android in the following way :

access the following library folder : node_modules / react-native-html-to-pdf / android/src/java / android / pdfConverterJava
search for this class below and configure the values according to your wishes :

 private PrintAttributes getDefaultPrintAttrs() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return null;

        return new PrintAttributes.Builder()
                .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                .setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
                .setMinMargins(new PrintAttributes.Margins(
                    30, // padding Left
                    60, // padding top
                    30, // padding rigth
                    60  // padding bottom
                ))
                .build();
    }

then go to another folder with directory : node_modules / react-native-html-to-pdf / android / src / java / android / com / reactNativePDFmoduleJava
look for this class below and replicate it the same way you customized the first class above:

 PrintAttributes pagesize=null;
      if(options.hasKey(HEIGHT) && options.hasKey(WIDTH)) {
        pagesize=new PrintAttributes.Builder()
                .setMediaSize(PrintAttributes.MediaSize.ISO_A4) 
                .setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
                .setMinMargins(new PrintAttributes.Margins(
                  30, // padding left
                  60, // padding top
                  30, // padding rigth
                  60   // padding bottom
          ))
                .build();
      }

your pdf will be generated with padding on each page

@ThangNV1205
Copy link

or you can add css style for html content to padding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants