标签: itextsharp

如何调整字体大小以填充iTextSharp中的固定高度表格单元格

我正在从iTextSharp创建一个PDF进行打印.我有可变长度的文本,我希望始终使用最大字体大小来填充固定高度的表格单元格而不会看不到视线.如何才能做到这一点?

itextsharp

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

将文字放在图像上?

我需要以pdf格式插入图像,然后将文本放在图像顶部的某个坐标处.

iTextSharp可以实现吗?

itextsharp

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

HTML to PDF土耳其语字符问题

我想使用ITextSharp将ASP.NET网页转换为pdf.我写了一些代码,但我不能让它显示土耳其字符.谁能帮我?

这是代码:

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

using System.Web.UI;
using System.Web;
using iTextSharp.text.html.simpleparser;
using System.Text;
using System.Text.RegularExpressions;

namespace Presentation
{
    public partial class TemporaryStudentFormPrinter : System.Web.UI.Page
    {
        protected override void Render(HtmlTextWriter writer)
        {
            MemoryStream mem = new MemoryStream();
            StreamWriter twr = new StreamWriter(mem);
            HtmlTextWriter myWriter = new HtmlTextWriter(twr);
            base.Render(myWriter);
            myWriter.Flush();
            myWriter.Dispose();
            StreamReader strmRdr = new StreamReader(mem);
            strmRdr.BaseStream.Position = 0;
            string pageContent = strmRdr.ReadToEnd();
            strmRdr.Dispose();
            mem.Dispose();
            writer.Write(pageContent);
            CreatePDFDocument(pageContent);
        }
        public void CreatePDFDocument(string strHtml)
        {
            string strFileName = HttpContext.Current.Server.MapPath("test.pdf"); …
Run Code Online (Sandbox Code Playgroud)

pdf turkish character-encoding itextsharp

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

如何使用iTextSharp 4.0.2将默认缩放设置为100%?

我希望PDF阅读器(Adobe Reader)打开PDF文件,缩放自动设置为100%.

谢谢!

c# pdf acrobat itextsharp page-zoom

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

如何在ItextSharp(PdfStamper)中增加PDF字段的字体大小?

我正在使用PdfStamper在运行时创建PDF.我的问题是我无法增加PDF字段的字体大小.我试过这个,但没有运气,

stamper.AcroFields.SetFieldProperty("names", "textsize", 4f, null);
Font font = FontFactory.GetFont(FontFactory.COURIER, 2f, iTextSharp.text.Font.BOLD);    
stamper.AcroFields.AddSubstitutionFont(font.BaseFont);
Run Code Online (Sandbox Code Playgroud)

c# pdf itextsharp c#-4.0

3
推荐指数
2
解决办法
7749
查看次数

展平后AcroForm值丢失

我正在使用LibreOffice 4.1.3.2生成可填写的PDF:

  1. 创建了一个Writer文档
  2. 设置一些文本和测试字段
  3. 导出为PDF

使用Acrobar Reader打开pdf文件显示正确的可填写pdf.
接下来我使用iTextSharp 5.4.5填充字段并保存展平文档:

var pdf = new PdfReader(srcFilename);
using (var fw = new FileStream(dstFilename, FileMode.Create))
{
    var stamper = new PdfStamper(pdf, fw);
    var f = stamper.AcroFields;

    f.SetField("field1", "John Doe");
    f.SetField("field2", "12/04/2013");
    stamper.FormFlattening = true;
    stamper.Close();
}
pdf.Close();
Run Code Online (Sandbox Code Playgroud)

问题是填充的字段值在新文档中完全消失!
我认为没有找到或填充字段,但发现stamper.FormFlattening = true在保存的pdf中有评论字段值!
当然,我需要一个扁平化的PDF格式...

这有解决方案吗?

c# itextsharp acrofields

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

在pdf文档中没有顺序添加图像itextsharp(元素顺序错误)

我正在使用iTextSharp(5.4.5)几个星期了.本周,我遇到了一些奇怪的事情,它涉及到文档中元素的顺序.

我正在制作一份包含主题和图片(图表)的pdf报告.

文档的格式如下:

NR.主题标题1

主题1的CHART IMAGE(来自bytearray)

NR.主题2的主题标题

主题2的CHART IMAGE ...

下面是一个代码示例.我知道代码不完全正确,但它只是指出问题.让我们假设循环运行10次,所以我希望10个主题标题都直接跟随图像.

我注意到的是,如果到达页面结束并且应该添加新的IMAGE,则图像将移动到下一页,并且下一个主题标题将打印在上一页上.

所以在纸上我们有:

第1页:

主题1图像主题1

主题2图像主题2

主题3主题4

第2页:

图像主题3图像主题4

主题5图像主题5

...

因此,纸上元素的顺序与我通过Document.add方法将元素放在文档中的顺序不同.

这真的很奇怪.任何人有任何想法?

int currentQuestionNr = 0;
foreach (Topic currentTOPIC in Topics)
{
    currentQuestionNr++;

    //compose question (via table so all questions (with nr prefix) are aligned the same)
    PdfPTable questionTable = new PdfPTable(2);
    questionTable.WidthPercentage = 100;
    questionTable.SetWidths(new int[] { 4, 96 });

    PdfPCell QuestionNrCell = new PdfPCell();
    QuestionNrCell.BorderWidth = 0;
    QuestionNrCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
    QuestionNrCell.VerticalAlignment = PdfPCell.ALIGN_TOP;
    QuestionNrCell.AddElement(new Paragraph(String.Format("{0}. ", currentQuestionNr), …
Run Code Online (Sandbox Code Playgroud)

itext itextsharp

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

为什么FontFactory.GetFont("已知字体名称",floatSize)不起作用?

如果我说:

var georgia = FontFactory.GetFont("Georgia Regular", 10f);
Run Code Online (Sandbox Code Playgroud)

它不起作用.当我检查变量georgia的状态时,它的Family属性设置为值UNDEFINED,其FamilyName属性设置为Unknown.

它只有在我实际加载并注册字体文件然后得到它时才有效:

FontFactory.Register("C:\\Windows\\Fonts\\georgia.ttf", "Georgia");
var georgia = FontFactory.GetFont("Georgia", 20f);
Run Code Online (Sandbox Code Playgroud)

这是为什么?

c# itextsharp

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

将AcroField文本大小设置为自动

使用itextsharp,我试图将表单的文本字段的字体大小设置为auto.

我现在正在做这样的事情:

Object d = 0.0;

PdfReader reader = new PdfReader(path);

byte [] pdf;

using (var ms = new MemoryStream())
{
    PdfStamper stamper = new PdfStamper(reader, ms);

    AcroFields fields = stamper.AcroFields;

    foreach (var f in fields.Fields.Keys)
    {
        fields.SetFieldProperty(f, "textsize", d, null);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

System.InvalidCastException: Specified cast is not valid.
at iTextSharp.text.pdf.AcroFields.SetFieldProperty(String field, String name, Object value, Int32[] inst)
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

itext itextsharp acrofields

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

iTextSharp - 段落线高度

我目前正在研究PDF,但我正面临着试图增加a的行高的问题Paragraph,这是我现在的代码:

var tempTable = new PdfPTable(1);

cell = new PdfPCell(new Paragraph("My Account", GetInformationalTitle()));
cell.Border = Rectangle.NO_BORDER;
tempTable.AddCell(cell);

cell = new PdfPCell(new Paragraph("http://www.google.com/", GetInformationalOblique()));
cell.Border = Rectangle.NO_BORDER;
cell.PaddingBottom = 10f;
tempTable.AddCell(cell);

var para = new Paragraph("Login to 'My Account' to access detailed information about this order. " +
"You can also change your email address, payment settings, print invoices & much more.", GetInformationalContent());
 para.SetLeading(0f, 2f);

 cell = new PdfPCell(para);
 cell.Border = Rectangle.NO_BORDER;
 tempTable.AddCell(cell);
Run Code Online (Sandbox Code Playgroud)

正如你从上面所看到的,我正在尝试增加行高para,我已经尝试了para.SetLeading(0f, 2f)但它仍然没有增加行高或行距,因为它被称为. …

c# pdf pdf-generation typography itextsharp

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