Itextsharp Rectangle On Existing Pdf

  1. Itextsharp Examples
  2. Itextsharp Rectangle On Existing Pdf Document
  3. Itextsharp Pdf Download
  4. Pdfstamper Itextsharp
27 Nov 2013CPOL

I have created rectangle using PdfContentByte. Now I want to adda text inside this rectangle. How can I do this. How to add text in PdfContentByte rectangle using itextsharp? Ask Question Asked 4 years, 2 months ago. How to add newline to pdf in iText, java. Is there a way in iText to draw a rectangle in a PDF document? In the.NET version I just create a table with a border. I know it isn't Java but maybe the following code will help you.

Create/Read/Write Advance PDF Report using iTextSharp.DLL in Desktop, Mobile, Web Application

Contents


    The following two contents are added in this updated version:

Introduction

Recently I was looking for an Advance Tool to create complex PDF Report in C#.Net and I found iTextSharp. The main problem is that lacks of Documentation. Yes, there are a few examples in C#, but that is not sufficient to the Beginners and the examples are in older version of iTextSharp, there are lots of change in the latest version. So, it will be difficult for beginners to convert older version to latest version. Besides, I think that if I write an Article on this, then it will help me also as a future reference as I'll describe each functionality of this library with example. Frankly speaking, in this Article, you find all the examples from Chapter 1 of the book iText in Action, Second Edition which is written for Java Developers. I'll explain all the examples of the rest Chapters in my next release of this Article. So if any one is interested in using this library, he/she will get a good kick start.

Jul 28, 2019  Download Connectify Hotspot for free. With Connectify Hotspot, you can transform your PC into a Wi-Fi hotspot, and share your computer’s Internet. 1: Launch the Connectify Installer. Launch the Connectify Hotspot Installer that you’ve just downloaded by double-clicking the installer’s icon or launching it directly from your browser’s download manager. Download connectify me for pc windows 10. Jan 09, 2018  Download Connectify Hotspot 2018.1.1.38937. Turn your PC into a WiFi signal repeater. Connectify is a tool that will turn your computer (with WiFi access) into a signal repeater so that other nearby devices can connect to the Internet through its connection. Connectify Hotspot is a relatively lightweight app that allows you to transform your PC into a WiFi Hotspot and share Internet with all your devices. Connectify Hotspot has a really easy to understand and intuitive user interface that makes it simple to manage your connections on your network. Jul 29, 2017  Download Connectify Hotspot 2019 for Share & Connect for Free. Connectify Hotspot from revolutionary software that spread like open fire very quickly and gained wide fame. The duty of this program is to disperse the internet from a spot of the source from a laptop to talk about the web with other devices such as mobile, laptop, tablet devices and other devices situated in the same place.

To know the history or any other details of iTextSharp, please go through the Official Website

Requirements

  • To compile this library, you need a C# 2008 compiler or better, Visual Studio 2008 or Visual C# 2008 Express Edition
  • This library code will run in:
    • .NET 2.0
    • .NET 3.0
    • .NET 3.5
    • .NET 4.0
    • .NET 4.0 Client Profile
    • .NET 4.5
    • .NET 4.5 Client Profile

Installation

  • Simply install the NuGet package

Or you can download the library DLL from the above link or from the SourceForge. Then do the following:

  • Add the following library into your project by adding reference to that library DLL. Just see the image below:
  • The necessary namespace that you have to add into your C# file to do what are in this Article are::
    • iTextSharp.text
    • iTextSharp.text.pdf

Quick Start

Creating PDF Document in 6 Steps:

  • Step 1: Create a System.IO.FileStream object:
  • Step 2: Create a iTextSharp.text.Document object:
  • Step 3: Create a iTextSharp.text.pdf.PdfWriter object. It helps to write the Document to the Specified FileStream:
  • Step 4: Openning the Document:
  • Step 5: Adding a Paragraph by creating a iTextSharp.text.Paragraph object:
  • Step 6: Closing the Document:

Working with Page Size of PDF Document:

