Free Support Forum - aspose.com

Laying out labels on PDF documents

Hi, I’ve looked at all the examples and can find no example of producing labels via Aspose PDF (not via Words). Here below is a short VB program that uses floating boxes since this will ensure that label contents will be contained within a pre-defined area and fixed to a specific location. Trouble is that the top left label is fine but the top right label appears on a new page. Also, if the text does exceed the box size it then appears on the next page! Please can you advise the best way to get labels at fixed positions and that any excess is lost rather than messing up another label. Finally, once the labels come from a data source, there needs to be a better way than creating floating boxes for every label. For info the labels in use are LP14 99 (2 across, 7 down). Thank you

    Dim PDFdoc As New Aspose.Pdf.Document("Label Planet LP14 99 Portrait.pdf") 'this has the outline of labels just for testing
    Dim PDFPageInfo As Aspose.Pdf.PageInfo = PDFdoc.PageInfo
    Dim PDFmarginInfo As Aspose.Pdf.MarginInfo = PDFPageInfo.Margin
    PDFmarginInfo.Left = 36
    PDFmarginInfo.Right = 36
    PDFmarginInfo.Top = 48
    PDFmarginInfo.Bottom = 48
    Dim box As New Aspose.Pdf.FloatingBox(250, 100)
    box.Top = 0
    box.Left = 0
    box.Paragraphs.Add(New Aspose.Pdf.Text.TextFragment("Name" & vbCrLf & "Job title" & vbCrLf & "Department" & vbCrLf & "CompanyCompanyCompanyCompanyCompanyCompanyCompany" & vbCrLf & "Address1" & vbCrLf & "Address2" & vbCrLf & "Address3" & vbCrLf & "Town" & vbCrLf & "County" & vbCrLf & "Postcode" & vbCrLf & "Country"))
    PDFdoc.Pages(1).Paragraphs().Add(box)
    Dim box2 = New Aspose.Pdf.FloatingBox(250, 100)
    box2.Top = 0
    box2.Left = 300
    box2.Paragraphs.Add(New Aspose.Pdf.Text.TextFragment("Name" & vbCrLf & "Job title" & vbCrLf & "Department" & vbCrLf & "CompanyCompanyCompanyCompanyCompanyCompanyCompany" & vbCrLf & "Address1" & vbCrLf & "Address2" & vbCrLf & "Address3" & vbCrLf & "Town" & vbCrLf & "County" & vbCrLf & "Postcode" & vbCrLf & "Country"))
    PDFdoc.Pages(1).Paragraphs().Add(box2)
    PDFdoc.Save("Label sample.pdf")

@msutherland25

Thank you for contacting support.

You may try Adding Text Stamp in the PDF File. A TextStamp will not move or disturb other text stamps based on their size or content.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thank you for your reply. Firstly, I am totally confused by the use of facades. Can facades be mixed with normal PDF DOM or must it be either facades or DOM? Also, text stamps seem to have many limitations themselves; firstly the text stamp does not constrain the size of the text (because they have no size), secondly by default, they repeat on each page etc etc.

Perhaps using tables is a better way forwards - if only I can get each cell to keep a specific size and the whole table to be in a precise position?

I’m used to Words and Cells, so PDF seems vastly more difficult to do anything basic. I am using Aspose.PDF since I don’t trust Word to not move the document and thus no longer print labels correctly.

Can you suggest a way to make PDF work for labels please

@msutherland25

Aspose.Pdf.Facades is an old model and is going to be obsolete soon, which is why we always recommend to use DOM (Document Object Model) approach that is more advanced and enhanced. However, Facades will be obsolete once all features will be supported by DOM. Therefore, you may use Facades approach as well as DOM approach in same program to achieve your requirements.

Moreover, TextStamp supports setting the font size as explained in suggested documentation article, but it is in-fact different than TextFragment. So adding Table and the text in table cells is better approach because TextFragment can be added to table cell. Please visit Add and Extract a Table for your kind reference.