使用iTextSharp版本4.1.6,我在这样的pdf文档的左上角添加了一个徽标。
public MemoryStream GeneratePdf(bool landscapeMode)
{
// Create the iTextSharp document.
var doc = new Document(PageSize.A4, 20, 20, 25, 25);
if(landscapeMode) {
//set to landscape mode
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
}
// Set the document to write to memory.
MemoryStream memStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memStream);
writer.CloseStream = false;
doc.Open();
//get logo
var logo = iTextSharp.text.Image.GetInstance(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images/Logo.png"));
// set position in document
logo.SetAbsolutePosition(doc.LeftMargin, doc.PageSize.Height - doc.TopMargin - logo.Height);
//insert logo
doc.Add(logo);
// Add other stuff ...
// Close and return memory stream
doc.Close();
return memStream;
}
只要landscapeMode
设置为true,徽标就会正确显示(原始尺寸),但当landscapeMode
设置为false(纵向模式)时,徽标会升级约150% 。如何在纵向模式下停止这种意外的放大?