Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string formFile = @"E:\Vineet\CRMS\Quotation_Form_New.pdf";
            string newFile = @"E:\Vineet\CRMS\New Quotation\Quotation_Form_de1.pdf";
            
            PdfReader reader = new PdfReader(formFile);
            PdfStamper stamper = new PdfStamper(reader, new FileStream(
                    newFile, FileMode.Create));
            
            AcroFields fields = stamper.AcroFields;
            
            fields.SetField("SalesRep", "SalesVine");
            fields.SetField("QuotationNo", "D100");
          
            stamper.FormFlattening = true;
            stamper.Close();
Posted
Updated 31-Mar-11 1:35am
v3
Comments
Vineet_2109 31-Mar-11 6:48am    
How define size of font.....??
in PDF it shows too big...
Sandeep Mewara 31-Mar-11 7:04am    
Always wrap your code in PRE tags. It makes the question readable.
Sandeep Mewara 31-Mar-11 7:05am    
Now, you have posted the code but I am not very clear what are you looking for in it?
BobJanova 31-Mar-11 7:23am    
Seems like this is one that should be directed to the author of the PDF reader/writer library you are using. I guess the Stamper is supposed to clone the original document and has a bug or a setting you need to set.
Vineet_2109 31-Mar-11 7:38am    
fields.SetFields("SalesRep","SalesVine");
SalesRep is my PFD textbox ID. and salesVine would will be written there..but in between need to change font size coz this font size is too big in PDF. so how can i change font size..

1 solution

Not sure which PDF library you're using here but one that always works well for me is iTextSharp PDF:

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

public void generatePDF(string[] htmlPages, FileInfo Output, string password)
    {
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Output.FullName, FileMode.Create));
        writer.SetEncryption(PdfWriter.STRENGTH128BITS, password, "MasterPassword", PdfWriter.ALLOW_PRINTING);
        document.Open();
        for (int iteratePages = 0; iteratePages < htmlPages.Length; iteratePages++)
        {
            ArrayList lt = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlPages[iteratePages]), null);
            ColumnText ct = new ColumnText(writer.DirectContent);
            ct.SetSimpleColumn(20, 20, PageSize.A4.Width - 20, PageSize.A4.Height - 20);
            for (int k = 0; k < lt.Count; ++k)
            {
                ct.AddElement((IElement)lt[k]);
            }
            document.NewPage();
            ct.Go();
        }
        document.AddAuthor("Your Name");
        document.AddCreator("Your Company");
        document.AddSubject("Doc Subject");
        document.AddTitle("Hello PDF");
        document.Close();
    }



The above function takes an array of HTML strings as the pages of the document so within that HTML you can specify the font size.
You need to reference itextsharp.dll which is avaiable to download here[^]

 
Share this answer
 
Comments
Vineet_2109 1-Apr-11 7:21am    
this would make whole HTML..
My question is .... i do have PDF generated and there are blank field in which i write my values.
But values which i write through c# code is too big in font how can i decrease the font size... ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900