Solved

asp.net, itextsharp, print pdf

Posted on 2013-06-08
3
1,225 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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Class Library Dynamics For Connectstring Information 2 24
Adware on IIS hosted asp.net website 1 20
Coding C# in Linux 8 36
Finally almost got it 5 23
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

25 Experts available now in Live!

Get 1:1 Help Now