Coder Social home page Coder Social logo

Comments (11)

VahidN avatar VahidN commented on June 8, 2024

How can I reproduce it? Where is your code?

from itextsharp.lgplv2.core.

rh1314 avatar rh1314 commented on June 8, 2024
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.

rh1314 avatar rh1314 commented on June 8, 2024

pdfStamper.Close();------ This leads to failure.

from itextsharp.lgplv2.core.

VahidN avatar VahidN commented on June 8, 2024

I added a new test based on your code, and I can't reproduce your issue. It works:
issue39

Make sure you are using Version 1.5.0

Install-Package iTextSharp.LGPLv2.Core -Version 1.5.0

from itextsharp.lgplv2.core.

rh1314 avatar rh1314 commented on June 8, 2024

test.pdf
sorry,try this。

from itextsharp.lgplv2.core.

rh1314 avatar rh1314 commented on June 8, 2024

I use this too.
<PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.5.0" />

from itextsharp.lgplv2.core.

VahidN avatar VahidN commented on June 8, 2024

About your test.pdf. That file is a corrupted file and can't be opened with Adobe Reader:
issue39_@

from itextsharp.lgplv2.core.

rh1314 avatar rh1314 commented on June 8, 2024

This file can be previewed in the browse。There are many files of this type。Can we solve it?

from itextsharp.lgplv2.core.

rh1314 avatar rh1314 commented on June 8, 2024

It's normal to use this tool.
http://www.pdfdo.com/pdf-add-watermark.aspx

example

from itextsharp.lgplv2.core.

VahidN avatar VahidN commented on June 8, 2024

Fixed it via #a2f225b

from itextsharp.lgplv2.core.

lock avatar lock commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.