标签: itextpdf

iTextPDF 库 - 找不到类“com.itextpdf.text.pdf.PdfAWriter”

在最新版本的 itextpad v5.4.0 中找不到类“com.itextpdf.text.pdf.PdfAWriter”。我什至尝试下载额外的罐子,但没有成功。

任何帮助将不胜感激。

itext itextpdf

2
推荐指数
1
解决办法
1万
查看次数

如何使用itextpdf生成pdf文件的页脚

我一直在网上搜索如何使用java中的itextpdf制作或设置页脚.直到现在我还没有找到任何关于如何做到这一点.我看过一些关于如何使用和设置标题的文章.但不是页脚.这是一个示例代码

Document document = new Document(PageSize.LETTER);

Paragraph here = new Paragraph();
Paragraph there = new Paragraph();

Font Font1 = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);

here.add(new Paragraph("sample here", Font1));
there.add(new Paragraph("sample there", Font1));
//footer here 

document.add(here);
document.add(there);
document.add(footer);
Run Code Online (Sandbox Code Playgroud)

java footer itextpdf

2
推荐指数
1
解决办法
1万
查看次数

PDF页面使用itext重新排序

我正在使用itext pdf库.任何人都知道如何在现有的PDF格式中移动页面?

实际上我想在文件开头移动几页.

它类似于下面,但我不明白它是如何工作的.

 reader = new PdfReader(baos.toByteArray());
 n = reader.getNumberOfPages();
 reader.selectPages(String.format("%d, 1-%d", n, n-1));
 PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(filename));
 stamper.close();
Run Code Online (Sandbox Code Playgroud)

任何人都可以详细解释一下吗?

java itext itextpdf

2
推荐指数
1
解决办法
3401
查看次数

我们如何从没有页眉和页脚的 PDF 文件中提取文本内容

我们如何从 PDF 文件中提取文本内容,我们正在使用 pdfbox 从 PDF 文件中提取文本,但我们不需要页眉和页脚。我正在使用以下 java 代码。

PDFTextStripper stripper = null;
  try {
    stripper = new PDFTextStripper();
   } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
   }
     stripper.setStartPage(pageCount);
     stripper.setEndPage(pageCount);
   try {
      String pageText = stripper.getText(document);
       System.out.println(pageText);  
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
 }
Run Code Online (Sandbox Code Playgroud)

java pdf itext pdfbox itextpdf

2
推荐指数
1
解决办法
4510
查看次数

将Drawable传递给iTextPdf而不是Image - Android

我正在使用iTextPdf创建一个签入应用程序.我已经使用图像对象添加了一个图像:

imagePath = "/sdcard/Mugshot.jpg";
Image image = Image.getInstance(imagePath);
image.setAbsolutePosition(165f, 465f);
image.scaleToFit(290f,290f);
document.add(image);
Run Code Online (Sandbox Code Playgroud)

我希望在添加任何内容之前以相同的方式添加图像,因为我预计任何后续内容都会覆盖现有内容.

android image itextpdf android-resources

2
推荐指数
1
解决办法
1552
查看次数

Itextpdf:在文本中间设置图像

我在段落中有一个文字我希望在文本中间设置一个图像:

public void createPdf(String dest, String imgSource) throws IOException, DocumentException {
    Document doc = new Document ();
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(dest));
    doc.open ();
    Paragraph p = new Paragraph();
    Image image1 = Image.getInstance(imgSource);
    p.add(new Chunk("This is my photo : "));
    p.add (image1);
    p.add(new Chunk(" so beautifull :)"));
    doc.add(p);
    doc.close();
}
Run Code Online (Sandbox Code Playgroud)

它是一个小图像(宽度= 100,高度= 50),但我的图像位于第二行.有可能这样设置:"这是我的照片:[IMAGE] so beautifull :)"

java itext itextpdf

2
推荐指数
1
解决办法
657
查看次数

嵌套的iText PdfPTable边框宽度

我正在使用iTextPdf生成pdf,我正在使用下面的代码创建嵌套表.

PdfPTable table = new PdfPTable(3);
PdfPTable nestedTable = new PdfPTable(2);
table.addCell(nestedTable);
Run Code Online (Sandbox Code Playgroud)

现在,我希望边框宽度为table0,即不可见.我已经检查了api和SO上的几个帖子,但我找不到任何实质性内容.有办法吗?

