Solved

asp.net, itextsharp, print pdf

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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