Hello
How can I ensure that my pdf document with only one section, containing several multi-line text paragraphs, generates automatically page breaks where necessary, according to the page margins? Now the text simply flows to the very bottom of the page regardless of the page margins, instead of making a second page to continue the text which doesn’t fit on the first page.
Here’s my code - thanks in advance for your help!
protected void Page_Load(object sender, EventArgs e)
{
Pdf pdf = new Pdf();
pdf.OpenType = OpenType.Auto;
pdf.DestinationType = DestinationType.FitHeight;
pdf.Title = “Fallbeurteilung”;
pdf.Producer = “RVK PartnerPool”;
pdf.Subject = “Fallbeurteilung”;
pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = @“c:\inetpub\wwwroot\PartnerPoolWeb\Uploads”;
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
Section mainSection = pdf.Sections.Add();
MarginInfo margin = new MarginInfo();
margin.Left = 60;
margin.Top = 50;
margin.Right = 95;
margin.Bottom = 60;
mainSection.PageInfo.Margin = margin;
mainSection.FirstLineIndent = 0;
Aspose.Pdf.Image imgLogo = new Aspose.Pdf.Image(mainSection);
imgLogo.PositioningType = PositioningType.PageRelative;
imgLogo.Left = 475;
imgLogo.Top = 35;
imgLogo.ImageScale = 0.15F;
imgLogo.ImageInfo.File = “c:/inetpub/wwwroot/PartnerPoolWeb/images/rvk-logo-pdf.gif”;
imgLogo.ImageInfo.ImageFileType = ImageFileType.Gif;
mainSection.Paragraphs.Add(imgLogo);
Aspose.Pdf.Image imgQLabel = new Aspose.Pdf.Image(mainSection);
imgQLabel.PositioningType = PositioningType.PageRelative;
imgQLabel.Left = 490;
imgQLabel.Top = 620;
imgQLabel.ImageScale = 0.30F;
imgQLabel.ImageInfo.File = “c:/inetpub/wwwroot/PartnerPoolWeb/images/Q_Label.gif”;
imgQLabel.ImageInfo.ImageFileType = ImageFileType.Gif;
mainSection.Paragraphs.Add(imgQLabel);
mainSection.Paragraphs.Add(addText(“RVK Vertrauensarzt”,50,100,true));
mainSection.Paragraphs.Add(addText(“Stellungsnahme”, 250, 100, true));
mainSection.Paragraphs.Add(addText(FallDossier[FallDossierType.s_ModificationDate].ToString().Substring(0,10), 440, 100, false));
mainSection.Paragraphs.Add(addText(“VERTRAULICH”, 50, 130, true));
mainSection.Paragraphs.Add(addText(“Auftraggeber:”, 50, 160, false));
mainSection.Paragraphs.Add(addText(“Zuständig:”, 50, 175, false));
mainSection.Paragraphs.Add(addText(FirmaKunde[CompanyType.Kundenname], 150, 160, false));
mainSection.Paragraphs.Add(addText(PersonKunde[PersonType.Vorname].ToString() + " " + PersonKunde[PersonType.Name].ToString(), 150, 175, false));
mainSection.Paragraphs.Add(addText("________________________________________________________________________", 50, 180, false));
mainSection.Paragraphs.Add(addText(“Versicherter Nr.:”, 50, 200, false));
mainSection.Paragraphs.Add(addText(“Geburtsdatum:”, 350, 200, false));
mainSection.Paragraphs.Add(addText(“Name / Vorname:”, 50, 215, false));
mainSection.Paragraphs.Add(addText(Versicherter[VersicherterType.VersichertenNr].ToString(), 150, 200, false));
mainSection.Paragraphs.Add(addText(Versicherter[VersicherterType.Geburtsdatum].ToString().Substring(0,10), 435, 200, false));
mainSection.Paragraphs.Add(addText(Versicherter[VersicherterType.Vorname].ToString() + " " + Versicherter[VersicherterType.Name].ToString(), 150, 215, false));
mainSection.Paragraphs.Add(addText("________________________________________________________________________", 50, 220, false));
mainSection.Paragraphs.Add(addText(“Beurteilender Arzt:”, 50, 240, false));
mainSection.Paragraphs.Add(addText(“Referenz Nr.:”, 350, 240, false));
mainSection.Paragraphs.Add(addText(PersonVA[PersonType.Vorname].ToString() + " " + PersonVA[PersonType.Name].ToString(), 150, 240, false));
mainSection.Paragraphs.Add(addText(FallDossier[FallDossierType.ID].ToString(), 435, 240, false));
Aspose.Pdf.Text auftragText = addText(“Fragestellung des Kunden:”, 50, 270, true);
auftragText.ID = “auftragText”;
auftragText.Segments.Add(addSegment("\n\n" + Convert.ToString(FallDossier[FallDossierType.AT_Auftrag]).Replace("\n", " “)));
auftragText.Segments.Add(addSegment(”\n\n\nStellungsnahme:\n", true, false, false));
try
{
SortedList FallBeurteilung = FallBeurteilungen[FallBeurteilungen.Length - 1];
foreach (string line in FallBeurteilung[FallBeurteilungType.Stellungnahme].ToString().Split(new string[] { “\n” }, StringSplitOptions.None))
auftragText.Segments.Add(addSegment("\n" + line));
}
catch (Exception ex)
{
auftragText.Segments.Add(addSegment("\n\nEs wurde bisher keine Fallbeurteilung abgegeben."));
}
auftragText.Segments.Add(addSegment("\n\n\nFreundliche Grüsse", false, false, false));
auftragText.Segments.Add(addSegment("\nRVK", true, false, false));
auftragText.Segments.Add(addSegment("\n\n\n" + Convert.ToString(PersonVA[PersonType.Vorname]) + " " + Convert.ToString(PersonVA[PersonType.Name]), false, false, false));
auftragText.Segments.Add(addSegment("\n" + Convert.ToString(PersonVA[PersonType.Beruf]), false, false, false));
auftragText.Segments.Add(addSegment("\nPartnerPool-Arzt", false, false, false));
mainSection.Paragraphs.Add(auftragText);
pdf.Save(“Fallbeurteilung.pdf”, SaveType.OpenInAcrobat, Response);
Response.End();
}
protected Aspose.Pdf.Text addText(object text, float left, float top)
{
return addText(text, left, top, false, false, PositioningType.PageRelative, “”);
}
protected Aspose.Pdf.Text addText(object text, float left, float top, bool bold)
{
return addText(text, left, top, bold, false, PositioningType.PageRelative, “”);
}
protected Aspose.Pdf.Text addText(object text, float left, float top, bool bold, bool underline)
{
return addText(text, left, top, bold, underline, PositioningType.PageRelative, “”);
}
protected Aspose.Pdf.Text addText(object text, float left, float top, PositioningType positioningType, string referenceParagraphId)
{
return addText(text, left, top, false, false, positioningType, referenceParagraphId);
}
protected Aspose.Pdf.Text addText(object text, float left, float top, bool bold, bool underline, PositioningType positioningType, string referenceParagraphId)
{
Aspose.Pdf.Text newText = new Aspose.Pdf.Text("");
if (text != null)
newText.Segments[0].Content = text.ToString();
newText.Segments[0].TextInfo.FontName = “Gill Sans MT”;
newText.Segments[0].TextInfo.IsUnicode = true;
newText.Segments[0].TextInfo.FontSize = 11;
newText.Segments[0].TextInfo.IsTrueTypeFontBold = bold;
newText.Segments[0].TextInfo.IsUnderline = underline;
newText.PositioningType = positioningType;
if (positioningType.Equals(PositioningType.ParagraphRelative))
newText.ReferenceParagraphID = referenceParagraphId;
newText.Left = left;
newText.Top = top;
return newText;
}
protected Aspose.Pdf.Segment addSegment(string text)
{
return addSegment(text, false, false, false);
}
protected Aspose.Pdf.Segment addSegment(string text, bool bold, bool underline, bool italic)
{
Aspose.Pdf.Segment newSegment = new Aspose.Pdf.Segment();
newSegment.Content = text.Trim((’ '));
newSegment.TextInfo.FontName = “Gill Sans MT”;
newSegment.TextInfo.IsUnicode = true;
newSegment.TextInfo.FontSize = 11;
newSegment.TextInfo.IsTrueTypeFontBold = bold;
newSegment.TextInfo.IsUnderline = underline;
newSegment.TextInfo.IsTrueTypeFontItalic = italic;
return newSegment;
}
Hi,
Thank you for considering Aspose.
Please try adding this line of code:
pdf.PageSetup.Margin = margin;
Hope it helps.
Thanks.
Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html
Hello again
Thanks. Unfortunately this doesn’t change a thing. The result is the same as before. Any other ideas?
Björn
Hi,
In my test, I won’t use any relative positioning type and it works for me. I am also attaching the Pdf file for your reference. I use the following code.
Pdf pdf = new Pdf();
pdf.OpenType = OpenType.Auto;
pdf.DestinationType = DestinationType.FitHeight;
pdf.Title = “Fallbeurteilung”;
pdf.Producer = “RVK PartnerPool”;
pdf.Subject = “Fallbeurteilung”;
pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = Path.GetTempPath();
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Total.lic”);
Section section2 = pdf.Sections.Add();
MarginInfo margin = new MarginInfo();
margin.Left = 60;
margin.Top = 50;
margin.Right = 95;
margin.Bottom = 60;
Aspose.Pdf.TextInfo textInfo = new Aspose.Pdf.TextInfo();
// define fonts, etc.
textInfo.FontName = “Arial”;
textInfo.FontSize = 8;
textInfo.Alignment = Aspose.Pdf.AlignmentType.Justify;
pdf.TextInfo = textInfo;
pdf.PageSetup.Margin = margin;
section2.PageInfo.Margin = margin;
section2.FirstLineIndent = 0;
Aspose.Pdf.Text txt1 = new Aspose.Pdf.Text("\nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim. Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Ut nec neque. Maecenas aliquam ullamcorper nisl. Praesent porttitor turpis eleifend ante. Morbi sodales.", textInfo);
Aspose.Pdf.Text txt2 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt3 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt4 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt5 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt6 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt7 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt8 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt10 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt11 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt12 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt13 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt14 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt15 = (Aspose.Pdf.Text)txt1.CompleteClone();
Aspose.Pdf.Text txt16 = (Aspose.Pdf.Text)txt1.CompleteClone();
section2.Paragraphs.Add(txt1);
section2.Paragraphs.Add(txt1);
section2.Paragraphs.Add(txt2);
section2.Paragraphs.Add(txt3);
section2.Paragraphs.Add(txt4);
section2.Paragraphs.Add(txt5);
section2.Paragraphs.Add(txt6);
section2.Paragraphs.Add(txt7);
section2.Paragraphs.Add(txt8);
section2.Paragraphs.Add(txt10);
section2.Paragraphs.Add(txt11);
section2.Paragraphs.Add(txt12);
section2.Paragraphs.Add(txt13);
section2.Paragraphs.Add(txt14);
section2.Paragraphs.Add(txt15);
section2.Paragraphs.Add(txt16);
pdf.Save(“D:/AsposeTest/Fallbeurteilung.pdf”);
It is difficult to generate an error from your code posted on the forum. If the problem remains, then send your output Pdf, along with the images you have used in your code .
Thanks.
Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html
Hi again
Ok, auto positioning works fine for me!
Thanks for your help!
Björn Metzinger