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

how can i add margin or padding(for bottom and top) in page?? is there any option for page format (A4,letter,a3,a5,legal)? #82

Open
bhaumik1111 opened this issue Jan 2, 2024 · 6 comments

Comments

@bhaumik1111
Copy link

No description provided.

@raister21
Copy link

This PR has support for page format.
#81

or you can use my fork.

Margin and padding does not have support.

@bhaumik1111
Copy link
Author

is there any logic for padding margin? apply on html content?

@raister21
Copy link

This package does not support header/footer or paddings on html content.

Instead you can Add your own Header and Footer on the html itself. apply the padding and margin to the html itself, that should work

@bhaumik1111
Copy link
Author

i am new to flutter !
how can i do this?
pls give mesuggestion for it any demo code or something

@raister21
Copy link

add this to your pubspec.yaml file

flutter_html_to_pdf:
    git:
      url: https://github.com/raister21/flutter_html_to_pdf

After that you can use the Updated version of this package. Which I am currently hosting through my GitHub, you can look into forking if you want to have a copy of my version of this package.

how can i do this?

In your Project,

final String htmlContent = """
    <!DOCTYPE html>
    <html>
      <head>
        <style>
        table, th, td {
          border: 1px solid black;
          border-collapse: collapse;
        }
        th, td, p {
          padding: 5px;
          text-align: left;
        }
        </style>
      </head>
      <body>
        <h2>PDF Generated with flutter_html_to_pdf plugin</h2>
        
        <table style="width:100%">
          <caption>Sample HTML Table</caption>
          <tr>
            <th>Month</th>
            <th>Savings</th>
          </tr>
          <tr>
            <td>January</td>
            <td>100</td>
          </tr>
          <tr>
            <td>February</td>
            <td>50</td>
          </tr>
        </table>
        
        <p>Image loaded from web</p>
        <img src="https://i.imgur.com/wxaJsXF.png" alt="web-img">
      </body>
    </html>
    """;

Directory appDocDir = await getApplicationDocumentsDirectory();
final targetPath = appDocDir.path;
final targetFileName = "example-pdf";

final generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
  htmlContent: htmlContent,
  printPdfConfiguration: PrintPdfConfiguration(
    targetDirectory: targetPath,
    targetName: targetFileName,
    printSize: PrintSize.A4,
    printOrientation: PrintOrientation.Portrait,
  ),
);

The htmlContent is what you will be printing. Whatever renders when you open the htmlContent on a web browser should be your expected results in pdf (generatedPdfFile).

@penkzhou
Copy link

penkzhou commented Jan 22, 2024

all those changes have been merged into this repo

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

3 participants