MigraDoc GDI 1.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);
ドキュメントのレンダリング後にページサイズを設定するのが悪い考え。 'section.PageSetup = document.DefaultPageSetup.Clone();'という行を取るとうまくいくのですか? –
ありがとうございました!!!それがトリックでした。それでは、なぜこのURLは「あなたはDefaultPageSetupを変更してはいけません、代わりにClone()を使うべきです」と言っていますか? http://stackoverflow.com/questions/32757196/how-can-set-the-page-size-of-migradocレンダリング後のページサイズの設定もやめました。それは、暗闇の中でちょうどそのショットが問題を解決したかどうかを確認することでした – Hoppe
ポイントは:DefaultPageSetupを変更しないでください。 DefaultPageSetupのクローンを割り当てるかどうかにかかわらず、セクションのPageSetupを変更します。 –