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

PDF coming in two pages #31

Open
justapps4u opened this issue Sep 10, 2015 · 4 comments
Open

PDF coming in two pages #31

justapps4u opened this issue Sep 10, 2015 · 4 comments

Comments

@justapps4u
Copy link

Hi
In my app, I generate a HTML string fetching values from the database. Then I use this HTML string (myHTML) to generate a PDF file using NDHTMLtoPDF. Code below:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/Invoice.pdf"];
self.PDFCreator = [NDHTMLtoPDF createPDFWithHTML:myHTML pathForPDF:filePath delegate:self pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(10, 5, 10, 5)];

Problem us that for many HTML's the PDF comes in two pages, even though the HTML is one page only. Some space is left below. The below HTML file is one such example.

https://www.dropbox.com/s/78ejvq4c82v8010/Invoice%20%281%29.html?dl=0

Can you please check this HTML file and let me know why the PDF for this comes in two pages?

@dfranc3373
Copy link

I have the same issue, HTML is as followed:

<html>

    <body style="font-family: arial;">

    <h1 align="right">Change Order</h1>

        <br />

        <hr style="width: 90%">

        <table align="center" style="width: 80%;">
        <tr>

            <td>Attention: <span id="attention"></span></td>
            <td>Company: <span id="company"></span></td>

        </tr>
        <tr>

            <td style="padding-top: 9px;">Date: <span id="date"></td>
            <td></span></td>

        </tr>
        <tr>

            <td style="padding-top: 9px;">Address: <span id="address"></span></td>
            <td></td>

        </tr>
        </table>

        <br />

        <hr style="width: 90%;">

        <div align="center">

            <h4 style="width: 80%; text-align: left;">Description of Charge</h4>

        </div>

        <table align="center" style="width: 80%; border: 1px solid;" id="main_data">
            <tr>
                <th style="width: 75%; text-align: left;">Description</th>
                <th style="width: 25%;">Cost</th>
            </tr>
        </table>

        <div align="center">

            <h4 style="width: 73%; text-align: right;">Tax: <span id="tax"></span> <br /> Total: <span id="total"></span></h4>

        </div>

        <table align="center" style="width: 80%;">
        <tr>

            <td style="width: 30%">Client Signature</td>
            <td valign="bottom"><hr style="margin-top: 22px;"/></td>

        </tr>
        <tr>

            <td style="padding-top: 9px;">Date:</td>
            <td></span></td>

        </tr>
        <tr>

            <td style="width: 30%">Contractor Signature</td>
            <td valign="bottom"><span id="signature"></span><br /><hr style="margin-top: 22px;"/></td>

        </tr>
        <tr>

            <td style="padding-top: 9px;">Date: <span id="date"></span></td>
            <td></span></td>

        </tr>
        </table>

    </body>

</html>

The code used to render is:


self.PDFCreator = [NDHTMLtoPDF createPDFWithHTML:@"<html> <body style='font-family: arial;'> <h1 align='right'>Change Order</h1> <br /> <hr style='width: 90%'> <table align='center' style='width: 80%;'> <tr> <td>Attention: <span id='attention'></span></td> <td>Company: <span id='company'></span></td> </tr> <tr> <td style='padding-top: 9px;'>Date: <span id='date'></td> <td></span></td> </tr> <tr> <td style='padding-top: 9px;'>Address: <span id='address'></span></td> <td></td> </tr> </table> <br /> <hr style='width: 90%;'> <div align='center'> <h4 style='width: 80%; text-align: left;'>Description of Charge</h4> </div> <table align='center' style='width: 80%; border: 1px solid;' id='main_data'> <tr> <th style='width: 75%; text-align: left;'>Description</th> <th style='width: 25%;'>Cost</th> </tr> </table> <div align='center'> <h4 style='width: 73%; text-align: right;'>Tax: <span id='tax'></span> <br /> Total: <span id='total'></span></h4> </div> <table align='center' style='width: 80%;'> <tr> <td style='width: 30%'>Client Signature</td> <td valign='bottom'><hr style='margin-top: 22px;'/></td> </tr> <tr> <td style='padding-top: 9px;'>Date:</td> <td></span></td> </tr> <tr> <td style='width: 30%'>Contractor Signature</td> <td valign='bottom'><span id='signature'></span><br /><hr style='margin-top: 22px;'/></td> </tr> <tr> <td style='padding-top: 9px;'>Date: <span id='date'></span></td> <td></span></td> </tr> </table> </body> </html>"
                                          pathForPDF:[@"~/Documents/delegateDemo.pdf" stringByExpandingTildeInPath]
                                           delegate:self
                                           pageSize:kPaperSizeA4
                                            margins:UIEdgeInsetsMake(10, 5, 10, 5)];

