Sign In  Sign Up Live-Chat

Table, iterate, image

Last post 08-12-2008, 4:42 PM by janlars. 6 replies.
Sort Posts: Previous Next
  •  08-06-2008, 5:32 PM 138629

    Table, iterate, image

    Hi, could I have an hint how to get images to work:

    Dim Pdf1 As New Pdf()
    Dim oSection As Aspose.Pdf.Section = Pdf1.Sections.Add()
    Dim oCell As Aspose.Pdf.Cell
    Dim oCellSeg As Aspose.Pdf.Segment
    Dim oCellText As Aspose.Pdf.Text
    Dim r, c as integer
    Dim imgX As New Aspose.Pdf.Image()
    Dim oTbl As New Aspose.Pdf.Table(oSection)
    oSection.Paragraphs.Add(oTbl)
    oTbl.ColumnWidths = "100 100 100 100"
    Dim oRow As Aspose.Pdf.Row
    for r = 1 to 3
    oRow = New Aspose.Pdf.Row(oTbl)
    oTbl.Rows.Add(oRow)
    for c = 1 to 4
    oCell = New Aspose.Pdf.Cell(oTbl)
    if r = 2 then ocell.Border = New BorderInfo(CType(BorderSide.bottom, Integer), 0.5F)
    oRow.Cells.Add(oCell)
    if r = 2 and c = 3 then
    'put imgX here
    else
    oCellText = New Aspose.Pdf.Text(oSection)
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg)
    oCellSeg.Content =  "Test" & r & c
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg) 
    end if
    next
    next
    Pdf1.Save("testTable.pdf", SaveType.OpenInAcrobat, Response)

     
  •  08-07-2008, 5:49 AM 138713 in reply to 138629

    Re: Table, iterate, image

    Attachment: Present (inaccessible)

    Hello Jan,

    Thanks for considering Aspose.

    As far as, I have understood from you code, your requirement is to place an image in Row =2 and Column =3. Please use the following code snippet at "put imgX here"

    imgX.ImageInfo.File = "C:\Temp\Aspose.JPG"
    imgX.ImageInfo.ImageFileType = ImageFileType.Jpeg
    oCell.Paragraphs.Add(imgX)

    The resultant file is in attachment. Please correct me if I have not properly understood your requirement.


    Nayyer Shahbaz
    Support Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  08-07-2008, 4:41 PM 138849 in reply to 138713

    Re: Table, iterate, image

    Attachment: Present (inaccessible)

    Thanks, it working. Unfortunately there is another problem: this table is huge, should be two pages, but is three because every row exept the first one on every page is in about twice height. The code is complicated since all data comes from a database and becuase of the need for presenting the data different depending on some data-values Therefore I first store the entire pdf-data incl. formatting details in some arrays. The important part of the code looks like this (there is actually another problem: is it possible to have combinations of borderside like left + bottom?):

    Dim Pdf1 As New Pdf()
    Dim oSection As Aspose.Pdf.Section = Pdf1.Sections.Add()
    Dim oCell As Aspose.Pdf.Cell
    Dim oCellSeg As Aspose.Pdf.Segment
    Dim oCellText As Aspose.Pdf.Text
    Dim oRow As Aspose.Pdf.Row
    Dim imgX As New Aspose.Pdf.Image()
    imgX.ImageInfo.File =  Server.MapPath("../images") & "/" & "sluplatta.jpg"
    imgX.ImageInfo.ImageFileType = ImageFileType.Jpeg     
    Dim oTbl As New Aspose.Pdf.Table(oSection)
    oTbl.IsFirstRowRepeated = True
    Dim marginInfo As MarginInfo = New MarginInfo()   'Instantiate the MarginInfo instance
    marginInfo.Top = 20
    marginInfo.Bottom = 72
    marginInfo.Left = 70
    marginInfo.Right = 10
    oSection.PageInfo.Margin = marginInfo
    oSection.Paragraphs.Add(oTbl)
    oSection.BackgroundImageFile = Server.MapPath("../images") & "/" & "SLU10_300.jpg" 
    oSection.BackgroundImageType = ImageFileType.Jpeg
    oTbl.ColumnWidths = "42 42 42 42 42 42 42 42 42 42 42 42"
    for r = 0 to antR
    oRow = New Aspose.Pdf.Row(oTbl)
    oTbl.Rows.Add(oRow)
    if r = 25 then oRow.IsInNewPage = True
    for c = 0 to 11
    if cSpan(r, c) > 0 then
    oCell = New Aspose.Pdf.Cell(oTbl)
    oCell.ColumnsSpan = cSpan(r, c)     
    if bordS(r, c) = 1 then ocell.Border = New BorderInfo(CType(BorderSide.top, Integer), 0.5F)
    if bordS(r, c) = 2 then ocell.Border = New BorderInfo(CType(BorderSide.all, Integer), 0.5F)
    if bordS(r, c) = 3 then ocell.Border = New BorderInfo(CType(BorderSide.left, Integer), 0.5F)
    if bordS(r, c) = 4 then ocell.Border = New BorderInfo(CType(BorderSide.right, Integer), 0.5F)
    if bordS(r, c) = 5 then ocell.Border = New BorderInfo(CType(BorderSide.bottom, Integer), 0.5F)         
    if bordS(r, c) = 11 then ocell.Border = New BorderInfo(CType(BorderSide.top, Integer), 1.5F)
    if bordS(r, c) = 12 then ocell.Border = New BorderInfo(CType(BorderSide.all, Integer), 1.5F)
    if bordS(r, c) = 13 then ocell.Border = New BorderInfo(CType(BorderSide.left, Integer), 1.5F)
    if bordS(r, c) = 14 then ocell.Border = New BorderInfo(CType(BorderSide.right, Integer), 1.5F)
    if bordS(r, c) = 15 then ocell.Border = New BorderInfo(CType(BorderSide.bottom, Integer), 1.5F)

    if c = 1 then oCell.ColumnsSpan = 2
    oRow.Cells.Add(oCell)
    if r = 0 and c = 0 then
    oCell.Paragraphs.Add(imgX)
    else
    oCellText = New Aspose.Pdf.Text(oSection)
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg)
    if align(r, c) = 1 then oCellText.TextInfo.Alignment = AlignmentType.Left
    if align(r, c) = 2 then oCellText.TextInfo.Alignment = AlignmentType.Center
    if align(r, c) = 3 then oCellText.TextInfo.Alignment = AlignmentType.Right
    With oCellSeg.TextInfo
    .FontName = fontT(r, c)  '"Courier" '"Times-Roman"
    .FontSize = fontS(r, c)
    if boldI(r, c) = "b" then .IsTrueTypeFontBold = true
    if boldI(r, c) = "i" then .IsTrueTypeFontItalic = true              
    End With
    oCellSeg.Content =  value(r, c)
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg)  
    end if
    end if 'cSpan > 0  
    next
    next
    Pdf1.Save("testTable.pdf", SaveType.OpenInAcrobat, Response)

     
  •  08-08-2008, 5:08 PM 139041 in reply to 138849

    Re: Table, iterate, image

    Hello Jan,

    I have seen the Pdf file, but I am unable to understand the problem that you have mentioned, could you please explain it once more.

    Secondly, I have tried executing the code, but it seems like you are calling so many external methods, which are providing the data, so in order for us to test the issue, a whole project is required.

    Concerning your query,” is it possible to have combinations of border side like left + bottom?" 
    Answer is, if you only want to add Left and Bottom border, than it is supported. Is it what you have asked, please correct me, if I have misunderstood your requirement.


    Nayyer Shahbaz
    Support Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  08-09-2008, 10:58 AM 139075 in reply to 139041

    Re: Table, iterate, image

    Attachment: Present (inaccessible)

    Hi Nayyer

    Rowheight: In the following code the height of each row is about twice the height of the letters no matter the size of the font (fontsize 6 gives rowheight about 12, fontsize 16 gives 32 etc) . It's not possible to force the row-height to be something because there could be several rows of text within a cell, solution?

    The IsFirstRowRepeated gives row 1 to occur on page 2, but why is the text in the cells in row 1, page 2 repeated?

    Cheers

    Dim Pdf1 As New Pdf()
    Dim oSection As Aspose.Pdf.Section = Pdf1.Sections.Add()
    Dim oCell As Aspose.Pdf.Cell
    Dim oCellSeg As Aspose.Pdf.Segment
    Dim oCellText As Aspose.Pdf.Text
    Dim oRow As Aspose.Pdf.Row
    Dim r, c as integer
    Dim oTbl As New Aspose.Pdf.Table(oSection)
    oTbl.IsFirstRowRepeated = True
    Dim marginInfo As MarginInfo = New MarginInfo()   'Instantiate the MarginInfo instance
    marginInfo.Top = 20
    marginInfo.Bottom = 72
    marginInfo.Left = 70
    marginInfo.Right = 10
    oSection.PageInfo.Margin = marginInfo
    oSection.Paragraphs.Add(oTbl)
    oTbl.ColumnWidths = "100 100 100 100"
    for r = 1 to 42
    oRow = New Aspose.Pdf.Row(oTbl)
    oTbl.Rows.Add(oRow)
    if r = 18 then oRow.IsInNewPage = True
    for c = 1 to 4
    oCell = New Aspose.Pdf.Cell(oTbl)
    ocell.Border = New BorderInfo(CType(BorderSide.all, Integer), 0.2F)
    oRow.Cells.Add(oCell)
    oCellText = New Aspose.Pdf.Text(oSection)
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg)
    oCellSeg.Content =  "Row " & r & ", Col " & c
    oCellSeg.TextInfo.FontSize = 10
    oCell.Paragraphs.Add(oCellText)
    oCellSeg = New Aspose.Pdf.Segment(oCellText)
    oCellText.Segments.Add(oCellSeg)  
    next
    next
    Pdf1.Save("testTable.pdf", SaveType.OpenInAcrobat, Response)

     
  •  08-09-2008, 8:08 PM 139091 in reply to 139075

    Re: Table, iterate, image

    Hi,

    I found you add the text paragraph into the cell twice. Please remove the following code:

                    oCell.Paragraphs.Add(oCellText)
                    oCellSeg = New Aspose.Pdf.Segment(oCellText)
                    oCellText.Segments.Add(oCellSeg)


    Tommy Wang
    Lead Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  08-12-2008, 4:42 PM 139428 in reply to 139091

    Re: Table, iterate, image

    Thanks...
     
View as RSS news feed in XML