标签: itextsharp

有没有办法用itextsharp替换PDF文件中的文本?

我正在使用itextsharp生成PDF,但我需要动态更改一些文本.我知道如果有任何AcroField可以改变,但我的PDF doen有任何一个.它只有一些纯文本,我需要改变其中的一些.

有谁知道怎么做?

c# itextsharp

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

使用iTextSharp从PDF删除第一页

有没有办法可以使用iTextSharp删除PDF的第一页?

c# itextsharp

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

使用iTextSharp将表单域的不同部分设置为具有不同的字体

我不确定这是可能的,但我认为值得一提.我已经弄清楚如何使用pdfstamper和acrofields方法设置一个formfield的字体,但我真的希望能够在同一个字段中设置文本的不同部分的字体.这是我如何设置当前表单字段的字体:

            // Use iTextSharp PDF Reader, to get the fields and send to the 
            //Stamper to set the fields in the document
            PdfReader pdfReader = new PdfReader(fileName);

            // Initialize Stamper (ms is a MemoryStream object)
            PdfStamper pdfStamper = new PdfStamper(pdfReader, ms);

            // Get Reference to PDF Document Fields
            AcroFields pdfFormFields = pdfStamper.AcroFields;

            //create a bold font
            iTextSharp.text.Font bold = FontFactory.GetFont(FontFactory.COURIER, 8f, iTextSharp.text.Font.BOLD);

            //set the field to bold
            pdfFormFields.SetFieldProperty(nameOfField, "textfont", bold.BaseFont, null);

            //set the text of the form field
            pdfFormFields.SetField(nameOfField, "This: …
Run Code Online (Sandbox Code Playgroud)

.net c# pdf fonts itextsharp

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

代码没有在我的PDF中绘制水平线

我正在尝试在顶部添加一条水平线,以将标题文本与我的pdf文件中的实际值分开: 在此输入图像描述

这是我的代码:

public class StudentList
{
    public void PrintStudentList(int gradeParaleloID)
    {
        StudentRepository repo = new StudentRepository();
        var students = repo.FindAllStudents()
                            .Where(s => s.IDGradeParalelo == gradeParaleloID);

        try
        {
            Document document = new Document(PageSize.LETTER);

            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Alumnos.pdf", FileMode.Create));
            document.Open();

            PdfContentByte cb = writer.DirectContent;
            cb.SetLineWidth(2.0f);   // Make a bit thicker than 1.0 default
            cb.SetGrayStroke(0.95f); // 1 = black, 0 = white
            cb.MoveTo(20, 30);
            cb.LineTo(400, 30);
            cb.Stroke();

            PdfPTable table = new PdfPTable(3);                
            float[] widths = new float[] { 0.6f, …
Run Code Online (Sandbox Code Playgroud)

c# itextsharp

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

PDF格式的希伯来文

我写了一个PDF文档,我尝试用希伯来语(UTF-8)编写,我不能在Windows窗体中使用C#和Visual Studio 2010使用以下代码.

Document Doc = new Document(PageSize.LETTER);

//Create our file stream
using (FileStream fs = new FileStream("C:\\Users\\moshe\\Desktop\\Test18.pdf", FileMode.Create, FileAccess.Write, FileShare.Read))
{
    //Bind PDF writer to document and stream
    PdfWriter writer = PdfWriter.GetInstance(Doc, fs);

    //Open document for writing
    Doc.Open();

    //Add a page
    Doc.NewPage();

    //Full path to the Unicode Arial file
    string ARIALUNI_TFF = Path.Combine("C:\\Users\\moshe\\Desktop\\proj\\gold\\fop\\gold", "ARIAL.TTF");

    //Create a base font object making sure to specify IDENTITY-H
    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

    //Create a specific font object
    iTextSharp.text.Font f = new …
Run Code Online (Sandbox Code Playgroud)

c# pdf itextsharp winforms

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

如何将BouncyCastle X509Certificate转换为X509Certificate2?

有没有办法将a转换Org.BouncyCastle.X509.X509CertificateSystem.Security.Cryptography.X509Certificates.X509Certificate2

逆操作很容易,结合Org.BouncyCastle.X509.X509CertificateParser使用 System.Security.Cryptography.X509Certificates.X509Certificate2.Export().

.net c# bouncycastle itextsharp

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

如何在现有pdf文件中将图像设置为pdf字段?

在此输入图像描述

如何在现有pdf文件中将图像设置为pdf字段?

我正在使用iTextSharp对象.

设置文本字段工作正常.没问题.

   pdfFormFields.SetField("Firstname", "Mujeeb");
Run Code Online (Sandbox Code Playgroud)

请帮忙.

c# itextsharp

6
推荐指数
2
解决办法
7847
查看次数

如何在iTextSharp中将PDF转换为文本文件

我必须从PDF文件中检索文本.但是使用下面的代码我只得到空文本文件.

for (int i = 0; i < n; i++)
{
    pagenumber = i + 1;
    filename = pagenumber.ToString();
    while (filename.Length < digits) filename = "0" + filename;
    filename = "_" + filename;
    filename = splitFile + name + filename;
    // step 1: creation of a document-object
    document = new Document(reader.GetPageSizeWithRotation(pagenumber));
    // step 2: we create a writer that listens to the document
    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename + ".pdf", FileMode.Create));

    // step 3: we open the document
    document.Open(); …
Run Code Online (Sandbox Code Playgroud)

c# pdf itextsharp

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

如何使用iTextSharp确定PDF文件类型

有没有办法确定PDF文件的类型:如果现有PDF文件是扫描图像,或者是否使用iTextSharp和C#从数据文件创建?

c# pdf itextsharp

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

ITextSharp PDFTemplate FormFlattening删除填充的数据

我正在将现有的应用程序从Java移植到C#.原始应用程序使用IText库填充PDF表单模板并将其另存为新PDF.我的C#代码(示例)如下:

string templateFilename = @"C:\Templates\test.pdf"; 
string outputFilename = @"C:\Output\demo.pdf";

using (var existingFileStream = new FileStream(templateFilename, FileMode.Open))
{
    using (var newFileStream = new FileStream(outputFilename, FileMode.Create))
    {
        var pdfReader = new PdfReader(existingFileStream);
        var stamper = new PdfStamper(pdfReader, newFileStream);

        var form = stamper.AcroFields;
        var fieldKeys = form.Fields.Keys;

        foreach (string fieldKey in fieldKeys)
        {
            form.SetField(fieldKey, "REPLACED!");
        }

        stamper.FormFlattening = true;
        stamper.Close();
        pdfReader.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

只有我省略了,所有这些都很有效

stamper.FormFlattening = true;
Run Code Online (Sandbox Code Playgroud)

行,但然后表单可见为...表单.当我添加此行时,设置为表单字段的任何值都将丢失,从而产生一个空白表单.我真的很感激任何建议.

c# itextsharp

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

标签 统计

c# ×10

itextsharp ×10

pdf ×4

.net ×2

bouncycastle ×1

fonts ×1

winforms ×1