4
A
回答
7
我相信只有y位置可供選擇:嘗試
PdfWriter.getVerticalPosition()
8
像@Olaf說,使用GetVerticalPosition
得到Y
。 X
只是文檔的LeftMargin
。下面是一個完整的工作的WinForms應用定位iTextSharp的5.1.1.0是希望做你在找什麼:
using System;
using System.Text;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Test file name
string TestFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
//Standard iTextSharp setup
using (FileStream fs = new FileStream(TestFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (Document doc = new Document(PageSize.LETTER))
{
using (PdfWriter w = PdfWriter.GetInstance(doc, fs))
{
//Open the document for writing
doc.Open();
//Will hold our current x,y coordinates;
float curY;
float curX;
//Add a paragraph
doc.Add(new Paragraph("It was the best of times"));
//Get the current Y value
curY = w.GetVerticalPosition(true);
//The current X is just the left margin
curX = doc.LeftMargin;
//Set a color fill
w.DirectContent.SetRGBColorStroke(0, 0, 0);
//Set the x,y of where to start drawing
w.DirectContent.MoveTo(curX, curY);
//Draw a line
w.DirectContent.LineTo(doc.PageSize.Width - doc.RightMargin, curY);
//Fill the line in
w.DirectContent.Stroke();
//Add another paragraph
doc.Add(new Paragraph("It was the word of times"));
//Repeat the above. curX never really changes unless you modify the document's margins
curY = w.GetVerticalPosition(true);
w.DirectContent.SetRGBColorStroke(0, 0, 0);
w.DirectContent.MoveTo(curX, curY);
w.DirectContent.LineTo(doc.PageSize.Width - doc.RightMargin, curY);
w.DirectContent.Stroke();
//Close the document
doc.Close();
}
}
}
this.Close();
}
}
}
2
確實存在只有y位置。
但如果需要呈現一些簡單的文字,之後把照片或畫一條線,他總是可以指望文本的呈現大小:
var chunk = new Chunk(String.Format("Sample text {0}",));
document.Add(new Paragraph(t));
float curY = writer.GetVerticalPosition(false);
float x = document.Left + chunk.GetWidthPoint();
1
如果你只需要畫一條線在當前部分之後,也許你不需要知道當前的x和y。 試試這個:
iTextSharp.text.pdf.draw.DottedLineSeparator sepLINE = new iTextSharp.text.pdf.draw.DottedLineSeparator();
sepLINE.LineWidth = 1;
sepLINE.Gap = 2;
sepLINE.Percentage = 50;
sepLINE.LineColor = new iTextSharp.text.BaseColor(System.Drawing.Color.Blue);
Chunk chnkLINE = new Chunk(sepLINE);
pdfDoc.Add(chnkLINE);
相關問題
- 1. 查找X和Y位置
- 2. 在pdf文件中查找最後一行的x,y位置 - itextsharp
- 3. x和y位置查找器JQuery JS
- 4. 查找組件的x,y位置
- 5. android java查找X和Y的位置
- 6. 如何查找JTextPane中偏移量的顯示位置(x,y)?
- 7. 在android中查找當前位置
- 8. 查找當前位置
- 9. 如何查找位置X和Y(圖像,區域)
- 10. 如何在DataGridView中獲取當前單元格的位置x和y?
- 11. 如何在python 3中找到鼠標的x和y位置?
- 12. 如何在pdf中找到文本的x,y位置
- 13. 在Cytoscape.js中的x,y位置查找元素
- 14. 查找文本x,y在Android的畫布中的位置
- 15. 在Flex中查找datagrid/adavancedDataGrid行的x,y位置
- 16. 在圖像[OpenCV/Python]中查找[x,y]旋轉座標位置
- 17. 如何查找我當前位置附近的位置?
- 18. 如何在Android中查找當前位置的谷歌地圖?
- 19. 如何在文件中查找當前位置的負值?
- 20. 如何在iPhone中查找當前位置?
- 21. 如何在Mapkit中查找我當前的位置
- 22. 如何在谷歌地圖iOS中查找當前位置?
- 23. 如何在Canvas中查找當前翻譯位置?
- 24. Swift:如何找到UILabel中某個字母的位置(x,y)?
- 25. 查找圖像中指定顏色的x,y位置?
- 26. 如何確定代表您在iOS中當前位置的藍點的x/y屏幕位置?
- 27. C#:如何將3D X Y和Z位置轉換爲2D X和Y位置?
- 28. 在位圖數據中查找像素位置(x和y座標)
- 29. 如何查找mapview中的當前位置
- 30. 如何在每15分鐘查找當前位置