Creating a Page of specified size, we must have to create a iTextSharp.text.Rectangle object and Passing the size as argument to its constructor. There are a few way to define Page Size:

  • First Way to define Page Size:
    Creating Page Size by Pixels or Inch. NOTE: In iTextSharp library, unit is 'point'. 72 points = 1 inch. Suppose we want to create a PDF File of width = 2 inch & height = 10 inch, then we need 144pt for 2 inch & 72pt for 10 inch. Lets see, how to do this:
  • Second Way to define Page Size:
    Taking Page Size from in-built iTextSharp.text.PageSize class:
    The following are the Supported in-built Page Size. Read the full Documentation of Page Size:
    • _11X17
    • A0
    • A1
    • A10
    • A2
    • A3
    • A4
    • A4_LANDSCAPE
    • A5
    • A6
    • A7
    • A8
    • A9
    • ARCH_A
    • ARCH_B
    • ARCH_C
    • ARCH_D
    • ARCH_E
    • B0
    • B1
    • B10
    • B2
    • B3
    • B4
    • B5
    • B6
    • B7
    • B8
    • B9
    • CROWN_OCTAVO
    • CROWN_QUARTO
    • DEMY_OCTAVO
    • DEMY_QUARTO
    • EXECUTIVE
    • FLSA
    • FLSE
    • HALFLETTER
    • ID_1
    • ID_2
    • ID_3
    • LARGE_CROWN_OCTAVO
    • LARGE_CROWN_QUARTO
    • LEDGER
    • LEGAL
    • LEGAL_LANDSCAPE
    • LETTER
    • LETTER_LANDSCAPE
    • NOTE
    • PENGUIN_LARGE_PAPERBACK
    • PENGUIN_SMALL_PAPERBACK
    • POSTCARD
    • ROYAL_OCTAVO
    • ROYAL_QUARTO
    • SMALL_PAPERBACK
    • TABLOID
  • Third Way to define Page Size:
    Rotating Document i.e. height becomes width & vice-versa:

Itextsharp Examples

Now, just pass this iTextSharp.text.Rectangle object (any one) i.e. either 'rec', or 'rec2' or 'rec3' to the iTextSharp.text.Document's constructor during object creation like below:

Setting Background Color of PDF Document:

Dvr drivers for windows 10. There are a few ways to set background color:

  • First Way to Set Background Color:
    It takes the object of iTextSharp.text.BaseColor. BaseColor constructor takes in-built System.Drawing.Color object Or you can pass RGB values to the constructor in different forms:
  • Second Way to Set Background Color:
    It takes the object of iTextSharp.text.pdf.CMYKColor. CMYKColor constructor takes only CMYK values in different forms:
Itextsharp Rectangle On Existing Pdf

Setting Page Margins of PDF Document:

Margins can be set during Document object creation like Page Size
Suppose we set the margins as below:

  • Left Margin: 0.5 inch
  • Right Margin: 1 inch
  • Top Margin: 1.5 inch
  • Bottom Margin: 2.5 inch

So, we need to do set the following points for the Left, Right, Top, Bottom Margins respectively as we already know that iTextSharp library only understand points where 72 points = 1 inch.

  • Left Margin: 36pt => 0.5 inch
  • Right Margin: 72pt => 1 inch
  • Top Margin: 108pt => 1.5 inch
  • Bottom Margini: 180pt => 2.5 inch

Lets implement:

Setting Text Alignment in PDF Document:

Alignment is one of the property of iTextSharp.text.Paragraph's object. iTextSharp Library provides various types of Alignments. These Alignments can be access through iTextSharp.text.Element class. The following are Alignment types provides iTextSharp:

  • [^]
  • [^]
  • [^]
  • [^]
  • [^]
  • [^]
  • [^]
  • [^]
  • [^]
  • [^]

As we already see the iTextSharp.text.Document's constructor takes iTextSharp.text.Paragraph's object during Document creation. So, after creating the Paragraph object and setting Alignment property, we can pass this object to iTextSharp.text.Document's constructor during Document ceration. Lets implement:

Setting Meta Information or Properties of a PDF Document:

The following Meta information of PDF Document, you can set through iTextSharp.text.Document's methods by creating its object i.e. doc here:

  • Author Name[^]
  • Creation Date[^]
  • Creator Name[^]
  • Header Name & Content[^]
  • Keywords[^]
  • Langugae[^]
  • Producer[^]
  • Subject[^]
  • Title[^]

Lets implement a few of them:

Removing Acrobat X Pro’s Default Actions Quit Acrobat if it is running. Open your Application folder. Locate the Adobe Acrobat X Pro folder and open it. Right-click on Adobe Acrobat Pro.app and choose Show Package Contents. The Contents folder will appear. Restart Acrobat. Remove adobe acrobat as default. HKEYCURRENTUSERSoftwareAdobe(product name)(version)AVAlertcCheckBox DWORD: iAppDoNotTakePDFOwnershipAtLaunch which is set to value 1.If AVAlert or cCheckbox do not exist by default, then select the Do not show this message again check box on the dialog box and then recheck. Apr 11, 2017  As explained, you might have set Acrobat Reader DC as default application to open all the files. Assuming that you are working on Windows computer? You can change the default application to open the pictures or other file format by following the steps mentioned below. If you have an Acrobat question, ask questions and get help from the community. My documents How do I remove Acrobat as the default reader? My documents are all coming up in acrobat as a default.

Now after openning this PDF file, right click over it and click Properties, then you'll see the following:

Creating a Multipage Document:

We can create a new page through iTextSharp.text.Document's NewPage() method by creating its object. Lets add five pages in PDF Document:

Creating a New PDF Document from an existing PDF Document:

We can read from a PDF Document using iTextSharp.text.pdf.PdfReader's object and write it to another PDF Document using iTextSharp.text.pdf.PdfStamper's object. Lets implement:

