vahidn / pdfreport Goto Github PK
View Code? Open in Web Editor NEWPdfReport is a code first reporting engine, which is built on top of the iTextSharp and EPPlus libraries.
License: GNU Lesser General Public License v3.0
PdfReport is a code first reporting engine, which is built on top of the iTextSharp and EPPlus libraries.
License: GNU Lesser General Public License v3.0
This library has been ported to .NET Core
https://github.com/VahidN/PdfReport.Core
Is it possible to download in memory pdf with jQuery ajax?
How can i remove extra space between a cell and html genereated cell?
view attached image.
tried this code, but nothing happens:
columns.AddColumn(column => {
column.PropertyName("User");
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(1);
column.Width(3);
column.HeaderCell("User");
column.CalculatedField(list =>
{
var user = list.GetSafeStringValueOf("User");
var photo = list.GetSafeStringValueOf("Photo");
var image = string.Format("<img src='{0}' />", photo);
return
@"<table style='width: 100%; font-size:9pt; border: 1px solid khaki; border-collapse: collapse;'>
<tr>
<td align='center' style='border: 1px solid khaki; border-collapse: collapse;'>" + user + @"</td>
</tr>
<tr>
<td align='center' style='border: 1px solid khaki; border-collapse: collapse;'>" + image + @"</td>
</tr>
</table>
";
});
column.ColumnItemsTemplate(template =>
{
template.XHtml();
//added this, but no sucess.
template.BasicProperties(new CellBasicProperties {
CellPadding = 0f,
PaddingBottom = 0f,
PaddingTop = 0f
});
});
});
The in-use version:
Operating system:
IDE: (e.g. Visual Studio 2015)
paste your core code
Exception message:
Full Stack trace:
hi all.
in PdfReport().Generate function
i have below code that works :
var fileName = string.Format("{0}-rpt.pdf", Guid.NewGuid().ToString("N")); fileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8); data.AsPdfFile(HttpContext.Current.Server.MapPath("~/Content/Temp/") + fileName);
but when i flush data to browser program goes to infinite loop :
data.FlushInBrowser(fileName, FlushType.Inline);
what`s wrong?
both codes work on localhost but on the server only top code works.
I want to limit the number of columns in the main table. Lets say the table will have 10 columns and then the limit will be 5, the first 5 columns will be in the first page and the second 5 columns will be on the next page. Is this doable?
Generate Excel,CSV File using this libiary
DatSource
And it is not a calculated field.
Say, for example in PdfReportSamples.Models
, UserMonthCalendar
, i have this new field:
public class UserMonthCalendar {
public int Id { set; get; }
public string Name { set; get; }
//new field added
public bool Nodata { set; get; }
public CalendarData MonthCalendarData { set; get; }
}
then i want to be able to do something like :
columns.AddColumn(column => {
if ( (bool)list.GetValueOf<UserMonthCalendar>(x => x.Nodata)) {
column.PropertyName<UserMonthCalendar>(x => x.Name);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(2);
column.Width(1);
column.HeaderCell("نام");
} else {
column.PropertyName<UserMonthCalendar>(x => x.MonthCalendarData);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(3);
column.Width(3);
column.HeaderCell("تقويم ماهيانه");
column.ColumnItemsTemplate(itemsTemplate =>
{
itemsTemplate.MonthCalendar(new CalendarAttributes
{
CalendarType = CalendarType.PersianCalendar,
UseLongDayNamesOfWeek = true,
Padding = 3,
DescriptionHorizontalAlignment = HorizontalAlignment.Center,
SplitRows = true,
CellsCustomizer = info =>
{
if (info.Year == 1391 && info.Month == 1 && info.DayNumber == 1)
{
info.NumberCell.BackgroundColor = new BaseColor(System.Drawing.Color.LimeGreen.ToArgb());
var phrase = info.NumberCell.Phrase;
foreach (var chunk in phrase.Chunks)
chunk.Font.Color = new BaseColor(System.Drawing.Color.Yellow.ToArgb());
}
}
});
});
}
});
but list
is avaiable only in CalculatedField
, and here the column is not a CalculatedField
but a ConditionalColumn
Also, many thanks for your great work.
The in-use version: 2.9.2
I'm using AcroFormTemplate and I want to add some photos to the next pages after first page using pdfreport.
How can I do that?
My source code(but not work):
MainTableColumns(columns =>
{
columns.AddColumn(column =>
{
column.Width(3);
column.PropertyName<FormReport>(x => x.Id);
column.HeaderCell(caption: "");
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(1);
column.ColumnItemsTemplate(template =>
{
template.PdfTemplate(
pdfTemplatePath: pdfTemplatePath,
onFillAcroForm: (data, form, pdfStamper) =>
{
form.GenerateAppearances = true;
foreach (var item in data)
{
var value = item.PropertyValue == null ? string.Empty : item.PropertyValue.ToString();
if (item.PropertyNameEquals<FormReport>(x => x.Image))
{
var images = value.Split(',');
for (int i = 0; i < images.Length; i++)
{
var size = PageSize.A4;
pdfStamper.InsertPage(i + 2, PageSize.A4);
var pdfImage = Image.GetInstance(images[i]);
pdfImage.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
pdfImage.SetAbsolutePosition(0, size.Height - pdfImage.Height);
pdfImage.ScaleToFit(size.Width, size.Height);
pdfStamper.GetOverContent(i + 2).AddImage(pdfImage);
}
}
else
{
form.SetField(item.PropertyName, value);
}
}
});
});
});
}
Dear Vahid, again thanks for this great library.
I finally selected HTML Cell for issue in #5
I changed your HtmlCellTemplatePdfReport
as in GIST, and then it is not rendered(noting is generated) and get the exception, but changing following function in PdfRpt.Core.Helper.HtmlToPdf.RtlElementsCollector
, corrects everything.
The change is just a simple double check and includes a try-catch-donothing
block.
private static void fixNestedTablesRunDirection(IElement element) {
var table = element as PdfPTable;
if (table == null) {
return;
}
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
//added this line
if (null == table.Rows || table.Rows.Count == 0) {
return;
}
//to here
foreach (var row in table.Rows) {
//added this try-catch
try {
var innerCells = row.GetCells();
//also this line
if (null == innerCells || innerCells.Length ==0) {
return;
}
//to here
foreach (var cell in innerCells ) {
cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
if (cell.CompositeElements == null) {
continue;
}
foreach (var item in cell.CompositeElements) {
fixNestedTablesRunDirection(item);
}
}
} catch {
}
}
}
if desired, i can send a pull request.
The in-use version: 2.9.2
Exception message:
Full Stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
PdfRpt.Core.Helper.HtmlToPdf.RtlElementsCollector.fixNestedTablesRunDirection(IElement element) +283
PdfRpt.Core.Helper.HtmlToPdf.RtlElementsCollector.Add(IWritable htmlElement) +614
iTextSharp.tool.xml.pipeline.end.ElementHandlerPipeline.Consume(IWorkerContext context, ProcessObject po) +36
iTextSharp.tool.xml.pipeline.end.ElementHandlerPipeline.Close(IWorkerContext context, Tag t, ProcessObject po) +15
iTextSharp.tool.xml.XMLWorker.EndElement(String tag, String ns) +181
iTextSharp.tool.xml.parser.XMLParser.EndElement() +111
iTextSharp.tool.xml.parser.state.ClosingTagState.Process(Char character) +61
iTextSharp.tool.xml.parser.XMLParser.ParseWithReader(TextReader reader) +247
iTextSharp.tool.xml.parser.XMLParser.Parse(TextReader reader) +5
PdfRpt.Core.Helper.HtmlToPdf.XmlWorkerHelper.processHtml(IElementHandler elementsHandler) +1281
PdfRpt.Core.Helper.HtmlToPdf.XmlWorkerHelper.RenderHtml() +112
PdfRpt.ColumnsItemsTemplates.XHtmlField.RenderingCell(CellAttributes attributes) +183
PdfRpt.Core.Helper.TableCellDefinitionsExt.runOnItemsTemplate(CellAttributes pdfRptTableCellDefinition, IColumnItemsTemplate defaultItemTemplate) +20
PdfRpt.Core.Helper.TableCellDefinitionsExt.CreateSafePdfPCell(CellAttributes pdfRptTableCellDefinition, IColumnItemsTemplate defaultItemTemplate) +34
PdfRpt.Core.PdfTable.TableCellHelper.AddGeneralCell(BaseColor backgroundColor, BaseColor foreColor, Object rawData, Int32 columnNumber, RowType pdfRowType, CellType pdfCellType, IList`1 rowValues, HorizontalAlignment horizontalAlignment, DocumentFontStyle pdfFontStyle, Int32 rotation, Boolean setItemTemplate, Int32 colSpan) +1145
PdfRpt.Core.PdfTable.TableCellHelper.AddRowCell(IList`1 rowValues, BaseColor backgroundColor, BaseColor foreColor, Int32 columnNumber) +325
PdfRpt.Core.PdfTable.RowsManager.addTableRow(IList`1 rowData, BaseColor backgroundColor, BaseColor foreColor) +129
PdfRpt.Core.PdfTable.RowsManager.addSingleRow(IList`1 row) +243
PdfRpt.Core.PdfTable.RowsManager.printNormalTable() +129
PdfRpt.Core.PdfTable.RowsManager.AddMainTableRows() +255
PdfRpt.Core.PdfTable.RenderMainTable.AddToDocument() +24
PdfRpt.PdfReportDocument.addMainTable() +88
PdfRpt.PdfReportDocument.createPdf() +344
PdfRpt.<>c__DisplayClass38_0.<runInReleaseMode>b__0(Document pdfDisposable) +24
PdfRpt.Core.Helper.Guard.SafeUsingBlock(TDisposable disposable, Action`1 action, Func`2 unwrapper) +54
I am using AcroFormTemplatePdfReport, it works as expected, but I also need to pass some image(s) as parameter to the template. I looked at the toolbar on OpenOffice, it only has image button which actually is a button not an image. Is there a workaround for it?
PS: I also tried XHtmlHeader but the problem with this approach is that, it scales down the main template.
One more thing: PdfReport is really great! thanks 👍👍👍
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.