感谢您的查看和帮助!
如何向PDF中写入透明的文本!
输入文件:input.pdf (353.8 KB)
错误输出:out.pdf (354.7 KB)
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
//创建文档实例
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(pdf);
//创建PDF文件的逐页集合
//Aspose.Pdf.Page page = doc.Pages.Add();
//获取特定页面
Aspose.Pdf.Page page = doc.Pages[1];
//创建Graph对象
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
//创建具有特定尺寸的矩形实例
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400);
//从Alpha颜色通道创建颜色对象
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
//将矩形添加到Graph对象的形状集合
canvas.Shapes.Add(rect);
//将图形对象添加到页面对象的段落集合
page.Paragraphs.Add(canvas);
//将值设置为不更改图形对象的位置
canvas.IsChangePosition = false;
//使用示例值创建TextFragment实例
Aspose.Pdf.Text.TextFragment text = new Aspose.Pdf.Text.TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ");
//从Alpha通道创建颜色对象
Aspose.Pdf.Color color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0);
//设置文本实例的颜色信息
text.TextState.ForegroundColor = color;
//向页面实例的段落集合添加文本
page.Paragraphs.Add(text);
doc.Save(savePdf);