iTextSharp的如何添加一个完整的换行符 [英] itextsharp how to add a full line break

查看:1864
本文介绍了iTextSharp的如何添加一个完整的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用iTextSharp的,我需要从左边到页面(100%宽度)的权利,但不知道如何画虚线断行。该文档总是有左,右的余量。请帮

  VAR的pageSize = PageSize.A4; 

如果(_pdfSettings.LetterPageSizeEnabled)
{
的pageSize = PageSize.LETTER;
}


变种DOC =新的文件(pageSize的);
PdfWriter.GetInstance(文件,流);
doc.Open();

//字体

VAR titleFont = GETFONT();
titleFont.SetStyle(Font.BOLD);
titleFont.Color = BaseColor.BLACK;
titleFont.Size = 16;

VAR largeFont = GETFONT();
largeFont.SetStyle(Font.BOLD);
largeFont.Color = BaseColor.BLACK;
largeFont.Size = 18;

INT ordCount = orders.Count;
INT ordNum = 0;

的foreach(订单VAR顺序)
{

变种addressTable =新PdfPTable(3);
addressTable.WidthPercentage = 100F;
addressTable.SetWidths(新[] {25,37,37});


//发件人地址

细胞=新PdfPCell();
//cell.Border = Rectangle.NO_BORDER;
cell.AddElement(新段(Người桂,titleFont));
cell.AddElement(新第(_localizationService.GetResource(admin.orders.pdfinvoice.sender,lang.Id),smallFont));
cell.AddElement(新第(_localizationService.GetResource(admin.orders.pdfinvoice.senderaddress,lang.Id),smallFont));
cell.AddElement(新第(_localizationService.GetResource(PDFInvoice.Hotline,lang.Id),smallFont));
cell.AddElement(新段(TAKARA.VN,largeFont));

addressTable.AddCell(单元);

......
块断行=新的块(新DottedLineSeparator());
doc.Add(断行);

doc.Add(新段());
....
}


解决方案

请看看这个例子 FullDottedLine



您正在创建一个 DottedLineSeparator 其宽度百分比为100%,默认情况下。这100%是完整的可用宽度的 withing页的的边缘。如果希望线超过可用宽度,则需要一个百分比高于100%的



在该示例中,缺省页大小(A4)和默认边距(36)被使用。这意味着,在网页的宽度为595用户单元和可用的宽度等于595 - (2×36)的用户单元。 ,跨越页的整个宽度所需的百分比等于100×(523分之595)



看看生成的PDF文件的 full_dotted_line.pdf ,你会看到,现在行通过利润运行。


I use itextsharp and i need to draw a dotted linebreak from left to right of the page(100% width) but don't know how. The doc always has a margin left right. Please help

var pageSize = PageSize.A4;

        if (_pdfSettings.LetterPageSizeEnabled)
        {
            pageSize = PageSize.LETTER;
        }


        var doc = new Document(pageSize);
        PdfWriter.GetInstance(doc, stream);
        doc.Open();

        //fonts

        var titleFont = GetFont();
        titleFont.SetStyle(Font.BOLD);
        titleFont.Color = BaseColor.BLACK;
        titleFont.Size = 16;

        var largeFont = GetFont();
        largeFont.SetStyle(Font.BOLD);
        largeFont.Color = BaseColor.BLACK;
        largeFont.Size = 18;

        int ordCount = orders.Count;
        int ordNum = 0;

        foreach (var order in orders)
        {

            var addressTable = new PdfPTable(3);
            addressTable.WidthPercentage = 100f;
            addressTable.SetWidths(new[] { 25, 37, 37 });


            // sender address

            cell = new PdfPCell();
            //cell.Border = Rectangle.NO_BORDER;
            cell.AddElement(new Paragraph("Người Gửi", titleFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("admin.orders.pdfinvoice.sender", lang.Id), smallFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("admin.orders.pdfinvoice.senderaddress", lang.Id), smallFont));
            cell.AddElement(new Paragraph(_localizationService.GetResource("PDFInvoice.Hotline", lang.Id), smallFont));
            cell.AddElement(new Paragraph("TAKARA.VN", largeFont));

            addressTable.AddCell(cell);

            ......
           Chunk linebreak = new Chunk(new DottedLineSeparator());
                doc.Add(linebreak);   

                doc.Add(new Paragraph(""));
           ....
}

解决方案

Please take a look at the example FullDottedLine.

You're creating a DottedLineSeparator of which the width percentage is 100% by default. This 100% is the full available width withing the margins of the page. If you want the line to exceed the available width, you need a percentage that is higher than 100%.

In the example, the default page size (A4) and the default margins (36) are used. This means that the width of the page is 595 user units and the available width equals 595 - (2 x 36) user units. The percentage needed to span the complete width of the page equals 100 x (595 / 523).

Take a look at the resulting PDF file full_dotted_line.pdf and you'll see that the line now runs through the margins.

这篇关于iTextSharp的如何添加一个完整的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