使用itextshapr嵌入pdf文件时隐藏文本
我正在学习 itextsharp,但我遇到了一些问题? 当我将文本嵌入pdf文件(水印)时如何隐藏文本? 如果我嵌入成功,如何从嵌入的 pdf 文件中获取文本? 抱歉我的英语水平最差。
我使用了“TEXT_RENDER_MODE_INVISIBLE”,但文本出现在 pdf 文件中(可见)。 这是我的代码:
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'm learning 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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TEXT_RENDER_MODE_*
常量仅适用于setTextRenderingMode()
。showTextAligned 的第一个参数定义了您希望文本如何与传入的点对齐。
PS:任何人都可以使用标准文本工具复制不可见文本。它并没有那么隐藏。 ctrl+a 也将选择它(以及页面上的任何和所有其他文本)。
TEXT_RENDER_MODE_*
constants are only for use withsetTextRenderingMode()
.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).