PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jul 13, 2024 5:27 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Deleted column in table
PostPosted: Tue Jun 11, 2024 12:33 pm 
Offline

Joined: Tue Jun 11, 2024 12:25 pm
Posts: 5
It is posible deleted column in created table?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 11, 2024 1:18 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
It is possible to delete a column from a MigraDoc table.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 11, 2024 6:01 pm 
Offline

Joined: Tue Jun 11, 2024 12:25 pm
Posts: 5
Sorry,
is it possible to delete a column from a MigraDoc table, which method to use?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 12, 2024 6:41 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
The MigraDoc "Table" class has a "Columns" property that provides the "RemoveObjectAt" method. Index is 0-based.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 12, 2024 7:57 am 
Offline

Joined: Tue Jun 11, 2024 12:25 pm
Posts: 5
When I use "RemoveObjectAt" method, pdfRenderer.RenderDocument(); calls Exception:

Code:
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=MigraDoc.DocumentObjectModel
  StackTrace:
   at MigraDoc.DocumentObjectModel.Visitors.VisitorBase.VisitParagraph(Paragraph paragraph)
   at MigraDoc.DocumentObjectModel.Paragraph.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.DocumentElements.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Tables.Cell.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Tables.Row.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Tables.Rows.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Tables.Table.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.DocumentElements.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Section.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Sections.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Document.MigraDoc.DocumentObjectModel.Visitors.IVisitable.AcceptVisitor(DocumentObjectVisitor visitor, Boolean visitChildren)
   at MigraDoc.DocumentObjectModel.Visitors.VisitorBase.Visit(DocumentObject documentObject)
   at MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
   at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
   at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
   at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()


My method:

Code:
        public static void TabelWithBorderTest()
        {
           var document = new Document();

           // Add a section to the document.
           var section = document.AddSection();

           Table table = section.AddTable();
           table.Borders.Width = 0.25;
           table.Rows.LeftIndent = 0;

           // Before you can add a row, you must define the columns
           Column column = table.AddColumn("7cm");
           column.Format.Alignment = ParagraphAlignment.Left;
            //
            table.AddColumn("8cm");
            //

           Row row = table.AddRow();
           row.Cells[0].AddParagraph("Text 1");
            //
            row.Cells[1].AddParagraph("Text 2");
            table.Columns.RemoveObjectAt(0);
            //

            // Create a renderer for the MigraDoc document.
            var pdfRenderer = new PdfDocumentRenderer(false) { Document = document };

           // Associate the MigraDoc document with a renderer.

           // Layout and render document to PDF.
           pdfRenderer.RenderDocument();

           // Save the document...
           const string filename = "Table.pdf";
           pdfRenderer.PdfDocument.Save(filename);
           // ...and start a viewer.
           Process.Start(filename);
        }


Any ideas?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 12, 2024 8:29 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
viking wrote:
Any ideas?
I have no idea why you add a column and then delete it again, but it should work.
Are you using 6.1.0 final?

See also:
https://docs.pdfsharp.net/General/Issue-Reporting.html

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 12, 2024 10:11 am 
Offline

Joined: Tue Jun 11, 2024 12:25 pm
Posts: 5
I use 6.1.0 final.
I have table in two variants.
I create first all columns, next delete selected.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 13, 2024 8:05 am 
Offline

Joined: Tue Jun 11, 2024 12:25 pm
Posts: 5
When I create all columns but I dont use AddParagraph(); program is correct
Example:
Code:
Table table = section.AddTable();

table.AddColumn("7cm");
table.AddColumn("7cm");

Row row = table.AddRow();
table.Rows[0].Cells[0].AddParagraph("Text 1");

table.Columns.RemoveObjectAt(1);


If I use AddParagraph(); calls Exception

in attach my project.


Attachments:
ConsoleAppPDF.rar [18.62 KiB]
Downloaded 111 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group