PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Sep 25, 2013 12:50 am 
Offline

Joined: Tue Sep 24, 2013 11:29 pm
Posts: 2
Hello,

I have a issue with PDF. Is there any way that if the text gets cut off at the bottom of the PDF and it could be moved to the page? it is more likely page break.

Please see below a code. Can you help fixing this as soon as possible?

Below is a code:

Code:
 PIASection PIASectionBLL = new PIASection();
            PIASection5Info GetPIASection = PIASectionBLL.GetPIASection5(pia_id);

            PdfPage page = document.AddPage();
            page.Orientation = PageOrientation.Landscape;

            Generator.GenHeader(page, "PIA Section 5", pia_year);

            Document migDoc = new Document();

            Section section = migDoc.AddSection();
            section.AddPageBreak();

            Table table = section.AddTable();

 table.Format.Font.Size = 10;
            table.Format.Font.Name = "Times New Roman";
            table.Borders.Visible = false;
            table.Rows.VerticalAlignment = VerticalAlignment.Center;

            column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn("5cm");
            column.Format.Alignment = ParagraphAlignment.Left;

            table.Rows.Height = 15;

            row = table.AddRow();
            row.Shading.Color = Color.Parse("blue");
            row.Borders.Visible = true;
            row.Cells[0].AddParagraph("Program Office or IT System information is shared with");
            row.Cells[1].AddParagraph("Reason why information is shared with the specified program or IT system");
            row.Cells[2].AddParagraph("List the specific information types that are shared with the Program or IT system");
            row.Cells[3].AddParagraph("Legal authority, binding agreement, SORN routine use, etc that permit external sharing (can be more than one)");
            row.Cells[4].AddParagraph("Method of transmittal");

            for (int c = 0; c < 5; c++)
            {
                row.Cells[c].Shading.Color = Color.FromRgbColor((byte)255, Color.Parse("0x1E2D54"));
                row.Cells[c].Format.Font.Bold = true;
                row.Cells[c].Format.Font.Size = 7;
                row.Cells[c].Format.Font.Color = Color.Parse("white");
                row.Cells[c].Tag = "header";
            }
            if (GetPIASection.ExternalDataCollection != null)
            {

                if (GetPIASection.ExternalDataCollection.Count > 0)
                {
                    foreach (ExternalSharingInfo int_row in GetPIASection.ExternalDataCollection)
                    {
                        row = table.AddRow();
                        row.Borders.Visible = true;
                        row.Cells[0].AddParagraph(int_row.program_office);
                        row.Cells[0].Shading.Color = Color.Parse(green);
                        row.Cells[1].AddParagraph(int_row.reason_information);
                        row.Cells[1].Shading.Color = Color.Parse(green);
                        row.Cells[2].AddParagraph(int_row.list_information);
                        row.Cells[2].Shading.Color = Color.Parse(green);
                        row.Cells[3].AddParagraph(int_row.legal_auth);
                        row.Cells[3].Shading.Color = Color.Parse(green);
                        row.Cells[4].AddParagraph(int_row.method_trans);
                        row.Cells[4].Shading.Color = Color.Parse(green);
                    }
                }
                else
                {
                    row = table.AddRow();
                    row.Borders.Visible = true;
                    row.Cells[0].AddParagraph("");
                    row.Cells[0].Shading.Color = Color.Parse(green);
                    row.Cells[1].AddParagraph("");
                    row.Cells[1].Shading.Color = Color.Parse(green);
                    row.Cells[2].AddParagraph("");
                    row.Cells[2].Shading.Color = Color.Parse(green);
                    row.Cells[3].AddParagraph("");
                    row.Cells[3].Shading.Color = Color.Parse(green);
                    row.Cells[4].AddParagraph("");
                    row.Cells[4].Shading.Color = Color.Parse(green);
                }
            }
            else
            {
                row = table.AddRow();
                row.Borders.Visible = true;
                row.Cells[0].AddParagraph("");
                row.Cells[0].Shading.Color = Color.Parse(green);
                row.Cells[1].AddParagraph("");
                row.Cells[1].Shading.Color = Color.Parse(green);
                row.Cells[2].AddParagraph("");
                row.Cells[2].Shading.Color = Color.Parse(green);
                row.Cells[3].AddParagraph("");
                row.Cells[3].Shading.Color = Color.Parse(green);
                row.Cells[4].AddParagraph("");
                row.Cells[4].Shading.Color = Color.Parse(green);
            }


            row = table.AddRow();
            row = table.AddRow();
            row.Cells[0].AddParagraph("If specific measures have been taken to meet the requirements of OMB Memoranda M-06-15 and M-06-16 , note them here. ");
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph("Please explain in the text box");
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph(string.IsNullOrEmpty(GetPIASection.txtResponse1) ? "" : GetPIASection.txtResponse1);
            row.Cells[0].Shading.Color = Color.Parse(green);
            row.Cells[0].Borders.Width = borderWidth;
            row.Cells[0].Borders.Visible = true;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();

            row = table.AddRow();
            row.Cells[0].AddParagraph("5.2 PRIVACY IMPACT ASSESSMENT: External sharing and disclosure");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph("Discuss the privacy risks associated with the sharing of information outside the Department and what steps, if any, are currently being taken to mitigate those identified risks. ");
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();

            row = table.AddRow();
            row.Cells[0].AddParagraph("Discuss whether access controls have been implemented and whether audit logs are regularly reviewed to ensure appropriate sharing outside of the Department. For example, is there a Memorandum Of Understanding (MOU), contract, or agreement in place with outside agencies or foreign governments. Discuss how the sharing of information outside of the Department is compatible with the stated purpose and use of the original collection. ");
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();

            row = table.AddRow();
            row.Cells[0].AddParagraph(@"Follow the format below when entering your risk assessment:");
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph(@"Privacy Risk: ");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Font.Underline = Underline.Single;
            row.Cells[0].MergeRight = 4;
            row = table.AddRow();
            row.Cells[0].AddParagraph(@"Mitigation: ");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Font.Underline = Underline.Single;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph("Please explain in the text box");
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
            row.Cells[0].MergeRight = 4;

            row = table.AddRow();
            row.Cells[0].AddParagraph(string.IsNullOrEmpty(GetPIASection.txtResponse2) ? "" : GetPIASection.txtResponse2);
            row.Cells[0].Shading.Color = Color.Parse(green);
            row.Cells[0].Borders.Width = borderWidth;
            row.Cells[0].Borders.Visible = true;
            row.Cells[0].MergeRight = 4;


            // Render this page
            docRenderer = new DocumentRenderer(migDoc);
            docRenderer.PrepareDocument();

            gfx = XGraphics.FromPdfPage(page);

            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1), XUnit.FromCentimeter(10), "25cm", table);[/color]

            gfx.Dispose();



