6
我在紙張大小的頁面方向上有問題。
我有一個pdf文件,其中包含肖像和風景頁面。使用iTextSharp設置圖像位置
此代碼完美工作。
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);
如果頁面是橫向或縱向,T如何設置圖像位置?
注意:一個PDF與橫向和縱向頁面方向。
是否有機會可以使用if語句?
if (//paper is landscape)
{
//code here
}
else
{
//code here
}