2
A
回答
1
不可能在不指定座標的情況下一個接一個地添加段落,但是我確實寫了這個示例,它會將段落向下移動到頁面上,並在必要時創建一個新頁面。在這個想要你可以寫出文本,段落,繪圖,並且總是知道「光標」的位置。
const int WIDTH = 500;
const int HEIGHT = 792;
pdfDocument myDoc;
pdfPage currentPage;
private void button1_Click(object sender, EventArgs e)
{
int height = 0;
myDoc = new pdfDocument("TUTORIAL", "ME");
currentPage = myDoc.addPage(HEIGHT, WIDTH);
string paragraph1 = "All the goats live in the land of the trees and the bushes, "
+ " when a person lives in the land of the trees and the bushes they wonder about the sanity"
+ " of it all. Whatever.";
string paragraph2 = "Redwood National and State Parks is located in northernmost coastal "
+ "California — about 325 miles north of San Francisco, Calif. Roughly 50 miles long, the parklands"
+ "stretch from near the Oregon border in the north to the Redwood Creek watershed southeast of"
+ "Orick, Calif. Five information centers are located along this north-south corrdior. Park "
+ "Headquarters is located in Crescent City, Calif. (95531) at 1111 Second Street.";
int iYpos = HEIGHT;
for (int ix = 0; ix < 10; ix++)
{
height = GetStringHeight(paragraph1, new Font("Helvetica", 12), WIDTH);
iYpos = CheckHeight(height, iYpos);
currentPage.addParagraph(paragraph1, 0, iYpos, sharpPDF.Enumerators.predefinedFont.csHelvetica, 12, WIDTH);
iYpos -= height;
height = GetStringHeight(paragraph2, new Font("Helvetica", 12), WIDTH);
iYpos = CheckHeight(height, iYpos);
currentPage.addParagraph(paragraph2, 0, iYpos, sharpPDF.Enumerators.predefinedFont.csHelvetica, 12, WIDTH);
iYpos -= height;
}
string tmp = Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".pdf";
myDoc.createPDF(tmp);
}
private int GetStringHeight(string text, Font font, int width)
{
Bitmap b = new Bitmap(WIDTH, HEIGHT);
Graphics g = Graphics.FromImage((Image)b);
SizeF size = g.MeasureString(text, font, (int)Math.Ceiling((float)width/72F * g.DpiX));
return (int)Math.Ceiling(size.Height)
}
private int CheckHeight(int height, int iYpos)
{
if (height > iYpos)
{
currentPage = myDoc.addPage(HEIGHT, WIDTH);
iYpos = HEIGHT;
}
return iYpos;
}
Y在這個API中倒退,所以792是TOP,0是BOTTOM。我使用一個Graphics對象來測量字符串的高度,因爲Graphics是以像素爲單位的,而Pdf是以點爲單位的,我估計它們是相似的。然後我從剩餘的Y值中減去高度。
在這個例子中,我不斷地加入paragraph1
和paragraph2
,隨着我一起更新我的Y位置。當我到達頁面底部時,我創建一個新頁面並重置我的Y位置。
這個項目多年來一直沒有看到任何更新,但源代碼是可用的,使用類似於我所做的一些事情可以使你自己的功能,允許你連續添加段落跟蹤CURSOR在哪些方面認爲應該繼續下一步的位置。
相關問題
- 1. 在特定座標處創建精靈?
- 2. 如何創建一個SVG精靈,然後獲取每個SVG的座標?
- 3. 如何在OpenGL ES 1.1中指定點精靈紋理座標?
- 4. 如何在段落中創建鏈接
- 5. Netbiscuits,創建段落標籤
- 6. 如何在每行中創建一個帶有幾個詞的段落?
- 7. 確定一個線段的座標
- 8. 處理中的精確鼠標座標
- 9. 在UITextView中創建段落
- 10. 如何創建多個段落/行?
- 11. 爲什麼段落標記溢出而不是創建新行?
- 12. 使用LibGDX不精確的Box2d座標
- 13. 如何在imageMap的精確座標處插入一個div
- 14. 創建和和更改h1標籤每四個段落(H1內容中包含段落的前十個元素)
- 15. SharpPDF在Serverside asp .Net中創建PDF C#
- 16. iFrame中html元素的精確座標
- 17. 如何創建帶有Read More/Read Less的段落(標籤中)?
- 18. 蒙戈DB創建精確的指數
- 19. 如何在android中拖動時獲得精確座標?
- 20. 在PPT文本每個段落會自動創建組合框
- 21. 如何正確地創建我的段落和列表內聯?
- 22. 如何確定矩形的座標,如果我知道兩個中間座標?
- 23. 如何在每個段中使用不同字體創建UISegmentedControl?
- 24. 指數不能被創建,因爲列的,是不精確的
- 25. 創建功能:每8個增量=一個段落
- 26. 如何用iTextPDF創建段落?
- 27. 如何反轉段落中的每一行和每個句子?
- 28. 創建一個自定義數據擴展與精確目標
- 29. 在Java中獲得精確的鼠標座標
- 30. 不確定如何創建一個MakeFIle
我很喜歡,如果它只是解釋換行符。還有什麼好運的,@Ryan? – Jules 2011-06-24 09:32:24