Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要删除合法页面格式顶部的大边距吗_C#_Pdfsharp_Migradoc - Fatal编程技术网

C# 要删除合法页面格式顶部的大边距吗

C# 要删除合法页面格式顶部的大边距吗,c#,pdfsharp,migradoc,C#,Pdfsharp,Migradoc,我在GDI1.50.4000-beta3b和1.32.4334.0中尝试了下面的代码。当我将页面大小设置为合法格式时,它要么没有转换为合法格式,要么在顶部留有一个很大的空白,就好像页面大小是8.5 x 11,额外的长度插入到PDF的顶部。我宁愿文本从页首开始。我怎样才能避开这件事 在下面的示例中,顶部有一个很大的空白 // Create a new MigraDoc document Document document = new Document(); //document.UseCmykCo

我在GDI1.50.4000-beta3b和1.32.4334.0中尝试了下面的代码。当我将页面大小设置为合法格式时,它要么没有转换为合法格式,要么在顶部留有一个很大的空白,就好像页面大小是8.5 x 11,额外的长度插入到PDF的顶部。我宁愿文本从页首开始。我怎样才能避开这件事

在下面的示例中,顶部有一个很大的空白

// Create a new MigraDoc document
Document document = new Document();
//document.UseCmykColor = true;

// Add a section to the document
Section section = document.AddSection();
section.PageSetup = document.DefaultPageSetup.Clone();
section.PageSetup.PageFormat = PageFormat.Legal; //setting page size here didn't seem to work
section.PageSetup.TopMargin = "0cm";

// Add a paragraph to the section
Paragraph paragraph = section.AddParagraph();

paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50);

// Add some text to the paragraph
paragraph.AddFormattedText(@"Hello World!", TextFormat.Bold);

#if GDI
// Using GDI-specific routines.
// Make sure to use "#if GDI" for any usings you add for platform-specific code.
{
}
#endif

#if WPF
// Using WPF-specific routines.
// Make sure to use "#if GDI" for any usings you add for platform-specific code.
{
}
#endif

// Create a renderer for the MigraDoc document.
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

// Associate the MigraDoc document with a renderer
pdfRenderer.Document = document;

// Layout and render document to PDF
pdfRenderer.RenderDocument();

pdfRenderer.PdfDocument.Pages[0].Size = PdfSharp.PageSize.Legal;

// Save the document...
const string filename = "HelloWorld.pdf";

pdfRenderer.PdfDocument.Save(filename);
// ...and start a viewer.
Process.Start(filename);

PageFormat
用于设置未设置的
PageWidth
PageHeight

调用
section.PageSetup=document.DefaultPageSetup.Clone()
PageWidth
PageHeight
分配A4大小的值。以后更改
PageFormat
对保持A4的有效页面大小没有影响

调用
section.PageSetup=document.DefaultPageSetup.Clone()后
必须将
PageWidth
PageHeight
设置为正确的值

section.PageSetup=document.DefaultPageSetup.Clone()用于初始化页面设置的所有值。如果使用PageSetup根据页边距等进行计算,请使用此选项

通常不建议调用
section.PageSetup=document.DefaultPageSetup.Clone()。强烈建议使用
Clone()
而不是直接更改
DefaultPageSetup


如果不指定
Clone()

在呈现文档后设置页面大小,则设置
PageFormat
的效果与预期一样。如果使用
section.PageSetup=document.DefaultPageSetup.Clone()行,它是否有效退出?非常感谢!!!这就成功了。那么为什么这个URL会说“您永远不应该修改DefaultPageSetup,而应该使用Clone()”?渲染后,我也停止设置页面大小。这只是一个在黑暗中拍摄,看看它是否解决了问题的要点是:不要修改DefaultPageSetup。修改节的页面设置,无论是否指定DefaultPageSetup的克隆。