2012-10-30 3 views
2

문제는 abcpdf에 의해 생성 된 pdf 파일의 각 페이지에 포함해야하는 헤더 파일입니다.ABCPDF 헤더 크기 및 위치 계산.

헤더 파일에는 두 개 이상의 이미지 파일과 여러 줄의 텍스트가 있으며 대소 문자에 따라 다릅니다.

문제는 헤더의 크기를 계산하는 방법을 모르겠다는 것입니다. 헤더와 함께 각 페이지에 html 파일의 나머지 부분을 배치하기 위해 사각형 위치를 할당 할 크기가 필요합니다. C#을 사용하고 있습니다.

답변

2

먼저 헤더를 추가 할 수 있도록 상단에 충분한 공간이있는 문서를 만들어야합니다. 아래 설정은 페이지의 약 1/5 인 헤더가있는 일반 A4 문서 용입니다. 밖으로 아래의 코드를 사용하여 이미지에서 다음 헤더 이미지, 문서의 각 페이지에 걸쳐 색 상자 헤더를두고

//Setting to create the document using ABCPdf 8 
var theDoc = new Doc(); 
theDoc.MediaBox.String = "A4"; 

theDoc.HtmlOptions.PageCacheEnabled = false; 
theDoc.HtmlOptions.ImageQuality = 101; 
theDoc.Rect.Width = 719; 
theDoc.Rect.Height = 590; 
theDoc.Rect.Position(2, 70); 
theDoc.HtmlOptions.Engine = EngineType.Gecko; 

.. 오른쪽 하단이 아닌 상단 왼쪽에서있는 PDF 파일에 좌표를 기억

이 경우 헤더 이미지는 인쇄 할 때 이미지가 너무 선명하게 보이지 않도록 이미지의 해상도를 가능한 높게 유지하기 위해 1710 x 381입니다.

private static Doc AddHeader(Doc theDoc) 
{ 
    int theCount = theDoc.PageCount; 
    int i = 0; 

    //Image header 
    for (i = 1; i <= theCount; i++) 
    { 
     theDoc.Rect.Width = 590; 
     theDoc.Rect.Height = 140; 
     theDoc.Rect.Position(0, 706); 

     theDoc.PageNumber = i; 
     string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png"); 

     Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath); 
     theDoc.AddImage(myBmp); 
    } 

    //Blue header box 
    for (i = 2; i <= theCount; i++) 
    { 
     theDoc.Rect.String = "20 15 590 50"; 
     theDoc.Rect.Position(13, 672); 
     System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#468DCB"); 
     theDoc.Color.Color = c; 
     theDoc.PageNumber = i; 
     theDoc.FillRect(); 
    } 

    //Blue header text 
    for (i = 2; i <= theCount; i++) 
    { 
     theDoc.Rect.String = "20 15 586 50"; 
     theDoc.Rect.Position(25, 660); 
     System.Drawing.Color cText = System.Drawing.ColorTranslator.FromHtml("#ffffff"); 
     theDoc.Color.Color = cText; 
     string theFont = "Century Gothic"; 
     theDoc.Font = theDoc.AddFont(theFont); 
     theDoc.FontSize = 14; 
     theDoc.PageNumber = i; 
     theDoc.AddText("Your Text Here"); 
    } 
    return theDoc; 
}