PDFのコンテンツがすべて1ページに収まらない場合、PDFのコンテンツを次のページに拡張するにはどうすればよいですか。現在、私はA4としてPDFを作成しています。
また、右下のページ 1/12 など、ページ数を指定するにはどうすればよいですか。
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());
}
まず、必要なサイズに自動的に拡張されるドキュメントがあることを確認する必要があります。以下の 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;
}
abc pdf は、HTML ページを pdf に変換し、コンテンツを 2 つの html ページに設定するために使用され、PDF で 2 つのページを生成します。詳細については、これを表示できます。 左側に「コンテンツ」があります。例をクリックしてから、「ページ化された HTML 例」を選択します。