Solved

asp.net, itextsharp, print pdf

Posted on 2013-06-08
3
1,206 Views
Last Modified: 2013-06-18
I have a link like <a href="printreport.pdf">Print</a> it calls simple pdf file. (the pdf has no company logo)
Now I want to the pdf printing with logo at the left top corner. I can change the url to
<a href="printreportwithlogo.aspx">Print</a>
and call itextsharp to add the logo there. First of all, is it possible? if yes, can you show me how to do that?

Thanks
0
Comment
Question by:solution1368
3 Comments
 

Author Comment

by:solution1368
ID: 39232541
one more question. there may be a pdf file with more than one page - meaning that
each pdf page has to print the company logo. so i believe it must use itextsharp to read
how many page in the pdf and then loop in and put the printing companylogo inside of the loop.

I just know how to describe but don't know how to code ...:-(

Thanks
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39232546
You could do something along these lines:

printreportwithlogo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="printreportwithlogo.aspx.cs" Inherits="WebApplication1.printreportwithlogo" %>

Open in new window

printreportwithlogo.aspx.cs
using iTextSharp.text.pdf;
using System;

namespace WebApplication1
{
    public partial class printreportwithlogo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/pdf";

            string pdfPath = Server.MapPath("~/Content/files/book.pdf");
            string imgPath = Server.MapPath("~/Content/images/experts-exchange-logo.png");
            PdfReader reader = new PdfReader(pdfPath);
            PdfStamper stamper = new PdfStamper(reader, Response.OutputStream);
            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgPath);
            PdfContentByte content;

            img.SetAbsolutePosition(10, 700);

            for (int i = 1; i < reader.NumberOfPages; i++)
            {
                content = stamper.GetOverContent(i);
                content.AddImage(img);
            }

            stamper.Close();
        }
    }
}

Open in new window


Keep in mind that the coordinate system starts from the bottom left, so you may need to fiddle with the "10, 700" to get your positioning just right. The for loop handles adding the image to each page. If you later need to only add it to one page, you can swap out the for loop for just its body.

Screenshot
1
 
LVL 7

Expert Comment

by:aplusexpert
ID: 39234543
Yes, you can do it. kaufmed is right. You can use his code.

Thank you.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now