Html string to pdf conversion not working on iOS

Product: PDFTron sdk for Xamrin iOS

Product Version: PDFTron iOS - 9.0.0

Please give a brief summary of your issue:
Html string to pdf conversion not working on iOS.

Please describe your issue and provide steps to reproduce it:
I am following your documentation and the below sample to convert a HTML string to PDF in iOS.

But I can’t get the output in here. It does not throw any errors or exceptions. Need your help to tackle this problem. Really grateful if you can assist me on this one.

Please provide a link to a minimal sample where the issue is reproducible:

Hi,

Thank you for getting in touch with us about this.
Are you able to share the HTML string you are trying to convert?

Hi,

Thanks for your response. Sure I can give a sample html, I cant upload a file as I am new user, so I will paste the code here.

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>This step contains a repeating section</title>
    <style type="text/css">
        body {
            color: dimgray;
            font-family: Helvetica;
        }

        .container {
            width: auto;
            height: auto;
            margin: auto;
            padding: 16px;
            font-family: arial;
            position: relative;
            font-size: 14px;
        }

        h1 {
            font-size: 24px;
            margin-top: 5px;
            padding-bottom: 10px;
            text-align: center;
        }

        h2 {
            font-weight: 700;
            font-size: 12px;
            padding: 10px;
            margin-bottom: 0px;
            color: black;
            background-color: #E8E8E8;
            background-size: contain;
            border: 1px solid #E8E8E8;
        }

        table {
            border-top: none;
            width: 100%;
            border-spacing: 0;
            border-collapse: collapse;
        }

        td {
            text-align: center;
            color: black;
            padding: 10px;
            overflow: hidden;
        }

        th {
            border-top: none;
            padding: 10px;
            overflow: hidden;
            color: black;
        }

        .div-listtable {
            border-top: 1px solid #E8E8E8;
            border-right: 1px solid #E8E8E8;
            border-left: 1px solid #E8E8E8;
        }

        .listtable {
            table-layout: fixed;
            border-top: none;
        }

            .listtable td {
                font-weight: normal;
                font-size: 10px;
                font-style: normal;
                text-align: left;
                border-bottom: 1px solid #E8E8E8;
            }

            .listtable th {
                font-weight: normal;
                font-size: 10px;
                border-top: none;
                border-bottom: 1px solid #E8E8E8;
                text-align: left;
                color: #535C61;
            }

        .div-formtable {
            border-top: none;
            border: 1px solid #E8E8E8;
        }

        .formtable {
            border-top: none;
            table-layout: fixed;
        }

            .formtable td {
                color: #2B363C;
                font-size: 10px;
                font-style: normal;
                text-align: left;
                vertical-align: top;
            }

            .formtable th {
                font-size: 10px;
                color: #535C61;
                text-align: left;
            }

        .markdown {
            display: inline-block;
            padding: 10px;
            border-radius: 5px;
        }

            .markdown p {
                /*
                The markdown to HTML library nests everything within a <p> tag which the browsers add a default margin to.
                We should remove that
            */
                margin: 0;
            }

        .badge {
            font-family: 'Open Sans';
            display: inline-block;
            padding: 10px;
            text-align: center;
            border-radius: 5px;
        }

    </style>
</head>
<body>
    <div class="container">
        <h1>This step contains a repeating section</h1><td style="vertical-align: top;"><h2>Purchase Order Main</h2><div class="div-formtable"><table class="formtable"><tr><td colspan="2"><span class="fieldheader">Order No</span><br>1</td><td colspan="2"><span class="fieldheader">Description</span><br>Test purchase order</td></tr><tr><td colspan="2"><span class="fieldheader">Purchaser</span><br>ALAIN</td></table></div><br></td><div class="markdown" color:#123F33; background-color:#3DD2AA;"><p>1-1 Engine (1)</p>
