我对纸张尺寸的页面方向有疑问。
我有一个包含纵向和横向页面的 pdf 文件。
此代码完美运行。
string FileLocation = "c:\\Temp\\SomeFile.pdf";
string WatermarkLocation = "c:\\Temp\\watermark.gif";
Document document = new Document();
PdfReader pdfReader = new PdfReader(FileLocation);
PdfStamper stamp = new PdfStamper(pdfReader, new FileStream(FileLocation.Replace(".pdf","[temp][file].pdf"), FileMode.Create));
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(WatermarkLocation);
img.SetAbsolutePosition(250,300); // set the position in the document where you want the watermark to appear (0,0 = bottom left corner of the page)
PdfContentByte waterMark;
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
waterMark = stamp.GetUnderContent(page);
waterMark.AddImage(img);
}
stamp.FormFlattening = true;
stamp.Close();
// now delete the original file and rename the temp file to the original file
File.Delete(FileLocation);
File.Move(FileLocation.Replace(".pdf", "[temp][file].pdf"), FileLocation);
因为我使用绝对值来设置图像位置。
img.SetAbsolutePosition(250,300);
如果页面是横向或纵向,如何设置图像位置?
注意:一个具有横向和纵向页面方向的 pdf。
有没有机会我可以使用 if 语句?
if (//paper is landscape)
{
//code here
}
else
{
//code here
}