Tech Off Thread

80 posts

Conversation Locked

This conversation has been locked by the site admins. No new comments can be made.

ASP.NET and iTextSharp (free PDF Generator for .NET)

Back to Forum: Tech Off
  • ManniAT

    Hi Guys,

    I'm new to iTextSharp (and general PDF devel).
    Can anyboy give me some "startup" how to digital sign a PDF document?
    As far as I know signed PDFs there are two kinds of.
    One is simply signed - and the other one is a "Certified Document".

    In Acrobat I get asked (when I am the first signer) if I want to certify the document.

    And furtheron  - there tow kinds of signing - one is with a visible signature - and one is without it.

    My primary goal is to
    a.) open an existing PDF
    b.) select a certificate from the users CertStore (CryptoAPI)
    c.) create a "Certified document" with the selected key
    d.) place a visula representation of it on the last page of the document.

    Regards

    Manfred

  • sbc

    While this is java code, it should be easily ported to C#.

    http://itextpdf.sourceforge.net/howtosign.html

  • ManniAT

    Hi,

    thanks for that hint - I will give it a try!

    By the way I did not find this site till now - I always was on lowagie.com Perplexed

    Thanks again

    Manfred

  • rocsky

    you can get more information about iTextsharp tutorial(both C# version and VB.NET version ) from http://hardrock.cnblogs.com

     

  • joachim

    rocsky wrote:

    you can get more information about iTextsharp tutorial(both C# version and VB.NET version ) from http://hardrock.cnblogs.com



    Yeah - as long as you can understand this:

    下类文件,为类构造函数增加了一个参数以便用户可以方便的在使用的时候设置配置文件路径,这样就可以把这个类包放置在任何可以被访问到的目录下,否则原来的版本下引用class.Chinese.php的文件必须和class在相同的目录下面才行。

    Perplexed

  • sbc

    joachim wrote:
    rocsky wrote:

    you can get more information about iTextsharp tutorial(both C# version and VB.NET version ) from http://hardrock.cnblogs.com



    Yeah - as long as you can understand this:

    下类文件,为类构造函数增加了一个参数以便用户可以方便的在使用的时候设置配置文件路径,这样就可以把这个类包放置在任何可以被访问到的目录下,否则原来的版本下引用class.Chinese.php的文件必须和class在相同的目录下面才行。


    According to translate.dictionary.com that is (assuming simplified chinese)

    translation wrote:
    下类 the document, increased a parameter for the kind of structure function in order to the user may facilitate in the use time establishment disposition document way, like this may lay aside this kind of package in any may under the table of contents which visits, otherwise under the original edition quotes class.Chinese.php the document to have only then to be good with class under the same table of contents.

  • Filth

    Hi,

    I've just starting using iTextSharp in a code behind page, but when I run it, it just shows a empty pdf.

    I was wondering if anyone could see anything crazy that I have or haven't done?

    The code in my page_load event is:

    MemoryStream m = new MemoryStream();

    Document document = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);

    try

    {

    Response.ContentType = "application/pdf";

    PdfWriter.GetInstance(document, m);

    document.Open();

    document.Add(new Paragraph(DateTime.Now.ToString()));

    document.Add(new Paragraph("This is another test"));

    document.Add(new Paragraph("Yet another test"));

    }

    catch (DocumentException ex)

    {

    Console.Error.WriteLine(ex.StackTrace);

    Console.Error.WriteLine(ex.Message);

    }

    // step 5: Close document

    document.Close();

    // step 6: Write pdf bytes to outputstream

    Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);

    Response.OutputStream.Flush();

    Response.OutputStream.Close();

  • sbc

    Have you tried it without the try / catch?

  • kldwhite

    Hi All,

    I'm just getting my feet wet with ASP.NET & VB.NET so please bear with me.

    I managed to get my web app to kick out PDFs of various sections of a report using 14 Crystal Reports, each of which has subreports.  I figured I'd be able to embed each section report into one master report to have all 14 sections all bundled into one PDF.  Alas, the subreports in each section don't appear in my final CR report.  Hunting around seems to indicate that CR XI Rel 2 and previous can't handle nested subreports.

    The only other way I can think to do this is to kick out all 14 PDFs and try to concatenate them together, perhaps using iTextSharp.

    Looking at the tutorials referenced previously, I see a command-line example of doing this, but not a way that my wee brain can see to do so in VB.NET on my ASPX page once I've generated the PDFs.

    Any pointers to any examples would be most welcome.

    DW

  • emranashraf

    Dear All

    I'm using iTextSharp to create PDF file in my ASP.NET Page. I'm using True Type Font(Amazone BT) in this pdf file.

    The Problem is When I deploy this application on the server. On the server Its running fine but when I run this web application from a  client machine it changes the font. 

    It runs fine if i copy the font on client as well. But its a web application so we cannot copy the font on every client if we are using on the internet.

    So how can it possible PDF file should use the font from server not from client machine.

    please help me!


    Thanks
    Imran Ashraf
     

  • rocsky

                PdfWriter writer =PdfWriter.GetInstance(doc,ms);
                writer.CloseStream=false;


    for detail :
    http://hardrock.cnblogs.com/archive/2006/02/23/336397.html


    http://hardrock.cnblogs.com

  • rocsky

    emranashraf wrote:
    Dear All

    I'm using iTextSharp to create PDF file in my ASP.NET Page. I'm using True Type Font(Amazone BT) in this pdf file.

    The Problem is When I deploy this application on the server. On the server Its running fine but when I run this web application from a  client machine it changes the font. 

    It runs fine if i copy the font on client as well. But its a web application so we cannot copy the font on every client if we are using on the internet.

    So how can it possible PDF file should use the font from server not from client machine.

    please help me!


    Thanks
    Imran Ashraf
     


    could you post your code here or to my bbs (http://www.steedsoft.com/bbs)?

    http://hardrock.cnblogs.com/


  • sigreg

    I've been working on this for about a day now and have been unsuccessful.  I have a PDF form that was generated in Adobe Designer 7.  This form submits to an asp.net page and I save the PDF form information to a database.  When the information needs to be viewed/printed, I am trying to take the information out of the database and populate the same PDF form template.  I have read through this thread and have tried what has been suggested and allI get is an empty PDF.  It does not throw any errors for the C# code that is populating the PDF.  I am using the syntax:

    PdfReader pdfSource = new PdfReader(sSource);
    PdfStamper pdfDest = new PdfStamper(pdfSource, Response.OutputStream);
    AcroFields aFields = pdfDest.AcroFields;
    aFields.SetField("FieldName", "Value");
    pdfDest.Close();

    The PDF is being written to the page's Response.OutputStream. One thing that I noticed when I was saving the submitted PDF form was that I had to reference the form variables like this:

    Request["form1[0].#subform[0].txtFirst[0]"];

    In this instance I would be inserting the data into the form like this:

    aFields.SetField("txtFirst", "Value");

    The fact that I am not getting an exception errors tells me that I am just not referencing the form fields correctly.  Thanks for your help.



  • sigreg

    I seem to have resolved my problem.  It was the way I was referring to the fields in my PDF form. I found an article that describes how to do it and the code.  Although part of this article says that iTextSharp cannot populate PDF forms created in Adobe Designer, this code worked for me.  I'm guessing that maybe when this post was made iTextSharp may not have been able to do it.  I am using 3.1.2.0 and it populates a PDF form generated in Adobe Designer v7. 

    Here's the link:
    http://www.nabble.com/Filling-PDF-Forms-tf392459.html#a1082808


  • sajidmhd

    1. I have a requirement where the customer wants to enter data through a PDF. So I created PDF using Adobe Designer 7.0 

    2. The PDF has a submit button, upon submit the data will be sent to my IIS web server.

    3. I should be able to read this XML and get the meaningful data to be stored elsewhere. (this is where i'm stuck with the crazy image chunk in the XML when there is an image field with an option to user to select a file!!)

    4. Later when the customer wants to edit, I SHOULD BE able to re-populate the data in the PDF and display them..

    preconditions:
    My customer has only Acrobat Reader. (I CAN NOT afford to buy license to 100s of end users)

    Any of you guys know how to do this using iTextSharp? is it possible? I tried a few of the code snippet given here, but it does not help, may be because its not yet upgraded to support 7.0.

    Any better way to approach this problem???


     

  • rocsky

    sajidmhd wrote:
    

    1. I have a requirement where the customer wants to enter data through a PDF. So I created PDF using Adobe Designer 7.0

    there is much difference between Acrobat PDF form with the Designer Form.

    2. The PDF has a submit button, upon submit the data will be sent to my IIS web server.

    no problem.

    3. I should be able to read this XML and get the meaningful data to be stored elsewhere. (this is where i'm stuck with the crazy image chunk in the XML when there is an image field with an option to user to select a file!!)

    no matter xml or fdf, PDF form both supports.

    4. Later when the customer wants to edit, I SHOULD BE able to re-populate the data in the PDF and display them..

    Also ok.

    preconditions:
    My customer has only Acrobat Reader. (I CAN NOT afford to buy license to 100s of end users)

    Any of you guys know how to do this using iTextSharp? is it possible? I tried a few of the code snippet given here, but it does not help, may be because its not yet upgraded to support 7.0.

    Any better way to approach this problem???

    iTextSharp support it, any way, seems you do not need itextsharp from your requirement.

    btw, not iTextsharp does not version 1.6 PDF form, it does not support adobe designer Form.

    if you want iTextSharp also support adobe designer form, you need do some extra job.

    have a look

    Demo: Fill and Save PDF Form online(also can add more function,such as email and save data to database ),Adobe Reader is enough .

    Good luck!

  • rocsky

    sigreg wrote:
    I seem to have resolved my problem.  It was the way I was referring to the fields in my PDF form. I found an article that describes how to do it and the code.  Although part of this article says that iTextSharp cannot populate PDF forms created in Adobe Designer, this code worked for me.  I'm guessing that maybe when this post was made iTextSharp may not have been able to do it.  I am using 3.1.2.0 and it populates a PDF form generated in Adobe Designer v7. 

    Here's the link:
    http://www.nabble.com/Filling-PDF-Forms-tf392459.html#a1082808



    sound it is good news.

    get more iTextsharp example:
    http://hardrock.cnblogs.com

  • Juba

    Hey  guys,

    I have a PDF file generated from my webform using ABCPdf but since it can't handle the TH tag I can't show my datagrid header on each consecutive pages (it's a very long one) - so I started to shop around for alternatives and would like to know if iTextSharp supports this tag and how can I print my webforms html into a PDF file?

    TIA!
    Juba
    Wink

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.