Adding Watermark to PDF Document using Layer:

Watermark can be add after creating the PDF Dodument in iTextSharp Library. Here I'll add Watermark to existing PDF Document i.e. Original.pdf, through creating a iTextSharp.text.pdf.PdfLayer object. Lets implement:

The created PDF Document is below:

Removing Watermark from the just created Watermarked Document by Removing Layer:

Whenever we add Layer in PDF Document, then the content of the Layer resides under OCG Group. So if I remove this Layer we can remove the content of the Layer also e.g. here it is Watermark Text. To remove all the Layers from PDF Document, you have to remove OCG Group completely from the Document using reader.Catalog.Remove(PdfName.OCPROPERTIES). Now follow the Steps below to remove the Watermark Text from Layer:

  • Read the existing watermarked document using iTextSharp.text.pdf.PdfReader's object
  • Taking each Page in the iTextSharp.text.pdf.PdfDictionary's object using GetPageN(int pageNumber) method of iTextSharp.text.pdf.PdfReader's object.
  • Taking the Content of the Page in the iTextSharp.text.pdf.PdfArray's object using GetAsArray(PdfName.CONTENTS) method of iTextSharp.text.pdf.PdfDictionary's object
  • Loop through this array and Get each element as iTextSharp.text.pdf.PRStream's object using GetAsStream(int arrayIndex) method of iTextSharp.text.pdf.PdfArray's object
  • Convert each stream into Bytes using Static method of iTextSharp.text.pdf.PdfReader class
  • Convert these Bytes into String using method
  • Search for the String '/OC' and also the Watermarked Text. If found then remove it by giving it zero length and zero data using two methods: Put() & SetData() of iTextSharp.text.pdf.PRStream class
  • Write this modified document exists in the reader to a new document using iTextSharp.text.pdf.PdfStamper's object

Lets Implement it:

Adding Watermark to each Page during Creation:

Now, we already know that, watermark cannot be add during Page creation, it have to add after document creation. So, I've created a class PDFWriterEvents which implements the interface iTextSharp.text.pdf.IPdfPageEvent and modify the event OnStartPage. This interface contains a set of events from the Openning & to Closing the PDF Document. The events are following:

  • public void OnOpenDocument(PdfWriter writer, Document document)
  • public void OnCloseDocument(PdfWriter writer, Document document)
  • public void OnStartPage(PdfWriter writer, Document document)
  • public void OnEndPage(PdfWriter writer, Document document)
  • public void OnParagraph(PdfWriter writer, Document document, float paragraphPosition)
  • public void OnParagraphEnd(PdfWriter writer, Document document, float paragraphPosition)
  • public void OnChapterEnd(PdfWriter writer, Document document, float paragraphPosition)
  • public void OnSectionEnd(PdfWriter writer, Document document, float paragraphPosition)
Existing

You may modify other events accroding to your needs which occured against a particular action. Let see the which I've created:

Lets see how & when you use the object of this class:

See, OnStartPage event called during adding a new paragraph. So I don't need to add watermark later:)

Export/Print/Output the PDF File directly to the Client without saving it to the Disk:

We can create PDF File in memory by creatig System.IO.MemorySystem's object. Lets see:

Pdf

Setting Viewer Preferences of a PDF Document:

The values of the different ViewerPreferences were originally stored in iTextSharp.text.pdf.PdfWriter class as an integer constant. You can set the ViewerPreferences by following two ways:

Using an offline attack, it’s possible to rapidly guess potential passwords to see if they’re correct.New research by Ryan Castellucci, a security researcher at digital fraud firm White Ops, indicates there is as major flaw in this method. He highlights that the final bitcoin address is recorded in the blockchain as a password hash. Bitcoin hacking tools. A white-hat hacker has released a new tool designed to illustrate the ease with which illicit actors can steal bitcoins from brainwallets, a type of bitcoin wallet iteration where passwords are not stored digitally – but in the memory of the user.Originally conceived as a way to keep sensitive wallet data offline and make bitcoin addresses easier to remember, was partly undone due to how it interacts with the bitcoin blockchain. A brainwallet uses a single, long password or phrase, converts it to a private key, a public key and finally an address.

  • By setting property ViewerPreferences of iTextSharp.text.pdf.PdfWriter class. To know all the ViewerPreferences and its purpose, please read this first. E.g.-
  • By calling method AddViewerPreference(PdfName key, PdfObject value) of iTextSharp.text.pdf.PdfWriter's object. To know which value is appropiate for which key, read this first. E.g.-

Encrypting a PDF Document:

By SetEncryption() method of iTextSharp.text.pdf.PdfWriter's object, we can encrypt a PDF document. Read full documentation of this method here. To know all the encryption types, click here. E.g.-

Itextsharp Rectangle On Existing Pdf Document

Declaration

References

Itextsharp Pdf Download

History

25th Nov, 2013: PART-I Release. PART-II will release soon :)

Pdfstamper Itextsharp