Skip to content
Loading
  • 0
    Hi Sahoo
     
    Ok i see  now, which means i will need to have a controller, model and view as well. Anything from the sql server side like a table column? I am thinking things like crud operation if the file is downloaed using pdf from the advert, then it wont exist. Whats your experience on this mate? 
    0
  • Laxmidhar Sahoo
    0
    hi
    For your case I think It is better to use itextsharp library .Belloe is the example
     
    1. using iTextSharp.text;  
    2. using iTextSharp.text.pdf;  
    3.   
    4.   
    5.     Document doc = new Document(PageSize.A4);  
    6.     var output = new FileStream(Server.MapPath("MyFirstPDF.pdf"), FileMode.Create);  
    7.     var writer = PdfWriter.GetInstance(doc, output);  
    8.   
    9.   
    10.     doc.Open();  
    11.   
    12.   
    13.     var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/ABsIS_Logo.jpg"));  
    14.     logo.SetAbsolutePosition(430, 770);  
    15.     logo.ScaleAbsoluteHeight(30);  
    16.     logo.ScaleAbsoluteWidth(70);  
    17.     doc.Add(logo);  
    18.   
    19.     PdfPTable table1 = new PdfPTable(2);  
    20.     table1.DefaultCell.Border = 0;  
    21.     table1.WidthPercentage = 80;  
    22.   
    23.     var titleFont = new Font(Font.FontFamily.UNDEFINED, 24);  
    24.     var subTitleFont = new Font(Font.FontFamily.UNDEFINED, 16);  
    25.   
    26.     PdfPCell cell11 = new PdfPCell();  
    27.     cell11.Colspan = 1;  
    28.     cell11.AddElement(new Paragraph("ABC Traders Receipt", titleFont));  
    29.   
    30.     cell11.AddElement(new Paragraph("Thankyou for shoping at ABC traders,your order details are below", subTitleFont));  
    31.   
    32.   
    33.     cell11.VerticalAlignment = Element.ALIGN_LEFT;  
    34.   
    35.     PdfPCell cell12 = new PdfPCell();  
    36.   
    37.   
    38.     cell12.VerticalAlignment = Element.ALIGN_CENTER;  
    39.   
    40.   
    41.     table1.AddCell(cell11);  
    42.   
    43.     table1.AddCell(cell12);  
    44.   
    45.   
    46.     PdfPTable table2 = new PdfPTable(3);  
    47.   
    48.     //One row added  
    49.   
    50.     PdfPCell cell21 = new PdfPCell();  
    51.   
    52.     cell21.AddElement(new Paragraph("Photo Type"));  
    53.   
    54.     PdfPCell cell22 = new PdfPCell();  
    55.   
    56.     cell22.AddElement(new Paragraph("No. of Copies"));  
    57.   
    58.     PdfPCell cell23 = new PdfPCell();  
    59.   
    60.     cell23.AddElement(new Paragraph("Amount"));  
    61.   
    62.   
    63.     table2.AddCell(cell21);  
    64.   
    65.     table2.AddCell(cell22);  
    66.   
    67.     table2.AddCell(cell23);  
    68.   
    69.   
    70.     //New Row Added  
    71.   
    72.     PdfPCell cell31 = new PdfPCell();  
    73.   
    74.     cell31.AddElement(new Paragraph("Safe"));  
    75.   
    76.     cell31.FixedHeight = 300.0f;  
    77.   
    78.     PdfPCell cell32 = new PdfPCell();  
    79.   
    80.     cell32.AddElement(new Paragraph("2"));  
    81.   
    82.     cell32.FixedHeight = 300.0f;  
    83.   
    84.     PdfPCell cell33 = new PdfPCell();  
    85.   
    86.     cell33.AddElement(new Paragraph("20.00 * " + "2" + " = " + (20 * Convert.ToInt32("2")) + ".00"));  
    87.   
    88.     cell33.FixedHeight = 300.0f;  
    89.   
    90.   
    91.   
    92.     table2.AddCell(cell31);  
    93.   
    94.     table2.AddCell(cell32);  
    95.   
    96.     table2.AddCell(cell33);  
    97.   
    98.   
    99.     PdfPCell cell2A = new PdfPCell(table2);  
    100.   
    101.     cell2A.Colspan = 2;  
    102.   
    103.     table1.AddCell(cell2A);  
    104.   
    105.     PdfPCell cell41 = new PdfPCell();  
    106.   
    107.     cell41.AddElement(new Paragraph("Name : " + "ABC"));  
    108.   
    109.     cell41.AddElement(new Paragraph("Advance : " + "advance"));  
    110.   
    111.     cell41.VerticalAlignment = Element.ALIGN_LEFT;  
    112.   
    113.     PdfPCell cell42 = new PdfPCell();  
    114.   
    115.     cell42.AddElement(new Paragraph("Customer ID : " + "011"));  
    116.   
    117.     cell42.AddElement(new Paragraph("Balance : " + "3993"));  
    118.   
    119.     cell42.VerticalAlignment = Element.ALIGN_RIGHT;  
    120.   
    121.   
    122.     table1.AddCell(cell41);  
    123.   
    124.     table1.AddCell(cell42);  
    125.   
    126.   
    127.     doc.Add(table1);  
    128.   
    129.     doc.Close();  
     
    0
  • 0
    Is this a console application? I want to follow the structure of MVC if you can comprehend my argument, nothing wrong with this logic. I just need flow, hope make sense.
    0
  • Laxmidhar Sahoo
    0
    hi
    C# code is same in mvc as well as asp.net.just calling method is different.use post method in mvc  
    0