Thank you,
Chi Ming


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 25, 2013 9:06 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!
chipun wrote:
Is there any way that if the text gets cut off at the bottom of the PDF and it could be moved to the page? it is more likely page break.
When MigraDoc is used as intended, it will break the table to as many pages as are needed.

Use the technique shown in the Hello MigraDoc sample.

The technique shown in the Mix MigraDoc and PDFsharp sample is for experienced users. MigraDoc will tell you how many pages the document needs, but you have to add the pages and call the renderer to draw each page.

MigraDoc samples:
http://www.pdfsharp.net/wiki/MigraDocSamples.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 25, 2013 1:19 pm 
Offline

Joined: Tue Sep 24, 2013 11:29 pm
Posts: 2
Actually, I am new to MigraDoc and PDFsharp.

MigraDoc will tell you how many pages the document needs, but you have to add the pages and call the renderer to draw each page.

How will MigraDoc tell me how many pages the documents?


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 25, 2013 2:58 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
chipun wrote:
How will MigraDoc tell me how many pages the documents?
docRenderer.FormattedDocument.PageCount

See this sample:
http://www.pdfsharp.net/wiki/MixMigraDo ... Page_Two_2

It creates thumbnails of the pages on one page.
You would call AddPage(), get a gfx for the new page and then call docRenderer.RenderPage().
That's the complicated way.

This sample shows the simple way:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
Call renderer.RenderDocument() and the renderer will add all pages that are needed.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

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