This is a migrated thread and some comments may be shown as answers.

PDF - Static Width, Dynamic Length

3 Answers 248 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Veteran
Johannes asked on 06 Jun 2019, 01:04 AM

I've recently been given the task of turning some labels that we use to put on hardcopy documents into format that can be printed with a small label printer that takes 62mm label tape.

Basically, the user types all the data for the label into a form. I then store the details for them in a grid. When they are ready to print the label, they click a print button that is in my grid. The data for the label is put into a pdf and they print it from the pdf.

The label printer uses a continuous roll or tape so that the text fields can be as long as they want. I'm currently putting all the details into a Table object and then I draw the table with a width of 62mm.

How can I find what the height of the table would be when the width is 62mm so that I can set the height of the page?

 

public RadFixedDocument CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage page = document.Pages.AddPage();
            page.Size = new Size(Telerik.Windows.Documents.Media.Unit.MmToDip(62), Telerik.Windows.Documents.Media.Unit.MmToDip(100));
            FixedContentEditor editor = new FixedContentEditor(page);

            Table table = CreateDetailsTable();
                        
            editor.DrawTable(table, Telerik.Windows.Documents.Media.Unit.MmToDip(62));

            return document;
        }

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 06 Jun 2019, 11:13 AM
Hello Johannes,

Thank you for your interest in Telerik Document Processing.

You can achieve this by measuring the table size after the table content is added and use the DesiredSize property to get the height of the table:
RadFixedDocument document = new RadFixedDocument();
 
Table table = CreateDetailsTable();
 
double widthInDip = Telerik.Windows.Documents.Media.Unit.MmToDip(62);
table.Measure(new Size(widthInDip, double.PositiveInfinity));
 
RadFixedPage page = document.Pages.AddPage();
page.Size = new Size(widthInDip, table.DesiredSize.Height);
 
FixedContentEditor editor = new FixedContentEditor(page);
editor.DrawTable(table, widthInDip);

I hope this helps.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Johannes
Top achievements
Rank 1
Veteran
answered on 07 Jun 2019, 01:05 AM
Perfect. thanks for the quick response.
0
Georgi
Telerik team
answered on 11 Jun 2019, 12:31 PM
Hi Johannes,

I am happy to hear the proposed solution works for you.

Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfProcessing
Asked by
Johannes
Top achievements
Rank 1
Veteran
Answers by
Georgi
Telerik team
Johannes
Top achievements
Rank 1
Veteran
Share this question
or