Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

edit pdf itextsharip

string oldFile = "oldFile.pdf";
string newFile = "newFile.pdf";

// open the reader
PdfReader reader = new PdfReader(oldFile);
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);

// open the writer
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();

// the pdf content
PdfContentByte cb = writer.DirectContent;

// select the font properties
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.DARK_GRAY);
cb.SetFontAndSize(bf, 8);

// write the text in the pdf content
cb.BeginText();
string text = "Some random blablablabla...";
// put the alignment and coordinates here
cb.ShowTextAligned(1, text, 520, 640, 0);
cb.EndText();
cb.BeginText();
text = "Other random blabla...";
// put the alignment and coordinates here
cb.ShowTextAligned(2, text, 100, 200, 0);
cb.EndText();

// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);

// close the streams and voilá the file should be changed :)
document.Close();
fs.Close();
writer.Close();
reader.Close();
Comment

PREVIOUS NEXT
Code Example
Csharp :: php check syntax error folder 
Csharp :: catwherehouse 
Csharp :: c# create empty file if not exists 
Csharp :: asp net identity login failed for user 
Csharp :: how to make a 2d character move in unity 2020 
Csharp :: c# supplier equivalent 
Csharp :: C# Move Camera Over Terrain Using Touch Input In Unity 3D - Append To Camera 
Csharp :: what loops are entry controlled c# 
Csharp :: player not following slide object unity 2d 
Csharp :: IOS app crashing on ios 15 unity 
Csharp :: c# get hwid 
Csharp :: .net check connection 
Csharp :: if statement to check if a time is between two times c# 
Csharp :: translate english to spanish 
Csharp :: binary addition c# 
Csharp :: how to download things c# 
Csharp :: unity photon base onenable 
Csharp :: C# Character and String Literals 
Csharp :: JAJAAJAJAJ 
Csharp :: how to get user control dropdown value in asp net 
Csharp :: add buttons to taskbar thumbnail WPF 
Csharp :: player movement script unity 
Csharp :: unity timer 
Csharp :: qcombobox delegate text filter 
Csharp :: C#$ 
Csharp :: Handle all AggregateExceptions when using Task.Whenall() async 
Csharp :: windows forms picturebox click event 
Csharp :: c# xaml textblock new line 
Csharp :: wcf service dependency injection 
Csharp :: how to textbox anywhere on chart in c# 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =