How do I make ABCPdf to automatically write to a new page when text requires more than 1 page?

StackOverflow https://stackoverflow.com/questions/23535842

  •  17-07-2023
  •  | 
  •  

Вопрос

I deal with dynamic input text, so the pages should be dynamically created. If page 1 is already full, it should write to a new page, so it means I can have page 2, page 3 and so on depending on the data processed.

Currently, my text is truncated. Only writes Page 1, the rest of data are not written.

My current code below:

//add page 1
theDoc.Page = theDoc.AddPage();
theDoc.AddImageHtml(html, true, 826, true);

//continue adding page if needed                             
while (theDoc.GetInfo(theID, "Truncated") == "1")
{
   theDoc.Page = theDoc.AddPage();
   theDoc.AddImageHtml(html, true, 826, true);
}

//save file
String pdfFilePath = WebConfigurationManager.AppSettings["pdfFilePath"];
Guid fileName = Guid.NewGuid();
pdfLink = pdfFilePath + fileName.ToString() + ".pdf";
theDoc.Save(pdfLink);
theDoc.Clear();

variable html contains all the data(webpage), I'm probably missing something in my while loop. Any help is appreciated! Thanks

Это было полезно?

Решение

Found it, Use Chainable and then Flatten()

theDoc.Page = theDoc.AddPage();
int theID;
theID = theDoc.AddImageUrl("http://www.yahoo.com/");

while (true) {
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
  break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}

for (int i = 1; i <= theDoc.PageCount; i++) {
   theDoc.PageNumber = i;
  theDoc.Flatten();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top