Hi,
I have a PDF which has some static text and some dynamic text fields. I want to get the objects in a page and fill the data in the dynamic text fields where ever required. Apart from these dynamic text fields i want to add a table in the Aspose.PDF which has to be generated dynamically using .Net Datatable.This table may contain some n number of rows.Once the page limit is exceeded the rows should get displayed in the next page. Can anyone share the sample code snippet which suits the above scenario. Thanks in advance!
Hi Suchitra,
Thanks Nayyer for the reply. But the above code is not working. As i am using Aspose 7.3 version. Will this be possible with this version.
Hi,
Anyone know how to add dynamic pages to the existing PDF document. I have made many trials but i haven't seen the output yet. Currently am using 7.3 version Aspose dll. Below is the code snippet i have tried to add a page to the existing PDF. But this is not working. Am I missing anything in the below code. Please do the needful.
Aspose.Pdf.License license = new Aspose.Pdf.License();
////license.SetLicense(System.Web.HttpContext.Current.Server.MapPath("/AsposeTotal/Aspose.Total.lic"));
license.SetLicense(@"Aspose.Total.lic");
string strFilePath = @"Test.pdf";
Document pdfDocument = new Document(strFilePath);
//insert a empty page in a PDF
Aspose.Pdf.Page page = pdfDocument.Pages.Add();
// Add a 4th page in the existing PDF
pdfDocument.Pages.Insert(4, page);
//save output file
pdfDocument.Save("output.pdf");
Suchitra SS:But the above code is not working. As i am using Aspose 7.3 version. Will this be possible with this version.
//Instntiate the Document object by
calling its empty constructor<o:p></o:p>
Document doc = new Document("c:/pdftest/LineHeight_HTML2pdf.pdf");
// add table on first page
Page page = doc.Pages[1];
//Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
//Add the table in paragraphs collection of the desired section
page.Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = "50 50 50";
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
//Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
//Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
//Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("col1");
row1.Cells.Add("col2");
row1.Cells.Add();
TextFragment mytext = new TextFragment("col3 with large text string");
//row1.Cells.Add("col3 with large text string to be placed inside cell");
row1.Cells[2].Paragraphs.Add(mytext);
row1.Cells[2].IsWordWrapped = false;
//row1.Cells[2].Paragraphs[0].FixedWidth= 80;
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("item1");
row2.Cells.Add("item2");
row2.Cells.Add("item3");
//Save the Pdf
doc.Save(“c:/pdftest/33917.pdf”);
Suchitra SS:The above code is not working. As i am using Aspose 7.3 version. Will this be possible with this version.
Suchitra SS:Anyone know how to add dynamic pages to the existing PDF document. I have made many trials but i haven’t seen the output yet. Currently am using 7.3 version Aspose dll. Below is the code snippet i have tried to add a page to the existing PDF. But this is not working. Am I missing anything in the below code. Please do the needful.
// Load source PDF document<o:p></o:p>
Aspose.Pdf.Document doc = new Aspose.Pdf.Document("input.pdf");
// add a blank page to PDF file
doc.Pages.Add();
// Save updated document containing table object
doc.Save(“Blank_page_added.pdf”);
// Load source PDF document<o:p></o:p>
Aspose.Pdf.Document doc = new Aspose.Pdf.Document("input.pdf");
// get current page count of document and add new page after last page
doc.Pages.Insert(doc.Pages.Count + 1);
// Save updated document containing table object
doc.Save(“blank_page_added.pdf”);
Hi Nayyer,
Sorry for the delay in replying. The above code is working fine to me.
Here i have a question. How can i add a TextFragment dynamically.
Ex: for(int i=0;i<datatable.rows.count; i++)
{
var textfragment = new TextFragment(datatable.Rows[i][0].ToString()) { Position = new Position(108, 400) };
textfragment .TextState.FontSize = 10;
textfragment .TextState.Font = FontRepository.FindFont("TimesNewRoman");
textBuilder.AppendText(textfragment);
}
When i implement the above logic am able to add only one fragment to the page.
Is there is any way to implement.
Thanks in advance.
Hi Nayyer,
Can you please tell me how to add RowHeight and Columnheight for a table. As i am using Aspose.PDf 7.3 version.
Here is my sample code.
Aspose.Pdf.Table table = new Aspose.Pdf.Table(Convert.ToInt32(7), 5, rect)
{
IsOpaque = true,
BorderColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)
RowHeights = 30;
};
Thanks in advance.
Hi there,