|
Rank: Newbie Groups: Member
Joined: 4/29/2022 Posts: 4
|
I'm trying to generate a PDF file from a .NET dataset table using EO.Pdf.Acm however the documentation isn't very clear on how to generate the PDF file in this documentation on tables: LINKBasically I am pulling a single data record from a data source and putting it into a .NET datatable. Very basic really, ie: Name: John Doe Address: 123 Alcott Lane Email: jdoe@protonmail.comHere's a crack at the implementation code:
Code: C#
//create new pdf doc
PdfDocument doc = new PdfDocument();
EO.Pdf.Acm.AcmRender render = new EO.Pdf.Acm.AcmRender(doc);
//create new table, letter size
AcmTable table = new AcmTable(8.5f, 11f);
//new row
AcmTableRow row;
//iterate through data table created from datasource query
for (int rowCt = 0; rowCt <= dt.Rows.Count-1; rowCt++)
{
row = new AcmTableRow();
table.Rows.Add(row);
//column iteration
for (int colCt = 0; colCt <= dt.Columns.Count-1; colCt++)
{
//create cell for data description
AcmTableCell cell = new AcmTableCell(new AcmText(dt.Columns[colCt].ColumnName));
row.Cells.Add(cell);
//create cell for data
cell = new AcmTableCell(new AcmText(dt.Rows[rowCt].ItemArray[colCt].ToString()));
row.Cells.Add(cell);
//create a new row and add it to the table.
row = new AcmTableRow();
table.Rows.Add(row);
}
}
Not sure how the pdf generation is done since there are no clear implementation examples in the above link, but here's what I tried:
Code: C#
try
{
render.Render(table);
doc.Save("test.pdf");
}
catch (Exception ex) { }
Since this is WinForms and not HTML, It seemed like a good idea to use ACM to generate the PDF, but not sure... Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
Any kind of .NET project can use the HTML to PDF feature. Generally HTML to PDF is much easier to use than ACM.
Having that said, you can use ACM if you wish. The basic flow of your code is correct. Even though there are some obvious issues which I am not sure if it is due to copy/paste issue (For example, your code is missing the closing } for the inner for loop). Exactly what is your question about the code you posted?
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/29/2022 Posts: 4
|
Okay, I didn't know that we can use HTML to PDF since this is a Windows Form.
The problem/question that I have is that since there is no additional implementation details in the Table example (https://www.essentialobjects.com/doc/pdf/acm/advanced%20formatting/table).
IE: once the table is created, how is the PDF generated?
Since there was no example to generate a PDF after the table was created I tried this:
render.Render(table); doc.Save("test.pdf");
However this didn't produce any result.
Is there an example of how to generate a PDF from a windows form using HTML to PDF?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Tikhon wrote:render.Render(table); doc.Save("test.pdf");
However this didn't produce any result. Your code is correct. Can you explain what you mean by "didn't produce any result"? Did it generate any PDF file at all? Or it generated a PDF file but the PDF file is empty? Tikhon wrote:Is there an example of how to generate a PDF from a windows form using HTML to PDF? HTML to PDF has absoultely nothing to do with Windows Forms. So you can use any HTML to PDF sample code in the documentation.
|
|
Rank: Newbie Groups: Member
Joined: 4/29/2022 Posts: 4
|
eo_support wrote: Your code is correct. Can you explain what you mean by "didn't produce any result"? Did it generate any PDF file at all? Or it generated a PDF file but the PDF file is empty?
No PDF file was generated and no exception was thrown. Thanks again!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
It is not possible for this code not to create a file or throw an exception:
So the possibilities are: 1. The above code is not called at all. You can use a debugger to verify this; 2. The code is called and the file is created, but you are looking for it at the wrong location. To verify this, use an absolute path such as:
Hope this helps. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/29/2022 Posts: 4
|
Perfect!!
Got it thanks to your help...
God Bless..
|
|