Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net, itextsharp, print pdf

Posted on 2013-06-08
3
Medium Priority
?
1,361 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

971 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