[英]How to change the page size of one of the pages in a existing PDF using ABCPdf
[英]Change the inset of a specific page with abcpdf
我使用abcpdf從html字符串創建pdf。 以下代碼段顯示了我的操作方式:
var pdfDocument = new Doc();
pdfDocument.Page = pdfDocument.AddPage();
pdfDocument.Font = pdfDocument.AddFont("Times-Roman");
pdfDocument.FontSize = 12;
var documentId = pdfDocument.AddImageHtml(innerHtml);
var counter = 0;
while (true)
{
counter++;
if (!pdfDocument.Chainable(documentId))
{
break;
}
pdfDocument.Page = pdfDocument.AddPage();
// how to add a inset of 20, 0 on every page after the second? The following 2lines don't affect the pdf pages
if (counter >= 3)
pdfDocument.Rect.Inset(20, 0);
documentId = pdfDocument.AddImageToChain(documentId);
}
在AddPage之后,我想為頁數> 2的每個頁面添加一個新的插圖。
提前致謝
我可以向您保證,您的插播通話將起作用。 嘗試在每個頁面上調用FrameRect,您將能夠看到此內容。
那么,為什么沒有看到預期的效果呢?
好了,在您調用AddImageUrl / HTML時,HTML具有固定的寬度。 隨后對AddImageToChain的每次調用都使用此固定寬度。
如果在“插圖”頁面中減小頁面區域的高度,則頁面的下一部分將被截斷為該高度。
如果在“插圖”頁面中減小區域的寬度,則事情會變得更加困難。 寬度是固定的,因此無法更改。 相反,ABCpdf將按比例縮小頁面,使其適合頁面大小。
因此,如果將寬度從600點減少到580點,則此內容的比例因子將為580/600 = 97%。
這很可能是正在發生的事情,但是由於比例因子很小,您沒有注意到它。
我從事ABCpdf的工作,我的答復可能包含基於ABCpdf的概念。 這就是我所知道的。 :-)
SwissCoder的評論1是正確的。 AddImageHtml
已經添加了第一頁。 在還聯系了WebSuperGoo支持人員之后,他們建議我使用Doc
類的PageCount
。
while (true)
{
if (!pdfDocument.Chainable(documentId))
{
break;
}
pdfDocument.Page = pdfDocument.AddPage();
if (pdfDocument.PageCount >= 3)
pdfDocument.Rect.Inset(0, 20);
documentId = pdfDocument.AddImageToChain(documentId);
}
另一種解決方案是將索引調整為required pagenumber - 1
因為ÀddImageHtml
已將第一頁添加到文檔中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.