Hidden text when embedding in pdf file using itextshapr
I'm l开发者_StackOverflowearning itextsharp and i have some problem? How to hidden text when i embeded it in pdf file (watermark) ? And if i embeded successfully, how to get text from embeded pdf file ? Sorry about my worst English skill.
I have used "TEXT_RENDER_MODE_INVISIBLE" but text appeared (visible) in pdf file. This is my code:
PdfReader reader = new PdfReader("test.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileStream("testStamperPdf.pdf", FileMode.Create));
stamper.ViewerPreferences = PdfWriter.PageLayoutTwoColumnLeft;
PdfContentByte under;
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
int total = reader.NumberOfPages;
for (int i = 1; i <= total; i++)
{
under = stamper.GetUnderContent(i);
under.BeginText();
under.SetFontAndSize(baseFont, 18);
under.ShowTextAligned(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, "Stackoverflow", 200, 400, 45);
under.EndText();
}
stamper.Close();
I don't understand!!!
under.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
under.showTextAligned(PdfContentByte.ALIGN_CENTER, someString, x, y, rot);
TEXT_RENDER_MODE_*
constants are only for use with setTextRenderingMode()
.
The first parameter for showTextAligned defines how you want your text aligned with regards to the point you passed in.
PS: anyone will be able to copy your invisible text with the standard text tool. It's not THAT hidden. ctrl+a will also select it (along with any and all other text on the page).
精彩评论