PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 20, 2024 2:16 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Aug 19, 2016 10:53 am 
Offline

Joined: Fri Aug 19, 2016 10:31 am
Posts: 2
I was trying to generate a PDF file using Migradoc and PDFsharp with the following elements in it.
1. A paragraph with a long text in it
2. A table with one row and one column
The page format used is Letter and orientation is Landscape.
The PDF file got generated with both the elements, but the paragraph was displayed in full page width but the table was lesser in width. I have attached the screen of the generated file.
My code is as below:
Code:
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            //Add section to document
            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();
            //assign page format and orientation
            document.DefaultPageSetup.PageFormat = PageFormat.Letter;
            document.DefaultPageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
            //Add a section to document
            MigraDoc.DocumentObjectModel.Section section = document.AddSection();
            //Get the page size for the specified page format
            Unit Width, Height;
            PageSetup.GetPageSize(PageFormat.Letter, out Width, out Height);
            //Add a paragraph in to the section with long string
            section.AddParagraph("fejhfwehfhefehw fehwfjke fhehf wejkfh  jfhef hwejfhewjf hwefhwe hfjwe  jhefjhew jfhwejfhe jehje hfjwe hfjkehf jefh ehfejf hejkfhew fjkwehfjk wehfjw ehfjwe hjkfwe hjfhwe jkfhwe jkfhwef hwe jkfke gfdg fgdfg fdgdf gdf dfgdfg dfgdfg dfgdfg ");
           
            //Below table to be added to the section
            MigraDoc.DocumentObjectModel.Tables.Table migradocTable = new MigraDoc.DocumentObjectModel.Tables.Table();
            MigraDoc.DocumentObjectModel.Tables.Column column;
            //Add one column to the table
            for (int i = 0; i < 1; i++)
            {
                column = migradocTable.AddColumn(Width);
                column.Borders.Visible = true;
                column.Borders.Width = 1;
            }

            for (int i = 0; i < 1; i++)
            {
                //Add one row to the table
                MigraDoc.DocumentObjectModel.Tables.Row row = migradocTable.AddRow();
                row.Cells[i].AddParagraph("Test.....");
            }
            //Add the table to the section
            section.Add(migradocTable);
            //Render document
            renderer.Document = document;
            renderer.RenderDocument();
            //Save the document
            renderer.PdfDocument.Save("C:\\Sample.pdf");


Please help me to make both paragraph and table of same width and they have to take the full page width of the document (both margins can be subtracted from the page width).


Attachments:
Sample.PNG
Sample.PNG [ 7.81 KiB | Viewed 7027 times ]
Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 19, 2016 1:34 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 915
Location: CCAA
Hi!
sumith wrote:
Please help me to make both paragraph and table of same width and they have to take the full page width of the document (both margins can be subtracted from the page width).
You set format to Landscape, so the width of the page will be the Height of a Letter page.
So the width of the tabke should be the value of "height" minus left margin minus right margin.

The margins will return 0 if you do not set any values. Use "DefaultPageSetup" to query the default values.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 23, 2016 4:45 am 
Offline

Joined: Fri Aug 19, 2016 10:31 am
Posts: 2
Thanks Thomas. I missed that. Done the changes according to your answer and it works fine now.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 224 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