2015-02-07 5 views
2

MigraDoc을 사용하여 PDF를 만들고 있는데 첫 페이지와 첫 번째 페이지에 바닥 글이 있고 나머지 모든 페이지 (첫 번째 페이지는 제외)에 머리말이 있어야합니다. 나는 DifferentFirstPageHeaderFooter으로 실험했으나 필요한 결과를 얻지 못했습니다. 해당 설정과 머리글과 바닥 글을 추가 할 수있는 적절한 조합이 있다는 것을 알고 있지만 무엇이 있는지 모르겠습니다. 나는 MigraDoc 청구서 샘플에 기초를두고 있습니다. 표지는 섹션이며 나머지 문서는 페이지 나누기가있는 섹션입니다. 페이지 당 하나의 섹션으로 나눌 필요가 있을까요? 모든 팁 주셔서 감사.MigraDoc 머리말과 꼬리

편집

내가 보여 헤더를 얻었으나, 내가 뭘하는지보다 그것을 할 수있는 더 좋은 방법이처럼 보인다. 꼬리말이 전혀 나타나지 않습니다. 여기에 내가 그들을 추가 해요 어디 :

Document document = new Document(); 
Section section = document.AddSection(); 

section.PageSetup.DifferentFirstPageHeaderFooter = true;   

Paragraph paragraph = section.Footers.Primary.AddParagraph(); 
paragraph.AddFormattedText(ReportName, TextFormat.Bold); 
paragraph.AddText("\nCreated on "); 
paragraph.AddFormattedText(CreateDate, TextFormat.Bold); 
paragraph.AddFormattedText("\n" + Properties.Length, TextFormat.Bold); 
paragraph.AddText(" Records"); 
paragraph.AddFormattedText("\n" + TurnoverPercent, TextFormat.Bold); 
paragraph.AddText(" Turnover Rate"); 
paragraph.Format.Font.Size = 10; 
paragraph.Format.Alignment = ParagraphAlignment.Center; 

// Later, in a different method... 
Section section = document.AddSection(); 

    // Header image 
    Image image = section.Headers.Primary.AddImage(filename); 
    image.Height = "2.5cm"; 
    image.LockAspectRatio = true; 
    image.RelativeVertical = RelativeVertical.Line; 
    image.RelativeHorizontal = RelativeHorizontal.Margin; 
    image.Top = ShapePosition.Top; 
    image.Left = ShapePosition.Right; 
    image.WrapFormat.Style = WrapStyle.Through; 

    image = section.Headers.FirstPage.AddImage(filename); 
    image.Height = "2.5cm"; 
    image.LockAspectRatio = true; 
    image.RelativeVertical = RelativeVertical.Line; 
    image.RelativeHorizontal = RelativeHorizontal.Margin; 
    image.Top = ShapePosition.Top; 
    image.Left = ShapePosition.Right; 
    image.WrapFormat.Style = WrapStyle.Through; 

나는 차 및 FirstPage에 바닥 글 단락을 추가 시도하고 변화를 보이지 않았다. DifferentFirstPageHeaderFooter은 전체 문서가 아닌 섹션에만 적용됩니까?

+0

왜 downvote입니까? – nasch

+0

FirstPage 헤더는 첫 번째 페이지에서 사용됩니다. 귀하의 경우 Primary 헤더는 다른 모든 페이지에서 사용됩니다. 둘 다 설정하면 모든 페이지에 헤더가 생깁니다. 1.50 베타 버전을 사용하고 있습니까? 아니면 이전 버전입니까? –

+0

음, 알아 냈습니다. 'DifferentFirstPageHeaderFooter'는 설정 한 섹션에만 적용되는 것이 아니라 모든 섹션에 적용되는 것으로 보입니다. 일단 각 섹션에서 적절하게 설정하면 문제가 모두 해결되고 머리말과 꼬리말이 내가 원하는 곳에 나타납니다. – nasch

답변

2

음, 알아 냈습니다. DifferentFirstPageHeaderFooter은 설정 한 섹션에만 적용되는 것이 아니라 모든 섹션에 적용되는 것으로 보입니다. 일단 각 섹션에서 적절하게 설정하면 문제가 모두 해결되고 머리말과 꼬리말이 내가 원하는 곳에 나타납니다. 여기에 업데이트 된 코드가 있습니다.

Section section = document.AddSection(); 

section.PageSetup.DifferentFirstPageHeaderFooter = true;   

Paragraph paragraph = section.Footers.FirstPage.AddParagraph(); 
paragraph.AddFormattedText(ReportName, TextFormat.Bold); 
paragraph.AddText("\nCreated on "); 
paragraph.AddFormattedText(CreateDate, TextFormat.Bold); 
paragraph.AddFormattedText("\n" + Properties.Length, TextFormat.Bold); 
paragraph.AddText(" Records"); 
paragraph.AddFormattedText("\n" + TurnoverPercent, TextFormat.Bold); 
paragraph.AddText(" Turnover Rate"); 
paragraph.Format.Font.Size = 10; 
paragraph.Format.Alignment = ParagraphAlignment.Center; 

// Later, in a different method... 
Section section = document.AddSection(); 

// Need to do this even though we've never set this field on this section 
section.PageSetup.DifferentFirstPageHeaderFooter = false; 

    // Header image 
    Image image = section.Headers.Primary.AddImage(filename); 
    image.Height = "2.5cm"; 
    image.LockAspectRatio = true; 
    image.RelativeVertical = RelativeVertical.Line; 
    image.RelativeHorizontal = RelativeHorizontal.Margin; 
    image.Top = ShapePosition.Top; 
    image.Left = ShapePosition.Right; 
    image.WrapFormat.Style = WrapStyle.Through; 
+0

섹션에 설정 한 등록 정보는 덮어 쓰기 될 때까지 다음 섹션 모두에 상속됩니다. –

+1

그래, 알아 냈어. 문서에서 명확하지 않은 많은 것들 중 하나입니다. – nasch

1

DifferentFirstPageHeaderFooter이 필요합니다.

아마 코드가 올바르지 않을 수 있습니다. 예, 코드를보고 싶습니다. 코드를 보지 않고 어떻게 도울 수 있습니까?

섹션 당 하나의 페이지가있는 많은 섹션이 작동하지만 MigraDoc이 사용되는 방식은 아닙니다.

+0

코드를 추가했습니다. (코드를 표시하지 않고 마지막 질문에 답을했기 때문에 항상 필요한 것은 아닙니다!). 페이지 및 섹션에 대해 설명하고 작동 방법에 대해 설명해 주시겠습니까? 나는 그들의 문서가 아주 철저하지 않다는 것을 안다. – nasch

+1

도움말 페이지에는 "코드를 포함하면 모든 질문에 도움이되는 것은 아니지만 작성한 코드에 문제가있는 경우이를 포함시켜야합니다." 코드가 예상대로 작동하지 않습니다. –