</div><div style='padding: 10px; border: 1px solid #E8E8E8'><header><b>Step Header</b></header><p>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<div style='text-indent: 5%'><b>Indent 1</b> Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... </div><br><div style='text-indent: 10%'><b>Indent 2</b> Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... </div><br><div style='text-indent: 15%'><b>Indent 3</b> Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... </div><br>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<br><br><span style='color: red'>Warning!</span> Warning message... Warning message... <br><br><span style='color: blue'>Info!</span> Info message... Info message... <br><br><span style='color: green'>Success!</span> Success message... Success message...<br><br><p>Variable Test: <ul><li>Order Number: 1</li><li>Line Number: 1</li><li>Item ID: Engine</li><li>Quantity: 1</li></ul></div><h2>Purchase Order Serials List</h2><div class="div-listtable"><table class="listtable"><tr><th></th><th>Order No</th><th>Line No</th></tr><tr><td class="fieldheader">EN001</td><td>1</td><td>1</td></tr></table></div><div class="markdown" color:#123F33; background-color:#3DD2AA;"><p>1-2 Wheels (4)</p>
</div><div style='padding: 10px; border: 1px solid #E8E8E8'><header><b>Step Header</b></header><p>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<div style='text-indent: 5%'><b>Indent 1</b> Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... </div><br><div style='text-indent: 10%'><b>Indent 2</b> Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... </div><br><div style='text-indent: 15%'><b>Indent 3</b> Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... </div><br>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<br><br><span style='color: red'>Warning!</span> Warning message... Warning message... <br><br><span style='color: blue'>Info!</span> Info message... Info message... <br><br><span style='color: green'>Success!</span> Success message... Success message...<br><br><p>Variable Test: <ul><li>Order Number: 1</li><li>Line Number: 2</li><li>Item ID: Wheels</li><li>Quantity: 4</li></ul></div><h2>Purchase Order Serials List</h2><div class="div-listtable"><table class="listtable"><tr><th></th><th>Order No</th><th>Line No</th></tr><tr><td class="fieldheader">WH001</td><td>1</td><td>2</td></tr><tr><td class="fieldheader">WH002</td><td>1</td><td>2</td></tr><tr><td class="fieldheader">WH003</td><td>1</td><td>2</td></tr><tr><td class="fieldheader">WH004</td><td>1</td><td>2</td></tr></table></div><div class="markdown" color:#123F33; background-color:#3DD2AA;"><p>1-3 Seats (2)</p>
</div><div style='padding: 10px; border: 1px solid #E8E8E8'><header><b>Step Header</b></header><p>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<div style='text-indent: 5%'><b>Indent 1</b> Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... Indent 1... </div><br><div style='text-indent: 10%'><b>Indent 2</b> Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... Indent 2... </div><br><div style='text-indent: 15%'><b>Indent 3</b> Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... Indent 3... </div><br>Test paragraph goes here... Test paragraph goes here... Test paragraph goes here... Test paragraph goes here...<br><br><span style='color: red'>Warning!</span> Warning message... Warning message... <br><br><span style='color: blue'>Info!</span> Info message... Info message... <br><br><span style='color: green'>Success!</span> Success message... Success message...<br><br><p>Variable Test: <ul><li>Order Number: 1</li><li>Line Number: 3</li><li>Item ID: Seats</li><li>Quantity: 2</li></ul></div><h2>Purchase Order Serials List</h2><div class="div-listtable"><table class="listtable"><tr><th></th><th>Order No</th><th>Line No</th></tr><tr><td class="fieldheader">SE001</td><td>1</td><td>3</td></tr><tr style="background-color: #360065; color: #FAFAFA;"><td class="fieldheader">SE002</td><td>1</td><td>3</td></tr></table></div>
    </div>
</body>
</html>

Thanks and regards,
/Dhanushka

Hi @Jamie_Dassoulas,

Any updates on this one?

Hi @dhanushka.premasingh,

Thank you for your patience and for reporting this.
We were able to reproduce the issue and I believe it’s because the sample code on our site is slightly out of date.
Here is an updated version of the conversion code which should work:

pdftronprivate.PTConvert.ConvertHTMLStringToPDF(htmlString, baseURL, CGSize.Empty, (pathToPDF) => {
    if (pathToPDF == null)
    {
        // Failed to convert HTML to PDF.
        return;
    }

    var documentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

    var urlToPdf = new NSUrl(pathToPDF, false);
    var destinationURL = (new NSUrl(documentDirectory)).Append(urlToPdf.LastPathComponent, false);
    var destinationFileURL = NSUrl.CreateFileUrl(destinationURL.Path, null);
                
    NSError error = null;
    var result = NSFileManager.DefaultManager.Copy(urlToPdf, destinationFileURL, out error);
    if (!result)
    {
        // Failed to copy PDF to persistent location.
    }
    // Do something with PDF output.
});
}

Are you able to try that and let us know if it works for you?
I will also update the website with the newer version of the snippet.

Hi @Jamie_Dassoulas,
Thank you for your help. I will try that out. And another issue right here when installing the nuget.

Any idea why this error is?

Thanks and regards,
Dhanushka

Hi @dhanushka.premasingh

Could you share which version of Visual Studio you are using?
Are you able to try removing and re-adding the package and see if the issue persists?

Do any of the solutions listed on this page help at all? e.g. migrating to using Package References instead of package.config.

If none of those approaches work would you be able to share your project with us?

Best regards,
Jamie

Hi @Jamie_Dassoulas,

Really grateful for your help. I was able to convert html to pdf successfully. Now can I know how to add a footer to the pdf page and also to add repeating table headers using your library. Any links for documentation would be helpful.

Thanks and regards,
/Dhanushka