XPS 문서에서 PageHeight를 선언하려고 할 때 문제가 있습니다.XpsDocument가 높이 설정을 무시합니다.
내 코드는 지금까지 다음과 같습니다
private FixedDocumentSequence GetDocument(DocumentPaginator paginator)
{
FixedDocumentSequence document = null;
string tempFileName = System.IO.Path.GetTempFileName();
File.Delete(tempFileName);
using (var xpsDocument = new XpsDocument(tempFileName, FileAccess.ReadWrite, CompressionOption.NotCompressed))
{
var writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
var printTicket = new PrintTicket
{
PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4, paginator.PageSize.Width, paginator.PageSize.Height),
PageBorderless = PageBorderless.Borderless,
PageMediaType = PageMediaType.None,
};
writer.Write(paginator, printTicket);
//paginator.PageSize.Height = 1122
var d = xpsDocument.GetFixedDocumentSequence();
//d.DocumentPaginator.PageSize.Height = 1056
document = d;
}
return document;
}
문제는 내가이 코드에서 얻고 1122의 페이지 크기 높이 선언하고 있다는 것입니다 : 내가 볼 때
var pd = new PrintDialog();
var sz = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
을하지만, 재산으로
d.DocumentPaginator.PageSize.Height
높이가 인 것을 볼 수있다 1056이 높이는 NorthAmericanLetter Page 형식 높이의 높이가됩니다. 명시 적 PageMediaSize가있는 특정 printTicket을 이미 지정하고 있습니다.
편집 : 여기
내 코드를 편집하지만,이 같은 결과 제공 :
private FixedDocumentSequence GetDocument(DocumentPaginator paginator)
{
FixedDocumentSequence document = null;
string oldTempFileName = System.IO.Path.GetTempFileName();
File.Delete(oldTempFileName);
XpsDocument oldXpsDocument;
using (oldXpsDocument = new XpsDocument(oldTempFileName, FileAccess.ReadWrite, CompressionOption.NotCompressed))
{
var writer = XpsDocument.CreateXpsDocumentWriter(oldXpsDocument);
var printTicket = new PrintTicket
{
PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4, paginator.PageSize.Width, paginator.PageSize.Height),
PageBorderless = PageBorderless.Borderless,
PageMediaType = PageMediaType.None,
};
writer.Write(paginator, printTicket);
}
//string newTempFileName = System.IO.Path.GetTempFileName();
//File.Delete(newTempFileName);
using (var newXpsDocument = new XpsDocument(oldTempFileName, FileAccess.Read, CompressionOption.NotCompressed))
{
var d = newXpsDocument.GetFixedDocumentSequence();
document = d;
}
return document;
}
는 내가 처음 사용하는 블록으로 만든있어 파일에 보면서 난 아직도 볼 수 있습니다
<FixedPage
xmlns="http://schemas.microsoft.com/xps/2005/06" xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key"
xml:lang="und"
Width="816" Height="1056">
<FixedPage.Resources>
<ResourceDictionary>
<LinearGradientBrush x:Key="b0" StartPoint="33,0" EndPoint="33,23" ColorInterpolationMode="SRgbLinearInterpolation" MappingMode="Absolute" SpreadMethod="Pad">
Edit2가 : 페이지의 높이가 1056의 1.fpage 파일의 출력이다
내 문제의 해결책을 찾았습니다. 내 DocumentPaginator에서 GetPage 메서드를 재정의해야하고 새 DocumentPage (visual)를 반환해야합니다.이 생성자에는 PageSize를 올바르게 설정 한 경우에만 PageSize를 설정할 수있는 오버로드가 있습니다. http://msdn.microsoft.com/en-us/library/ms597306(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.windows.documents.documentpage(v=vs.110).aspx 내 앞의 코드 : 두 번째 생성자와 지금
public override DocumentPage GetPage(int pageNumber)
{
// create page element (PageTemplate is a custom usercontrol that can hold content)
var page = new PageTemplate(this, pageNumber + 1);
// arrange the elements on the page
page.Arrange(new Rect(0, 0, PageSize.Width, PageSize.Height));
// return new document page
return new DocumentPage(page);
}
:
public override DocumentPage GetPage(int pageNumber)
{
// create page element (PageTemplate is a custom usercontrol that can hold content)
var page = new PageTemplate(this, pageNumber + 1);
// arrange the elements on the page
page.Arrange(new Rect(0, 0, PageSize.Width, PageSize.Height));
// return new document page
return new DocumentPage(page, PageSize, new Rect(0, 0, 10, 10), new Rect());
}
Win7에서 32 비트 응용 프로그램으로 실행하는 동안 응용 프로그램에서이 작업을 수행하지 않아도되었습니다. 저는 지금 Win8.1에 있는데, 제 인쇄 작업은 조경 작업을하기 시작했습니다. 그러나 결과는 초상화로 인쇄되었습니다. 나는이 포스트에서 끝내고, 오버로드 된 생성자를 사용했고, 이제 나의 결과는 예상대로이다. 감사! – Kcvin
@Netscape 문제가 없습니다. - 당신이 질문에 대답 한 사람이라는 것을 알았을 때 축하해주었습니다. 제 경험으로 이익을 얻을 수 있다는 것을 알았 기 때문에 기뻤습니다. –
감사. 니가 내 목숨을 구했어! – Brcinho