2011-03-16 4 views
1

Salut il j'avais utilisé avec succès cette grande bibliothèque PDF Sharp.now je voulais jouer avec des trucs dynamiques afin que les gens recomended pour passer à Migradoc je l'ai fait et comme sa fonction de paragraphe.Maintenant le problème est-ce quand j'ajoute le long paragraphe alors la nouvelle page n'est pas ajoutée au lieu de cela est le texte incomplet montré (incomplet dans le sens que le texte déborde) et j'ai ajouté une image en bas pour le footer look.how que je peux faire texte (longueur variable) et il ajoute juste le nombre requis de pages.Automatique Nouvelle page basée sur le texte

Mon code est jusqu'à présent

XFont font = new XFont("Times New Roman", 12, XFontStyle.Bold); 
      XFont fontReg = new XFont("Times New Roman", 12, XFontStyle.Regular); 

      // HACK² 
      gfx.MUH = PdfFontEncoding.Unicode; 
      gfx.MFEH = PdfFontEmbedding.Default; 

      string appPath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); 
      XImage image = XImage.FromFile(appPath + "/header.png"); 
      gfx.DrawImage(image, 0, 0); 
      //Civil Stamp 
      gfx.DrawImage(XImage.FromFile(appPath + "/cStamp.png"), 370, 380); 

      gfx.DrawImage(XImage.FromFile(appPath + "/Sp.png"), 230, 380); 

      CoverPageHeader(); 

      Document doc = new Document(); 
      MigraDoc.DocumentObjectModel.Section sec = doc.AddSection(); 
      // Add a single paragraph with some text and format information. 
      MigraDoc.DocumentObjectModel.Paragraph para = sec.AddParagraph(); 
      para.Format.Alignment = ParagraphAlignment.Left; 
      para.Format.Font.Name = "Times New Roman"; 
      para.Format.Font.Size = 12; 
      para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black; 

      para.AddText("We are pleased to present the attached Document Please review the Agreement and, if acceptable, " + 
       "sign one copy and return it to us. We will sign the copy of the agreement and return one for " + 
       "your records."); 

      para.AddLineBreak(); 
      para.AddLineBreak(); 
      para.AddText(longlongtextString); 
      para.AddLineBreak(); 
      para.AddLineBreak();    
      para.AddText("Sincerely,"); 

MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); 
      docRenderer.PrepareDocument(); 

      // Render the paragraph. You can render tables or shapes the same way. 
      docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0.7), XUnit.FromCentimeter(9), "18cm", para); 

      gfx.DrawString("Kelly Turbin PhD., P.E.-SECB", font, XBrushes.Black, 20, 500); 
      gfx.DrawString("Principal", font, XBrushes.Black, 20, 520); 
      gfx.DrawString("Project No " + textBoxProjNumber.Text, fontReg, XBrushes.Black, 20,785); 

      gfx.DrawImage(XImage.FromFile(appPath + "/AccB.png"), 20, 700); 
      gfx.DrawImage(XImage.FromFile(appPath + "/ScreenMagic.png"), 100, 690); 
      gfx.DrawImage(XImage.FromFile(appPath + "/Footer.png"), 220, 750); 

     } 

Répondre

0

Ne pas utiliser renderObject, utilisez plutôt RenderDocument et les pages sont automatiquement créées au besoin.

Exemple de code ici: http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

+0

il n'y a pas d'option pour docRenderer.RenderDocument il existe deux méthodes disponibles uniquement renderObject et RenderPage –

+0

si je change les dernières lignes du code alors on ne voit rien en pdf PdfDocumentRenderer = new PdfDocumentRenderer renderer (true, PdfSharp.Pdf.PdfFontEmbedding .Toujours); renderer.Document = doc; renderer.RenderDocument(); –

-1

Il n'y a aucun moyen de créer automatiquement de nouvelles pages en fonction de la taille du texte, lorsque vous utilisez le Mix of PDFSharp and MigraDoc, comme il est dans la question. La seule solution consiste à utiliser uniquement MigraDoc avec sa méthode RenderDocument.

Questions connexes