PDF watermark for print only, software

I can watermark any PDF file and the images inside are all fine, but now I need the watermark to appear only when the PDF file is printed ... Is this possible? How?

I need to do this programmatically, of course.

+3
source share
4 answers

You should probably use the fact that the screen uses RGB and CMYK printers. You should be able to create two colors in CMYK that map to the same RGB value. This, of course, is not enough for a certain specialist.

+1
source

, PDF, 4 - , 4.10 - .

+8

, itextsharp, , - pdf 1.7 SetPrint ( " ", true)

        string oldfile = @"c:\temp\oldfile.pdf";
        string newFile = @"c:\temp\newfile.pdf";
        PdfReader pdfReaderS = new PdfReader(oldfile);
        Document document = new Document(pdfReaderS.GetPageSizeWithRotation(1));
        PdfWriter pdfWriterD = PdfWriter.GetInstance(document, new FileStream(newFile, FileMode.Create, FileAccess.Write));
        pdfWriterD.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
        document.Open();
        PdfContentByte pdfContentByteD = pdfWriterD.DirectContent;

        BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        int n = pdfReaderS.NumberOfPages;

        string text = "UNCONTROLLED";

        for (int i = 1; i <= n; i++)
        {
            iTextSharp.text.Rectangle pageSizeS = pdfReaderS.GetPageSizeWithRotation(i);
            float pageWidth = pageSizeS.Width / 2;
            float pageheight = pageSizeS.Height / 2;

            document.SetPageSize(pageSizeS);
            document.NewPage();
            PdfImportedPage pdfImportedPage = pdfWriterD.GetImportedPage(pdfReaderS, i);

            PdfLayer layer1 = new PdfLayer("Watermark", pdfWriterD);
            layer1.SetPrint("Watermark", true);
            layer1.View = false;
            layer1.On = false;
            layer1.OnPanel = false;

            pdfContentByteD.BeginLayer(layer1);
            pdfContentByteD.SetColorFill(BaseColor.RED);
            pdfContentByteD.SetFontAndSize(bf, 30);

            ColumnText.ShowTextAligned(pdfContentByteD, Element.ALIGN_CENTER, new Phrase(text), 300, 700, 0);
            pdfContentByteD.EndLayer();

            pdfContentByteD.AddTemplate(pdfImportedPage, 0, 0);//, 0, 1, 0, 0);

        }
        document.Close();
        pdfReaderS.Close();
+2

Source: https://habr.com/ru/post/1727672/


All Articles