droidText jar如何在android中设置重新调整大小的图像中的pdf

时间:2015-08-10 12:55:40

标签: android pdf

我在我的应用程序中使用droidText jar for PDF创建但我不能重新调整图像大小并在同一行中设置文本和图像。在我的代码中我可以用pdf获取图像但不能用我的大小设置。

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmimg.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());

PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.setWidths(new int[]{1, 2});

float documentWidth = 100;
float documentHeight = 100;
myImg.scaleToFit(documentWidth, documentHeight);

float leftMargin =  doc.getPageSize().getWidth() - myImg.getScaledWidth();
float lMargin = leftMargin / 2 ;
float topMargin =  doc.getPageSize().getHeight() - myImg.getScaledHeight(); 
float tMargin = topMargin / 2 ;
myImg.setAbsolutePosition(lMargin,tMargin);

table.addCell("\n\nRavi Vaghela");
table.addCell(myImg);

doc.add(table); 

2 个答案:

答案 0 :(得分:2)

罗宾

您可以尝试使用 scaleAbsolute()方法调整图像大小,

public string Index()
{
    EmployeeDbContext employeeDbContext = new EmployeeDbContext();
    employeeDbContext.Employees.ToList();
    return "Hello world";
}

对于同一行How to display image and text beside each other Itext

中的图像和文本

答案 1 :(得分:0)

我得到了解决方案。图像和文本设置在同一行并设置为图像修复大小。按照我的代码显示:

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmimg.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    myImg = Image.getInstance(stream.toByteArray());

    Paragraph p1 = new Paragraph("About Me::\n",catFont);
    p1.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(p1);


    Paragraph nk = new Paragraph("Nick Name",catFont);
    nk.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(nk);



    Paragraph p = new Paragraph(20); 
    p.add(new Chunk("RAVI", subFont)); 
    myImg.scalePercent(100); 
    p.add(new Chunk(myImg, 280.0f, -100.0f));
    doc.add(p); 


    Paragraph ppp = new Paragraph("SunSign",catFont);
    ppp.setAlignment(Paragraph.ALIGN_LEFT);
    doc.add(ppp);

使用chunk我们可以在pdf中添加图像并设置大小和位置。 这里的subFont和catFont是我在我的代码中声明的FONT。

相关问题