TPPDF icon indicating copy to clipboard operation
TPPDF copied to clipboard

TPPDF : Add Multiple images with text content in the same cell in the Table()

Open yamapuvar opened this issue 5 years ago • 6 comments

I am working on a PDF Builder app and came through this tutorial.

Is there any way around to add some text in a cell with multiple images. I tried different ways but it results into error in the PDF.

I have tried this :

let table = PDFTable()

            let str = String(format: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
            let str1 = String(format: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \n\nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ")

            do {
                try table.generateCells(
                    data:[
                        ["Name", "Image", "Description"],
                        [project.name + "\n" +  project.address1, UIImage(named: "demo")!, str],
                        [project.name + "\n" +  project.address1, UIImage(named: "demo")!, str1]
                        ],
                    alignments: [
                    [.topLeft, .top, .top],
                    [.topLeft, .top, .top],
                    [.topLeft, .top, .top]
                        ])
                } catch PDFError.tableContentInvalid(let value) {
                    // In case invalid input is provided, this error will be thrown.

                    print("This type of object is not supported as table content: " + String(describing: (type(of: value))))
                } catch {
                    // General error handling in case something goes wrong.

                    print("Error while creating table: " + error.localizedDescription)
                }

    table.widths = [
               0.23, 0.30, 0.47
           ]

        let style = PDFTableStyleDefaults.simple
    table.style = style

    do {
        // Style each cell individually
        try table.setCellStyle(row: 1, column: 0, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
        try table.setCellStyle(row: 1, column: 1, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
        try table.setCellStyle(row: 1, column: 2, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
        try table.setCellStyle(row: 2, column: 0, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
        try table.setCellStyle(row: 2, column: 1, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
        try table.setCellStyle(row: 2, column: 2, style: PDFTableCellStyle(colors: (fill: UIColor.lightGray, text: UIColor.black)))
    } catch PDFError.tableIndexOutOfBounds(let index, let length){
        // In case the index is out of bounds

        print("Requested cell is out of bounds! \(index) / \(length)")
    } catch {
        // General error handling in case something goes wrong.

        print("Error while setting cell style: " + error.localizedDescription)
    }
    table.padding = 1.0
    table.margin = 2.0

    table.showHeadersOnEveryPage = true

    document.add(table: table)

Please help me to find some way around. Thank you.

yamapuvar avatar Nov 22 '19 05:11 yamapuvar

Hi there, I am not sure what exactly your issue is. Do you want multiple images and text in a single cell?

Please clarify your issue, and post any errors you receive while creating it

philprime avatar Jan 07 '20 14:01 philprime

Hello Philip,

Thank you for the response. We actually are working on an app where we need to include multiple data i.e. one or more image with text content below the image. I have attached a screenshot for your reference.

I tried to implement the same in the current code structure but could not get the desired result.

Please check and help me if possible.

Thank you.

Regards, Yama Puvar

[cid:d18fa016-dda8-4f7b-9db7-7ccfc93bceee]


From: Philip Niedertscheider [email protected] Sent: Tuesday, January 7, 2020 8:21 PM To: techprimate/TPPDF [email protected] Cc: Yama Puvar [email protected]; Author [email protected] Subject: Re: [techprimate/TPPDF] TPPDF : Add Multiple images with text content in the same cell in the Table() (#166)

Hi there, I am not sure what exactly your issue is. Do you want multiple images and text in a single cell?

Please clarify your issue, and post any errors you receive while creating it

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/techprimate/TPPDF/issues/166?email_source=notifications&email_token=AN27NADM6MNCMVX6D6H3PQTQ4SJIRA5CNFSM4JQL5R6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIJDPZA#issuecomment-571619300, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN27NAEANP4EF5ZLTUJ4M33Q4SJIRANCNFSM4JQL5R6A.

yamapuvar avatar Jan 08 '20 05:01 yamapuvar

@yamapuvar if you want to post an image into the issue, you need to use the Website to do so, sending an email won't post the screenshot, therefore I do not see it right now

philprime avatar Jan 08 '20 10:01 philprime

Hello Philip,

Please find attached PDF. I need to create PDF in such format. Please help if possible.

Sample PDF

yamapuvar avatar Jan 09 '20 04:01 yamapuvar

As of now, this case is not supported by the framework. I think to offer this feature we would have to extend the table content possibilities. This will be a major feature update and therefore break the API.

I will take a look and consider if it is viable in the next release.

If you can offer a solution from yourself, please feel free to open a PR

philprime avatar Jan 10 '20 12:01 philprime

how can i build a table of image and text

Gizmeondevwip avatar Sep 18 '20 15:09 Gizmeondevwip