2
A
回答
0
abc pdf用于将HTML页面转换为pdf,将您的内容设置为两个html页面,它将在PDF中生成两个页面。有关更多详细信息,您可以在左侧查看This,在此处有“内容”点击示例然后选择“分页的HTML示例”。
4
要添加文本到PDF文档,并让它创建新的页面,如果文本不适合您可以使用下面的代码。
theID = theDoc.AddHtml(theText)
While theDoc.Chainable(theID)
theDoc.Page = theDoc.AddPage()
theDoc.FrameRect
theID = theDoc.AddHtml("", theID)
Wend
要添加您的页码和页数到每个页面使用此。
theDoc.Rect = "100 50 500 150" 'position of page number
For i = 1 To theDoc.PageCount
theDoc.PageNumber = i
theDoc.AddText i & "/" & theDoc.PageCount
Next
编辑:C#版本
Doc doc = new Doc();
doc.Page = doc.AddPage();
int id = doc.AddImageUrl("http://www.google.com/", true, 700, true);
while (true)
{
if (!doc.Chainable(id))
break;
doc.Page = doc.AddPage();
id = doc.AddImageToChain(id);
}
doc.Font = doc.AddFont("Arial");
doc.FontSize = 9;
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Rect.String = "470 55 570 65";
doc.HPos = 1;
doc.AddText("Page " + i.ToString() + " of " + doc.PageCount.ToString());
}
2
你需要做的就是首先要确保你有一个将会被自动扩展到所需的大小的文件是什么,在C#下面的例子将采取URL并建立一个多达50页的文件,如果需要扩大。 (下面的示例将空间中的文档中页眉和页脚)
private static Doc CreateNewDoument(string currentURL)
{
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.ImageQuality = 101;
theDoc.Rect.Width = 719;
theDoc.Rect.Height = 590;
theDoc.Rect.Position(2, 70);
theDoc.HtmlOptions.Engine = EngineType.Gecko;
// Add url to document.););
try
{
//Make sure we dont have a cached page..
string pdfUrl = currentURL+ "&discache=" + DateTime.Now.Ticks.ToString();
int theID = theDoc.AddImageUrl(pdfUrl);
//Add up to 50 pages
for (int i = 1; i <= 50; i++)
{
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
theDoc.PageNumber = 1;
}
catch (Exception ex)
{
//HttpContext.Current.Response.Redirect(pdCurrentURL);
throw new ApplicationException("Error generating pdf..." + "Exception: " + ex + "<br/>URL for render: " + pdfUrl+ "<br/>Base URL: " + currentURL);
}
return theDoc;
}
然后到页脚添加到每个页面只是使用下面的方法。下面的方法在里面添加一个蓝色框和文本。
private static Doc AddFooter(Doc theDoc)
{
int theCount = theDoc.PageCount;
int i = 0;
for (i = 1; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 30);
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#468DCB");
theDoc.Color.Color = c;
theDoc.PageNumber = i;
theDoc.FillRect();
}
i = 0;
for (i = 1; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 260 50";
theDoc.Rect.Position(190, 20);
System.Drawing.Color cText = System.Drawing.ColorTranslator.FromHtml("#ffffff");
theDoc.Color.Color = cText;
string theFont = "Century Gothic";
theDoc.Font = theDoc.AddFont(theFont);
theDoc.FontSize = 17;
theDoc.PageNumber = i;
theDoc.AddText("Page " + i +" of " +theCount); //Setting page number
//theDoc.FrameRect();
}
return theDoc;
}
然后,只需调用一大堆..像
private static bool BuildPDF(string pdfPath)
{
bool pdfBuilt = false;
try
{
var theDoc = new Doc();
string pdGeneral = "http://ww.myurl.com";
theDoc = CreateNewDoument(pdGeneral);
theDoc = AddFooter(theDoc);
theDoc.Save(pdfPath);
theDoc.ClearCachedDecompressedStreams();
theDoc.Clear();
theDoc.Dispose();
pdfBuilt = true;
}
catch (Exception)
{
//PDF normaly in use dont worry..
}
return pdfBuilt;
}
相关问题
- 1. 将页码添加到pdf文档(itextsharp)
- 2. 将页码添加到组合PDF中
- 3. 将PDF文档添加到现有PDF文档的每个其他页面上?
- 4. iTextsharp将语言添加到PDF文档
- 5. 将PDF文档添加到表格
- 6. 将超链接添加到PDF文档
- 7. ITextSharp将页码添加到合并pdf
- 8. R - 将页码添加到PDF
- 9. 使用ghostscript将页码添加到pdf
- 10. 如何将页码添加到Postscript/PDF
- 11. 使用iTextSharp将页面添加到PDF文档
- 12. 在Java中添加PDF文档到Solr
- 13. 将文本添加到Python中的现有PDF文档中
- 14. 在PDF中添加pdf表格文档
- 15. ASP.Net webform/mvc3 - 将链接添加到多页PDF文档的每个页面
- 16. 将文本添加到PDF
- 17. 将文本添加到PDF
- 18. 将按钮添加到iPhone应用程序中的PDF文档
- 19. 使用iText将复选框添加到PDF文档中
- 20. 使用itextsharp将文本添加到PDF文档
- 21. 如何将链接添加到PDF文档的文件附件
- 22. 如何使用perl将页码添加到现有PDF中
- 23. 将单独文档中的页眉预先添加到页面
- 24. 将PDF文档(* .pdf)转储到文本?
- 25. 将页面添加到pdf在php
- 26. ReportLab将多页PDF添加到画布
- 27. DOMpdf,将新页面添加到PDF
- 28. 将保证金添加到pdf页面
- 29. 如何在合并两个pdf时将页码添加到输出pdf中?
- 30. 如何使用javascript将图像添加到pdf文档
问题标记为C# – Askolein
有效点@Askolein。我会更新我的答案。只有2年太晚:( – johna