标签: itextsharp

iTextSharp获得PDF DPI

如何将我从硬盘中读取的PDF的DPI转换为iTextSharp?

c# dpi itextsharp

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

iTextSharp GetFieldPositions到SetSimpleColumn

我正在使用最新版本的iTextSharp:http://sourceforge.net/projects/itextsharp/

我在使用GetFieldPositions(fieldName)获取某些AcroField的位置后尝试使用ColumnText.SetSimpleColumn.

我可以找到的所有示例都显示GetFieldPositions返回一个float []但是这似乎不再是这种情况了.它现在似乎是返回IList,它没有(根据Visual Studio)隐式转换为float [].

在0索引处的返回值内部是一个位置成员,它是一个Rectangle,但由于我见过的示例对返回的float []执行数学运算,我不确定GetFieldPostions中返回值的值是什么时候使用的使用SetSimpleColumn.这是我正在引用的一篇文章:http://blog.dmbcllc.com/2009/07/08/itextsharp-html-to-pdf-positioning-text/

最简单的接受答案是如何将值从GetFieldPositions转换为SetSimpleColumn.

谢谢!

.net c# pdf itext itextsharp

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

在itextSharp中使用LocationTextExtractionStrategy进行文本坐标

我的目标是从PDF中检索可能在表格结构中的数据到excel文件.

使用带有iTextSharp的LocationTextExtractionStrategy,我们可以以纯文本形式获取字符串数据,页面内容从左到右.

我怎样才能在这期间向前迈进

PdfTextExtractor.GetTextFromPage(reader,i,new LocationTextExtractionStrategy())

我可以使文本在结果字符串中保留其坐标.

例如,如果pdf中的第一行文本右对齐,则结果字符串必须包含尾随空格或空格,以保持内容右对齐.

请提出一些建议,我将如何继续实现同样的目标.

pdf excel itextsharp

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

使用PdfStamper添加矩形

嗨,我有一个使用itextsharp创建的pdf文件。

我使用pdfreader将创建的pdf读入pdfstamper。

现在,我尝试使用pdfstamper在所有页面上添加一个与页面大小相同的黑色矩形。我该怎么做呢?

另外,由于流关闭,我无法使用文档添加矩形!

    MemoryStream stream = new MemoryStream();

    PdfReader pdfReader = new PdfReader(output.ToArray());
    PdfStamper stamper = new PdfStamper(pdfReader, stream);

    for (int x = 0; x < stamper.Reader.NumberOfPages; x++)
    {
        Rectangle rectangle = document.PageSize;
        rectangle.BackgroundColor = new BaseColor(0, 0, 0);
        //stamper.Writer.AcroForm.
        //document.Add(rectangle);
    }

    output.Close();
    pdfReader.Close();
    stamper.Close();
Run Code Online (Sandbox Code Playgroud)

c# itextsharp

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

如何使用c#打开受密码保护的pdf

我想在c#.net windows应用程序面板或adobe reader中打开受密码保护的pdf.

我的想法是我想通过系统传递密码并打开pdf.用户可以看到pdf但无法保存.即使用户可以将我们保存在他们的计算机中,当他们重新打开pdf时,该文件也会询问密码.这意味着当他们想要阅读pdf时,他们必须使用系统,如果他们将pdf带到外面,他们就无法打开密码的cos.

我试过用Adobe Pdf dll,这个不能传递密码.而且我也试过用itextsharp,这个可以传递密码但是在传递密码之后,需要保存pdf.因此,当我打开pdf时,该文件没有密码.

我想通过系统直接打开受密码保护的pdf.我不想再保存.

c# pdf adobe password-protection itextsharp

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

使用iTextSharp将项目添加到现有PDF

将项目添加到现有PDF的正确方法是什么?方法GetFileBytes从磁盘读取PDF并转换为数组,这很好,但生成的文件NP.PDF与原始文件完全相同.我实际上想要添加条形码但是想要先尝试使用一个简单的项目.

Byte[] bytes = GetFileBytes();

Document document = new Document();
MemoryStream ms = new MemoryStream(bytes);

PdfWriter writer = PdfWriter.GetInstance(document, ms);
document.Open();

document.Add(new Paragraph("First Paragraph"));
document.Add(new Paragraph("Second Paragraph"));
//document.Close();
ms.Position = 0;

File.WriteAllBytes(@"e:\NP.pdf", (Byte[])ms.ToArray());
Run Code Online (Sandbox Code Playgroud)

itextsharp paragraph

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

PdfWriter.GetInstance抛出System.NullReferenceException

我正在尝试使用以下内容使用iTextSharp 5.3.4创建一个pdf文档