我正在使用iText版本5.1.2

java border itext itextpdf

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

无法识别带有Cp1252的DocumentException Arial

最近几个月,我使用字体Courier生成了成千上万的pdf(在Windows 7上进行开发,在OpenSuse进行测试和生产)。

现在我有了使用Arial的目标。所以我在属性文件中切换了字体名称,但出现了以下异常:

Stacktrace片段:com.itextpdf.text.DocumentException:无法识别带有'Cp1252'的字体'Arial'。在com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:708)在com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)在com.itextpdf.text.pdf.BaseFont.createFont (BaseFont.java:450)

谷歌一段时间后,我找到了解决方案。我只需要在设置中使用“ Arial.ttf”(如文件名)即可。但是之后,我又有了一个例外:

java.io.IOException: Arial.ttf not found as file or resource.
  at com.itextpdf.text.io.RandomAccessSourceFactory.createByReadingToMemory(RandomAccessSourceFactory.java:224)
  at com.itextpdf.text.io.RandomAccessSourceFactory.createBestSource(RandomAccessSourceFactory.java:173)
  at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:147)
  at com.itextpdf.text.pdf.TrueTypeFont.process(TrueTypeFont.java:625)
  at com.itextpdf.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:369)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:699)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)
  at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:450)
Run Code Online (Sandbox Code Playgroud)

因此,有一个提示,即itextpdf正在寻找文件。所以我只是将文件名输入C:\\Windows\\Fonts\\Arial.ttf到我们的配置中。现在可以了!

但是目标只是使用“ Arial”作为字体名称。可能吗?

非常感谢!

java itextpdf

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

iText PDF 正文内容在页脚部分重叠

我使用 itextpdf-5.5.3 版本。当我生成 PDF 并使用 PdfPTable 它重叠在页脚部分。

在此处输入图片说明

PDF的一些代码。

writer=PdfWriter.getInstance(document, out);
document.setPageSize(PageSize.A4);
document.setMargins(50, 45, 50, 40);
document.setMarginMirroring(false);

writer.setPageEvent(new HeaderAndFooter());
document.open();
Run Code Online (Sandbox Code Playgroud)

对于页脚,

public class HeaderAndFooter extends PdfPageEventHelper {
    private Font footerFont;
    public HeaderAndFooter() {
        super();
        footerFont = getFontObj(BaseColor.LIGHT_GRAY, 15);
        footerFont.setStyle(Font.ITALIC);
    }


    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        PdfContentByte canvas = writer.getDirectContent();
        canvas.rectangle(50, 30, 500, 780);
        canvas.setColorStroke(BaseColor.LIGHT_GRAY);
        canvas.stroke();

        PdfContentByte cb = writer.getDirectContent();
        footerFont.setSize(15);
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("____________________________________________________________",footerFont), ((document.left() + document.right())/2)+1f , document.bottom()+20, 0);
        ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(String.format("Page %d", writer.getPageNumber()),footerFont), (document.left() + …
Run Code Online (Sandbox Code Playgroud)

java itext itextpdf

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

ItextPdf :获取 Y 位置

我在我的项目中使用 itextpdf 5

我想为任何元素绘制一个变化栏。

我的方法drawBar接受输入Y1和Y2位置,如下所示:

drawBar(float y1, float y2, PdfWriter writer){
// draw bar
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何获取当前指针的 Y 位置。可行吗?

itext itextpdf

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

使用XmlWorker可以在TD内部标记工作吗?

<td>text text text</br>text text<td>
Run Code Online (Sandbox Code Playgroud)

是合法的HTML - 但它会导致XmlWorker 5.5.5和iText 5.5.5出错

com.itextpdf.tool.xml.exceptions.RuntimeWorkerException:找到无效的嵌套标记br,预期结束标记td.

如果你删除'br'然后代码工作,当然只有你没有获得多行行

这也没有通过在td css中使用white-space:pre并将'br'转换为回车来修复,因为iText会有效地忽略新行

这是一个特征/问题/从未被问过的事情吗?或者我错过了不在示例中的内容?

html文件... 链接

itext itextpdf

0
推荐指数
1
解决办法
6798
查看次数

标签 统计

itextpdf ×11

itext ×8

java ×7

android ×1

android-resources ×1

border ×1

footer ×1

image ×1

pdf ×1

pdfbox ×1