Solved

asp.net, itextsharp, print pdf

Posted on 2013-06-08
3
1,279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

759 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