Code Monkey home page Code Monkey logo

pdfreport's People

Contributors

vahidn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdfreport's Issues

[Question] How can remove space between cell and HtmlTablecell template

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
					 });
				 });
			 });

image

Infinite loop in PdfReport and FlushInBrowser

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.

Limit columns in maintable

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?

Conditional table column type creation, base on DataSource Field

creating table column type (or value) base on some condition on 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.

Environment

The in-use version: 2.9.2

How to insert page after existing pdf form

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);
                                        }
                                    }
                                });
                        });
                    });
                }

Exception in fixNestedTablesRunDirection with nested table

Summary of the issue

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.

Environment

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

Passing image as parameter to XML Form document

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 👍👍👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.