@dwong-uw
Copy link

Having a similar issue as well, except the HTML being rendered onto the PDF is being prematurely cut off on the first page. It only seems to happen when one column in the table is particularly wide.

simulator screen shot sep 25 2015 3 22 19 pm

As you can see, where "SUBTOTAL" stars on the next page should actually be a part of the table above.

This is the HTML that's being rendered:

<html lang='en'>
    <head>
        <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'></meta>
        <meta charset='utf-8'></meta>
        <title>Example 1</title>
        <link rel='stylesheet' href='pro_monochrome_template.css' media='all'></link>
    </head>
    <body>
        <header class='clearfix'>
            <div id='logo'>
                <img src='logo_6A979AF8B0E90B7F405911F9512BE8C1.jpg'></img>
            </div>
            <h1 id='invoice_num'>Invoice INV0001</h1>
            <div id='company' class='clearfix'>
                <div id='company_company' class='company'>Test Company</div>
                <div id='company_name' class='name'>Anna Haro</div>
                <div id='company_address1' class='address'>1001  Leavenworth Street</div>
                <div id='company_address2' class='address'>Sausalito CA 94965</div>
                <div id='company_phone' class='phone'>555-522-8243</div>
                <div id='company_email' class='email'>[email protected]</div>
            </div>
            <div id='client'>
                <div id='client_name_container' class='client_container'>
                    <span id='client_name_label' class='client_table_label'>Name</span>
                    <span id='client_name' class='client_table_value'>Daniel Higgins</span>
                </div>
                <div id='client_phone_container' class='client_container'>
                    <span id='client_phone_label' class='client_table_label'>Phone</span>
                    <span id='client_phone' class='client_table_value'>555-478-7672</span>
                </div>
                <div id='client_effective_date_container' class='client_container'>
                    <span id='effective_date_label' class='client_table_label'>Date</span>
                    <span id='effective_date' class='client_table_value'>September 24, 2015</span>
                </div>
            </div>
        </header>
        <main>
            <table>
                <thead>
                    <tr id='item_header'>
                        <th id='item_header_desc' class='service'>Description</th>
                        <th id='item_header_total'>Total</th>
                    </tr>
                </thead>
                <tbody id='items'>
                    <tr>
                        <td class='item-desc'>
                            <h3 class='name'>Item 1</h3>
                            <span class='desc'>This is a very long description, and when there is a long description then the description table cell becomes very wide. When a table cell becomes very wide, the renderer starts to cut the table off early into the page.</span>
                        </td>
                        <td class='total'>$4.00</td>
                    </tr>
                    <tr>
                        <td class='item-desc'>
                            <h3 class='name'>Item&nbsp;2</h3>
                            <span class='desc'>Test here</span>
                        </td>
                        <td class='total'>$15.00</td>
                    </tr>
                    <tr id='subtotal' class='footer_row'>
                        <td id='subtotal_label'>Subtotal</td>
                        <td id='subtotal_amt' class='total'>$19.00</td>
                    </tr>
                    <tr id='total' class='footer_row'>
                        <td id='total_label' class='grand total'>Total</td>
                        <td id='total_amt' class='grand total'>$19.00</td>
                    </tr>
                    <tr id='paid' class='footer_row'>
                        <td id='paid_label'>Paid</td>
                        <td id='paid_amt' class='total'>$0.00</td>
                    </tr>
                    <tr id='due' class='footer_row'>
                        <td id='due_label' class='grand total'>Due</td>
                        <td id='due_amt' class='grand total'>$19.00</td>
                    </tr>
                </tbody>
            </table>
            <div id='notices'>
                <div id='notes' class='notice'></div>
            </div>
        </main>
    </body>
</html>

@JackIsBack
Copy link

Did you guys, have fix your problems with that pdf cuttings issues ?

I had similar problem when using table. I replaced my table with inline block divs or flex, and fix the problem.

I had the same issue too using css: float and text-align.

Anyone has a workaround about all those problems ?

@Cai333
Copy link

Cai333 commented May 20, 2016

After a lot of searching it seems the problem (for me at least) was with my print CSS. Printing the HTML from a browser gave the same blank page at the end.

Simple fix—add this to the CSS:

html, body { height: auto; }

May not work for everyone but it fixed my problem.

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

5 participants