简体   繁体   中英

load an existing pdf in a C# application using iTextSharp

I need to know how do i load an existing .pdf ;say i have a .pdf in my local machine i added it to the location where i am creating a project i need to load this .pdf in my c# app and then i need to add some changes to it .

I created an empty c# project added an assembly info In the references i added the following

iTextSharp
Microsoft.CSharp
System
System.Data
System.Data.DataSetExtension
System.XML
System.XML.Ling

And a class as PdfClass.cs

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace contextcopypdf
{
     public class PdfClass
        {
            //function that loads an exisitng pdf
            public void LoadPdf()
            {
               string inputPdf = "sign.pdf";
               string outputPdf = "sign1.pdf";
               Pdfreader = new PdfReader(inputPDF);

            }
        }
 }

The IDE Is VS 2010 ultimate

Basically on this pdf i have got digital signature fields.

Thanks

You already have the code there that loads the pdf, change the path accordingly if needed.

        var path = @"c:\Templates\Invoice.pdf";

        var pdfReader = new PdfReader(path);

I see that your requirement is to digitally sign a PDF. Please read my book about digital signatures to make sure you do this correctly: http://itextpdf.com/book/digitalsignatures/

The examples in the book are in Java, but we've ported most of the examples to C#. You can find these examples here: http://sourceforge.net/p/itextsharp/code/

Browse for tutorial/signatures. Make sure you create CMS or CAdES signatures. The older flavors will be deprecated soon (or are already forbidden in PAdES).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM