我有一個非常簡單的代碼,可以將 png 影像放入 PDF
Document pdfDoc = new Document(PageSize.A4, 25, 25, 25, 10);
string pathfile = ConfigurationManager.AppSettings["Temp_SaveLocation"];
string fileName = "SomeName.pdf";
path = pathfile fileName;
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream(path, FileMode.Create));
pdfDoc.Open();
Image imghead = Image.GetInstance(templateFolder "Letterhead.png");
imghead.SetAbsolutePosition(0, 0);
pdfDoc.Add(imghead);
pdfWriter.CloseStream = true;
pdfDoc.Close();
但是,無論我將影像設定在什么位置,該影像最終都會出現在檔案的最底部。我什至嘗試了絕對位置的負值。盡管如此,影像仍保留在檔案的最底部。我怎樣才能將影像帶到最高點?
非常感謝您提前
uj5u.com熱心網友回復:
我發現洗掉此代碼后,影像將位于頂部。
imghead.SetAbsolutePosition(0, 0);
uj5u.com熱心網友回復:
我同意 K J。通過設定 imghead.SetAbsolutePosition(0, 0),您將影像設定為 (X,Y) 坐標,該坐標主要是頁面的左下角坐標。
一般來說,頁面的左下角與坐標系的原點(0, 0)重合。頁面右上角與坐標 (595, 842) 重合。您可以洗掉或注釋此方法 imghead.SetAbsolutePosition(0, 0) 或調整它的 Y 坐標以將影像移向頁面的上側。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/444815.html