Document document = new Document();
FileStream stm = new FileStream(filename, FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(document, stm);
Run Code Online (Sandbox Code Playgroud)

我收到带有以下堆栈跟踪的System.NullReferenceException:

System.NullReferenceException occurred
HResult=-2147467261
Message=La référence d'objet n'est pas définie à une instance d'un objet.
Source=itextsharp
StackTrace:
   à iTextSharp.text.Version.GetInstance()
InnerException: 
Run Code Online (Sandbox Code Playgroud)

我已经验证了文件和stm都不为空,如果我在VS12中选择"继续",则会创建文档 - 但是总是抛出异常.我更新到iTextSharp 5.4.0并且它仍在发生.我无法在任何地方找到任何相关信息 - 任何人都有任何想法?

wpf itextsharp

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

奇数编号单元格未添加到Pdf

我试图PdfPCell在一个循环中添加一个Table带有2列的iTextSharp Document.但是如果循环内的计数是奇数.然后最后一个单元格没有被添加.有人可以提供这个问题的解决方案吗?我的代码如下:

        var doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("~/QrCodes/") + fileName + ".pdf", FileMode.Create));
        doc.Open();
        PdfPTable table = new PdfPTable(2);
        table.WidthPercentage = 100;

        foreach (var item in items)
        {
            if (itemImages.Any(p => p.Reference == item.Reference) == true)
            {
                System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(@item.ItemQrCode));
                iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, ImageFormat.Jpeg);

                PdfPCell cellImage = new PdfPCell(pdfImage);
                cellImage.HorizontalAlignment = Element.ALIGN_CENTER;
                cellImage.VerticalAlignment = Element.ALIGN_MIDDLE;
                cellImage.Border = 0;

                table.AddCell(cellImage);

            }

        }

        doc.Add(table);
        doc.Close();
Run Code Online (Sandbox Code Playgroud)

asp.net itextsharp

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

使用iTextSharp将文本添加到内存流中的现有多页PDF文档

我正在尝试使用iTextSharp将文本添加到现有的PDF文件中.我一直在阅读很多帖子,包括这里流行帖子.

我有一些不同之处:

  • 我的PDF长X页
  • 我希望将所有内容保存在内存中,并且永远不会将文件存储在我的文件系统中

所以我尝试修改代码,因此它接受一个字节数组并返回一个字节数组.我走到这一步:

  • 代码编译并运行
  • 我的out字节数组的长度与字节数组的长度不同

我的问题:

  • 当我稍后存储修改后的字节数组并在我的PDF阅读器中打开它时,我看不到我添加的文本

我不明白为什么.从我看到的每个StackOverflow帖子中,我都这样做.使用DirectContent,我使用BeginText和写一个文本.然而,无论我如何移动位置,我都看不到它.

知道我的代码中缺少什么吗?

public static byte[] WriteIdOnPdf(byte[] inPDF, string str)
        {
            byte[] finalBytes;

            // open the reader
            using (PdfReader reader = new PdfReader(inPDF))
            {
                Rectangle size = reader.GetPageSizeWithRotation(1);
                using (Document document = new Document(size))
                {
                    // open the writer
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (PdfWriter writer = PdfWriter.GetInstance(document, ms))
                        {
                            document.Open();

                            for (var i = 1; i <= reader.NumberOfPages; i++)
                            { …
Run Code Online (Sandbox Code Playgroud)

c# pdf stream itextsharp c#-4.0

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

将iTextSharp PDF作为内存流返回会导致StreamNotSupported

我正在使用iTextSharp中的PdfStamper创建一个PDF文件,并将PDF作为内存流对象返回到调用函数,然后用于在WinForms的Teleriks PDF Viewer Component中显示PDF.

这是目标.

现在,创建PDF可以正常工作,并将数据返回给Calling函数,在Calling函数中,我应该将memorystream内容写入文件流,然后在Adobe Reader中打开它看起来很好.

但是,如果我选择在PDF查看器控件中显示PDF,我只会收到"不支持的流类型"错误.

现在,我认为PDF数据有问题所以我决定创建PDF文件,将其保存到磁盘,然后在Calling函数中将其读取到内存流,并在PDF Viewer中显示该内存流,对于我来说不明原因,作品....

我真的无法理解这一点并需要一些帮助.

所以,这将无法正常工作:

//The Calling function
private void dlgViewPDF_Load(object sender, EventArgs e)
{
    MemoryStream ms = PDFcreator.GeneratePDFdata(id);

   rPdfView.LoadDocument(ms);
}

//The PDF generator
public static MemoryStream GeneratePDFdata(string id)
{
    MemoryStream ms = new MemoryStream();

    string sTemplate = string.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "\\template.pdf");

    PdfReader pdfReader = new PdfReader(sTemplate);
    PdfStamper pdfStamper = new PdfStamper(pdfReader, ms);

    PdfContentByte cb = pdfStamper.GetOverContent(1);

    BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    BaseFont baseFontBold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.EMBEDDED);
    cb.SetColorFill(iTextSharp.text.Color.BLACK);
    cb.SetFontAndSize(baseFontBold, 14);

    cb.BeginText(); …
Run Code Online (Sandbox Code Playgroud)

c# pdf telerik itextsharp winforms

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

标签 统计

itextsharp ×10

c# ×6

pdf ×5

.net ×1

adobe ×1

asp.net ×1

c#-4.0 ×1

dpi ×1

excel ×1

itext ×1

paragraph ×1

password-protection ×1

stream ×1

telerik ×1

winforms ×1

wpf ×1