Barry
Barry

Reputation: 31

Convert HTML to PDF and share native in PhoneGap app

i want to convert my result HTML page to PDF in phone gap app and then want to share it with phone's native share window.anybody who already did this or have any idea, it would be great help as i stuck here from couple of weeks.

kendo.drawing.drawDOM($(".pdf-page"))
        .then(function(group) {
        // Render the result as a PDF file
        return kendo.drawing.exportPDF(group, {
            paperSize: "auto",
            margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" }
        });
    })
    .done(function(data) {
        // Save the PDF file
        kendo.saveAs({
            dataURI: data,
            fileName: "manual.pdf",
           // proxyURL: "//demos.telerik.com/kendo-ui/service/export",
            callback:alert("done 1")
        });
    });

its is working fine on PC but not working in android mobile app on which currently i am testing. if this works in mobile then can i use

window.plugins.socialsharing.share('Here is your PDF file', 'Your PDF', 'www/files/manual.pdf')

to share that pdf file

Upvotes: 1

Views: 1996

Answers (2)

Erick Lanford Xenes
Erick Lanford Xenes

Reputation: 1572

This is what we did:

<script>

    $(function () {
        $("#button0PDF").kendoButton();
        var button = $("#button0PDF").data("kendoButton");

        button.bind("click", function (e) {
            kendo.drawing.drawDOM("#divId", {
                forcePageBreak: ".page-break",
                //template: $("#page-template").html()

            })
            .then(function (group) {
                // Render the result as a PDF file
                return kendo.drawing.exportPDF(group, {
                    landscape: false
                });
            })
            .done(function (data) {
                // Save the PDF file
                kendo.saveAs({
                    dataURI: data,
                    fileName: "fileName.pdf",
                    proxyURL: "/API/Main/Post",
                });
            });
        });
    });

</script>

And the server side part:

public HttpResponseMessage Post([FromBody]FileData file)
        {
            var data = Convert.FromBase64String(file.Base64);

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(new MemoryStream(data))
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType);

            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = file.FileName
            };

            return result;
        }

Upvotes: 0

user5091906
user5091906

Reputation: 166

For Phonegap/Cordova apps:

You can use jsPDF library to create dpf file and Cordova file plugin to save pdf file locally and simply share it with using any Cordova share plugin.

Hope this link helps you saving pdf.

Upvotes: 1

Related Questions