Comments (11)
How can I reproduce it? Where is your code?
from itextsharp.lgplv2.core.
hi,code is shown below。pdf use `xxx.pdf`
/// <summary>
/// setWatermark
/// </summary>
/// <param name="inputfilepath"></param>
/// <param name="outputfilepath"></param>
/// <param name="waterMarkName"></param>
/// <param name="permission"></param>
public static void setWatermark(string inputfilepath, string outputfilepath, string waterMarkName)
{
PdfReader pdfReader = null;
PdfStamper pdfStamper = null;
try
{
pdfReader = new PdfReader(inputfilepath);
pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create));
int total = pdfReader.NumberOfPages + 1;
iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);
float width = psize.Width;
float height = psize.Height;
PdfContentByte content;
BaseFont font = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfGState gs = new PdfGState();
for (int i = 1; i < total; i++)
{
content = pdfStamper.GetOverContent(i);
gs.FillOpacity = 0.3f;
content.SetGState(gs);
content.BeginText();
content.SetColorFill(BaseColor.LightGray);
content.SetFontAndSize(font, 100);
content.SetTextMatrix(0, 0);
content.ShowTextAligned(Element.ALIGN_CENTER, waterMarkName, width / 2 - 50, height / 2 - 50, 55);
content.EndText();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (pdfStamper != null)
pdfStamper.Close();
if (pdfReader != null)
pdfReader.Close();
}
}
from itextsharp.lgplv2.core.
pdfStamper.Close();------ This leads to failure.
from itextsharp.lgplv2.core.
I added a new test based on your code, and I can't reproduce your issue. It works:
Make sure you are using Version 1.5.0
Install-Package iTextSharp.LGPLv2.Core -Version 1.5.0
from itextsharp.lgplv2.core.
test.pdf
sorry,try this。
from itextsharp.lgplv2.core.
I use this too.
<PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.5.0" />
from itextsharp.lgplv2.core.
About your test.pdf. That file is a corrupted file and can't be opened with Adobe Reader:
from itextsharp.lgplv2.core.
This file can be previewed in the browse。There are many files of this type。Can we solve it?
from itextsharp.lgplv2.core.
It's normal to use this tool.
http://www.pdfdo.com/pdf-add-watermark.aspx
from itextsharp.lgplv2.core.
Fixed it via #a2f225b
from itextsharp.lgplv2.core.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.
from itextsharp.lgplv2.core.
Related Issues (20)
- how the html2pdf display chinese characters? HOT 1
- html2pdf image display error HOT 1
- PDF Reader does not read the text from pdf. unit test case is also failing. HOT 1
- `System.Drawing.Common` no longer supported for non-Windows
- AES encryption | Don't Encrypt Meta Data fails to encrypt the pdf document HOT 6
- Strong naming the library HOT 1
- The PdfWriter ExtraCatalog property doesn't seem to work as expected
- Is there a easy way to convert from iTextSharp Image to SKBitmap?
- Wrong page split on nested PdfPTable HOT 2
- Add Font Location for Windows HOT 1
- Endless loop HOT 2
- Specified cast is not valid while reading a TIFF file
- Is there a way to insert svg as a background to PDF ? HOT 1
- Adding a scaled an image to a document produces PDF with the same size as not-scaled image. HOT 1
- Error when reading a large PDF file
- itextsharp.lgplv2.core is missing NuGet package README file HOT 1
- Open encrypted pdf issue
- System.MissingMethodException when migrate from 1.9.4 to 3.4.17 HOT 2
- The strange issue of deleting images from a PDF using iTextSharp HOT 1
- Error when extracting images from some tif files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from itextsharp.lgplv2.core.