cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
107 stars 61 forks source link

pdf document without any margins #54

Open sherifdarwish opened 6 years ago

sherifdarwish commented 6 years ago

Hi,

I am trying to control the pdf page margin as my CSS & HTML removes any margins or padding but the resulting PDF or PDF Preview always shows white margin around my content, this screen shows what i am trying to do

white-margin

I also noticed that print attributes were not set in case of saving the PDF file and i tried to set it in File output by updating PrintAttributes in printManager but this did not fix my problem


        PrintAttributes attributes = new PrintAttributes.Builder()
        .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
        .setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600))
        .setMinMargins(PrintAttributes.Margins.NO_MARGINS).build();  

        printManager.print(PRINT_JOB_NAME, pdfPrinter, attributes);
sherifdarwish commented 6 years ago

I found this issue but it is talking about IOS only https://github.com/cesarvr/pdf-generator/issues/7

cesarvr commented 6 years ago

Hi I try to add attribute as you mention the print method is ignoring it, so I'll need more time to solve this if you find a solution feel free to send a pull request 👍.

cesarvr commented 6 years ago

It looks like is a bug in Android API https://issuetracker.google.com/issues/69352609, hope you find a workaround.

sherifdarwish commented 6 years ago

Thanks

I found some java android apps doing the same printing directly and not having the same margin

It end out that they use a web view inside relative layout and this layout have some xml property to clear any padding around

I was not able to apply the same concept for our generated web view

I will try to share some sample soon for this

Regards

On Dec 13, 2017 9:40 PM, "Cesar Valdez" notifications@github.com wrote:

It looks like is a bug in Android API https://issuetracker.google. com/issues/69352609, hope you find a workaround.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/cesarvr/pdf-generator/issues/54#issuecomment-351482996, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSGurnA05blfSGuIH72A1DZG52ZOzpYks5tABoUgaJpZM4Qc36A .

sharutza commented 6 years ago

Hi I'm having the same problem.. need to remove the extra padding added to the pdf. Any solution on that?

Thanks!

sharutza commented 6 years ago

Found a solution if someone is still interested: it seems it's related to web-view css proprieties: I added this in my css or in style region of the html page: @page{ margin-left: 0px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px; padding:0px; }

And for IOS, there are some margins inserted by default in code in file "cordova-pdf-generator\src\ios\BNHtmlPdfKit.m"

(id)init { if (self = [super init]) { self.pageSize = [BNHtmlPdfKit defaultPageSize]; self.landscape = NO;

    // Default 1/4" margins
    self.topAndBottomMarginSize =0.25f * 72.0f;
    self.leftAndRightMarginSize = 0.25f * 72.0f;
}
return self;

}

Set these two to 0: self.topAndBottomMarginSize =0; self.leftAndRightMarginSize = 0;

The same in next 3 functions.

cesarvr commented 6 years ago

thanks for sharing @sharutza

elros88 commented 5 years ago

Hi, I'm having the same problem. I tried the @sharutza, the app did not get the style

sobhankp commented 2 years ago

Is there any help for android. I am also having the same problem.