小编shr*_*ity的帖子

创建一个矩形,在其中添加段落并使用 iText 根据文本调整矩形的高度

我能够创建一个矩形并在其中添加段落和图像。矩形的宽度也不错,但我只想根据段落中的文本设置矩形的高度。此外,我想以特定方式在矩形内添加数据,这就是我在其中创建表的原因。那么如何让表格填满整个矩形。有人可以帮我解决这个问题吗?

        PdfContentByte cb = writer.getDirectContent();

        Rectangle rect = new Rectangle(kBorderInset, document.getPageSize().getHeight()-kPageDisclaimerY,
                document.getPageSize().getWidth()-2 * kBorderInset,700f);
        cb.rectangle(rect);
        cb.stroke();

        rect.setBorder(Rectangle.BOX);
        rect.setBorderWidth(1);
        rect.setBorderColor(BaseColor.BLACK);
        cb.rectangle(rect);

        ColumnText ct = new ColumnText(cb);
        ct.setSimpleColumn(rect);
        ct.addElement(createTable1(auditBundle, context));
        ct.go();
Run Code Online (Sandbox Code Playgroud)

创建表代码

       private static PdfPTable createTable1(AuditBundle auditBundle, Context context) throws 
       DocumentException {
           PdfPTable table = new PdfPTable(3);
           table.setWidthPercentage(100);
           table.getDefaultCell().setUseAscender(true);
           table.getDefaultCell().setUseDescender(true);
           table.getDefaultCell().setFixedHeight(112f);
           table.setWidths(new int[]{1, 2, 1});

    float fntSize, lineSpacing;
    fntSize = 20f;
    lineSpacing = 12f;
    Paragraph paragraph = new Paragraph();
    paragraph.add(new Phrase(lineSpacing,auditBundle.getAudit().auditName,
            FontFactory.getFont(FontFactory.HELVETICA, fntSize)));
    paragraph.setAlignment(Element.ALIGN_LEFT | Element.ALIGN_CENTER);
    paragraph.setPaddingTop(30);
    PdfPCell cell = new PdfPCell(); …
Run Code Online (Sandbox Code Playgroud)

pdf android itext

6
推荐指数
1
解决办法
178
查看次数

想要创建一个带有矩形作为页眉和页脚中的段落以及正文中的部分的表单的pdf

我想创建一个有点像这样的pdf

我写到现在的代码如下:

public class HeaderFooterEvent extends PdfPageEventHelper {
    @Override
    public void onStartPage(PdfWriter writer, Document document) {
    }

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        addHeader(writer, document);
        addHeader2(writer, document);
        addFooter(writer, document);
    }

    void addHeader(PdfWriter writer, Document document){
        try {
            PdfContentByte cb = writer.getDirectContent();

            // the initial rectangle defines the max size of the content
            rect = new Rectangle(10, document.getPageSize().getBottom() + 50,
                    document.getPageSize().getWidth() - 2 * 10, document.getPageSize().getTop() - 50);

     // flip the rectangle if top and bottom were switched
            rect.normalize();

            ColumnText …
Run Code Online (Sandbox Code Playgroud)

pdf android itext

6
推荐指数
1
解决办法
255
查看次数

通过从应用程序设置切换按钮来启用或禁用FCM推送通知

我已在我的应用中通过Firebase实施了推送通知.即使从设置中禁用通知,通知也会到来.我为Firebase实施的课程是:

    public class MyFirebaseMessagingService extends FirebaseMessagingService {

            private static final String TAG = "MyFirebaseMsgService";
            @Override
            public void onMessageReceived(RemoteMessage remoteMessage) {

                //Displaying data in log

                Log.e(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
                //Calling method to generate notification

                String to="";
                to = remoteMessage.getData().get("key1");

        //when the notification is disabled then also the notification is coming
     if(notification_enable) {
    sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody(),to);
           }
        }

            //This method is only generating push notification
            //It is same as we did in earlier posts
            private void sendNotification(String title,String messageBody,String to) { …
Run Code Online (Sandbox Code Playgroud)

android push-notification firebase firebase-cloud-messaging

4
推荐指数
1
解决办法
9342
查看次数