我正在使用ABCpdf7创建一个pdf,我在某些情况下想要添加一个“水印状”文本,以便在文档的所有页面上显示。每当我在所有页面上使文本唯一时,它就会按预期工作,但如果它在所有页面上都是相同的文本,它将忽略我的alpha属性。
我似乎无法使用objectID和引用,当它不是图像时,由于pdf将以多种不同语言提供,我担心不可能只用文本创建图像并添加该...
例如,这有效:
theDoc.HPos = 0;
theDoc.VPos = 0;
theDoc.Rect.SetRect(250, 265, 500, 80);
theDoc.Transform.Rotate(55, 250, 265);
theDoc.FontSize = 72;
theDoc.Color.String = "0 0 0 a70";
Page[] pages = theDoc.ObjectSoup.Catalog.Pages.GetPageArray();
foreach (Page p in pages)
{
theDoc.Page = p.ID;
var dummy = theDoc.PageNumber.ToString();
theDoc.AddText("Unpublished" + dummy);
}
...但这不起作用:
theDoc.HPos = 0;
theDoc.VPos = 0;
theDoc.Rect.SetRect(250, 265, 500, 80);
theDoc.Transform.Rotate(55, 250, 265);
theDoc.FontSize = 72;
theDoc.Color.String = "0 0 0 a70";
Page[] pages = theDoc.ObjectSoup.Catalog.Pages.GetPageArray();
foreach (Page p in pages)
{
theDoc.Page = p.ID;
theDoc.AddText("Unpublished");
}
我觉得我错过了一些非常明显的东西,但似乎无法弄清楚是什么......
答案 0 :(得分:0)
theDoc.Transform.Rotate(55, 250, 265);
这一行应该为第一页调用一次,否则它将为每个页面保持旋转。
答案 1 :(得分:0)
在这种情况下,我读取了一个pfd文件并使用水印创建了另一个文件。
def main():
print 'starting...'
baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
print baseURL
while True:
try:
RHW, TW, TWF = getSensorData()
# LT = RCtime(RCpin)
f = urllib2.urlopen(baseURL +
"&field1=%s&field2=%s&field3=%s" % (TW, TWF, RHW))
sys.stdout.flush()
sys.stdout.write("Celcius: %s , Farenheit: %s , Humidity: %s "% (TW, TWF, RHW))
f.close()
sleep(int(myDelay))
except:
print 'exiting.'
break
答案 2 :(得分:-2)
嗨,我不是100%确定我是否完全理解这个问题,但是如果我认为这是可能有帮助的话。
您是否确定要为每个页面添加最后一个水印。在做类似的事情时,我遇到了不同不透明度的问题,而且我的文字是在一页上的某些对象下面然后在另一页上的顶部。我在我的包装器中创建了一个方法,我可以在每个页面上调用最后一个方法,以确保它放在页面上的其他所有内容之上。
public void DrawWaterMark(double positionX = -55, double positionY = 130, string text = "APPROVED", double width = 260, double height = 90, TextAlign textAlign = TextAlign.Center, int colourR = 197, int colourG = 197, int colourB = 197, int fontSize = 95)
{
// Set text alignment:
switch (textAlign)
{
case TextAlign.Left:
PdfDocument.HPos = 0;
break;
case TextAlign.Center:
PdfDocument.HPos = 0.5;
break;
case TextAlign.Right:
PdfDocument.HPos = 1;
break;
}
// Set the text colour:
PdfDocument.Color.String = colourR + " " + colourG + " " + colourB;
SetFontSize(fontSize);
// Draw text:
PdfDocument.Transform.Rotate(45, (PdfDocument.MediaBox.Width / 2), (PdfDocument.MediaBox.Height / 2));
DrawHtmlString(positionX, positionY, width, height, "<b>" + text + "</b>", TextAlign.Center, colourR, colourG, colourB, 50);
PdfDocument.Transform.Rotate(-45, (PdfDocument.MediaBox.Width / 2), (PdfDocument.MediaBox.Height / 2));
SetFontSize(11);
}