thanks for your code...
anyway, when i try to use it, i get this error:
+ ex {"The process cannot access the file 'C:\WwwRoot\Osiris.4\Portals\0\FileLezioni\105235373_Lesson_233.pdf' because it is being used by another process."} System.Exception
i've just created the pdf in this way...
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(rect)
Dim writer As iTextSharp.text.pdf.PdfWriter
writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, New FileStream(path & nameFile, FileMode.Create))
....
do my job ... then i do....
document.Close()
writer.Close()
Dim watermarkImage As String = watermarkimagepath & watermarkimageName
AddWatermarkImage(path & nomeFile, path & nomeFile, watermarkImage) 'callyour procedure
is there something i forget... if the document and writer are closed... what is missing??
Member
22 Points
48 Posts
Add WaterMark In PDF Files
Nov 14, 2008 12:12 AM|naimish|LINK
Private Sub btnAddWaterMark_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddWaterMark.Click
Dim input As String
Dim output As String
Dim water As String
If txtPath.Text = "" Or txtimgpath.Text = "" Or txtoutpath.Text = "" ThenMessageBox.Show("Please Enter Required Data", "Required Data Missing")
Else
input = txtPath.Text
water = txtimgpath.Text
output = txtoutpath.Text
AddWatermarkImage(input, output, water)
End If
End SubPublic Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing
Dim img As iTextSharp.text.Image = Nothing
Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
Dim rect As iTextSharp.text.Rectangle = Nothing
Dim X, Y As SingleDim pageCount As Integer = 0
Try
If System.IO.File.Exists(sourceFile) Thenreader = New iTextSharp.text.pdf.PdfReader(sourceFile)
rect = reader.GetPageSizeWithRotation(1)
stamper = New iTextSharp.text.pdf.PdfStamper(reader, New System.IO.FileStream(outputFile, IO.FileMode.Create))
img = iTextSharp.text.Image.GetInstance(watermarkImage)
If img.Width > rect.Width OrElse img.Height > rect.Height Then
img.ScaleToFit(rect.Width, rect.Height)
X = (rect.Width - img.ScaledWidth) / 2
Y = (rect.Height - img.ScaledHeight) / 2
Else
X = (rect.Width - img.Width) / 2
Y = (rect.Height - img.Height) / 2
End If
img.SetAbsolutePosition(X, Y)
pageCount = reader.NumberOfPages()
For i As Integer = 1 To pageCount
underContent = stamper.GetUnderContent(i)
underContent.AddImage(img)
Next
stamper.Close()
reader.Close()
ElseMessageBox.Show("File Does Not Exist", "Missing File")
End IfCatch ex As Exception
Throwex
End Try
End Sub
Naimish Pandya
[MCTS : Web Applications]
[MCPD : Web Developer]
Member
650 Points
151 Posts
Re: Add WaterMark In PDF Files
Nov 16, 2008 01:52 PM|Sagar Nishant|LINK
Nishant Sagar
None
0 Points
8 Posts
Re: Add WaterMark In PDF Files... in use by another process
Dec 09, 2008 04:57 AM|WeiLuDi|LINK
Hello.
thanks for your code...
anyway, when i try to use it, i get this error:
+ ex {"The process cannot access the file 'C:\WwwRoot\Osiris.4\Portals\0\FileLezioni\105235373_Lesson_233.pdf' because it is being used by another process."} System.Exception
i've just created the pdf in this way...
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(rect)
Dim writer As iTextSharp.text.pdf.PdfWriter
writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, New FileStream(path & nameFile, FileMode.Create))
....
do my job ... then i do....
document.Close()
writer.Close()
Dim watermarkImage As String = watermarkimagepath & watermarkimageName
AddWatermarkImage(path & nomeFile, path & nomeFile, watermarkImage) 'callyour procedure
is there something i forget... if the document and writer are closed... what is missing??
thanks
Rudy Vicelli
None
0 Points
8 Posts
Re: ok, but at page bottom
Dec 09, 2008 05:17 AM|WeiLuDi|LINK
hii, i undestood that source and destination cannot be the same...
i just wanted to ask how to put the watermark at page-bottom
thanks
Member
22 Points
48 Posts
Re: Add WaterMark In PDF Files... in use by another process
Jun 10, 2009 11:39 PM|naimish|LINK
It's an error for not closing the connection properly, check again to properly close() the connection.
Naimish Pandya
[MCTS : Web Applications]
[MCPD : Web Developer]
None
0 Points
2 Posts
Re: Add WaterMark In PDF Files... in use by another process
Jun 11, 2009 12:58 PM|micaela|LINK
Very nice thanks!
Member
22 Points
48 Posts
Re: Add WaterMark In PDF Files... in use by another process
Jun 29, 2009 01:07 AM|naimish|LINK
Welcome....!
Naimish Pandya
[MCTS : Web Applications]
[MCPD : Web Developer]
None
0 Points
1 Post
Re: Add WaterMark In PDF Files
Dec 23, 2010 02:18 PM|bortruh|LINK
Thanks naimish :)