I need to create a Pdf document with header,footers and text, should
be spanned to multiple pages when text does not fit in page and also footer need to be displayed
on every page.
1. when text size increases then text is not wrapping to nextline, instead it is displaying
half of the text.
What should I do, text should be fit in same line or to naxt line, and do not change the font size?
2.I tried to create multiple pages when text exceeds first page,
how can I create next page and draw text on that page?
I have gone through the syncusion documentation but, I couldn't solve above two problems.
Hi Adnan,
We have created a sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Pdf_Sample_TextPaginationWithHF977948996 to achieve your requirements of creating a Pdf document with header, footers and text, should be spanned to multiple pages when text does not fit in page and also footer need to be displayed on every page and overcome the mentioned issues.
Kindly try the attached sample and let us know the result.
Regards,
Surya V
Thanks for quick response. It worked fine but what if it is not a single element but multiple text elements
PdfLayoutFormat layoutFormat = new PdfLayoutFormat();
layoutFormat.Layout = PdfLayoutType.Paginate;
layoutFormat.Break = PdfLayoutBreakType.FitPage;
PdfTextElement textElement = new PdfTextElement("", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
@for (int i = 1; i < enumsClass.Priorities.Count+1; i++)
{
textElement = new PdfTextElement($"Priority: {i} ({@businessObjects.Where(a => a.Priority == i).Count()} objectDesciption)", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
textElement.Draw(pdfPage, new RectangleF(0, i*250, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
Hi Adnan,
Currently, We are analyzing to achieve your requirement with multiple text elements and we will update the further details on February 16th 2022.
Regards,
Surya V
|
PdfTextElement textElement = new PdfTextElement("", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
PdfLayoutResult result = null;
float y = 10;
for (int i = 0; i < 3; i++)
{
if(i == 0)
{
textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(pdfPage, new RectangleF(0, y, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
else
{
textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(result.Page, new RectangleF(0, y, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
y = result.Bounds.Height + 20;
} |
Thanks for your response, it works perfectly in the above sample. But if the text is small string not a long paragraph then if we iterate over it does not create multiple pages
PdfTextElement textElement = new PdfTextElement("", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
PdfLayoutResult result = null;
float y = 10;
//i want to create 10-15 pages
for (int i = 0; i < 600; i++)
{
if(i == 0)
{
textElement = new PdfTextElement("This is one liner text/Paragraph", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(pdfPage, new RectangleF(0, y, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
else
{
textElement = new PdfTextElement("This is one liner text/Paragraph", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(result.Page, new RectangleF(0, y+20, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
y = result.Bounds.Height + 40;
}
If i do
y = y + 40; it does creates 2-3 pages but the text elements is not Visible on that pages except a single element
Kindly let me know if i am missing something
|
PdfTextElement textElement = new PdfTextElement("", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
PdfLayoutResult result = null;
float y = 10;
for (int i = 0; i < 600; i++)
{
if (i == 0)
{
textElement = new PdfTextElement("This is one liner text/Paragraph", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(pdfPage, new RectangleF(0, y, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
else
{
textElement = new PdfTextElement("This is one liner text/Paragraph", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(result.Page, new RectangleF(0, y, pdfPage.GetClientSize().Width, pdfPage.GetClientSize().Height - pdfDocument.Template.Bottom.Height), layoutFormat);
}
y = result.Bounds.Y+ result.Bounds.Height + 40;
} |
Thanks, it does not work perfectly for my case(Multiple Pages) but i have found the way with the help of sample solution you provided
PdfTextElement element = new PdfTextElement("", new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
PdfTextLayoutResult result = element.Draw(pdfPage, bounds, layoutFormat);
//PdfLayoutResult result = null;
for (int i = 0; i < 600; i++)
{
bounds = new RectangleF(new PointF(0, result.LastLineBounds.Y + 20), new SizeF(pdfPage.Graphics.ClientSize.Width - 20, pdfPage.Graphics.ClientSize.Height - 10));
element.Text = "Some First text";
result = element.Draw(pdfPage, bounds.Location, bounds.Width, layoutFormat);
if ((result.Remainder != null) && (result.Remainder.Length > 0))
{
bounds = new RectangleF(new PointF(0, 10), new SizeF(pdfPage.Graphics.ClientSize.Width - 20, pdfPage.Graphics.ClientSize.Height - 10));
element.Text = result.Remainder;
result = element.Draw(pdfPage, bounds.Location, bounds.Width, layoutFormat);
}
else
{
pdfPage = result.Page;
bounds = new RectangleF(new PointF(0, result.LastLineBounds.Y + 20), new SizeF(pdfPage.Graphics.ClientSize.Width - 20, pdfPage.Graphics.ClientSize.Height - 10));
}
}
This way we can create as many pages as needed Thanks
Thanks, i have one more question regarding this
The way we are writing text on the page
element.Text = "Some First text";
result = element.Draw(pdfPage, bounds.Location, bounds.Width, layoutFormat);
and adding next text after getting the bounds of previous text element. as such
if ((result.Remainder != null) && (result.Remainder.Length > 0))
{
bounds = new RectangleF(new PointF(0, 10), new SizeF(pdfPage.Graphics.ClientSize.Width - 20, pdfPage.Graphics.ClientSize.Height - 10));
element.Text = result.Remainder;
result = element.Draw(pdfPage, bounds.Location, bounds.Width, layoutFormat);
}
else
{
pdfPage = result.Page;
bounds = new RectangleF(new PointF(0, result.LastLineBounds.Y + 20), new SizeF(pdfPage.Graphics.ClientSize.Width - 20, pdfPage.Graphics.ClientSize.Height - 10));
}
Can we do the same if we want to draw multiple images, means can we draw image and get its bounds to draw next image
Thanks
Hi Adnan,
We do not have support for adding multiple
images by using PdfLayoutResult approach. As a workaround, we can achieve this
requirement by manually calculating the previous image bounds and draw the image
based on the Y position. We have attached the sample and output document for
your reference, please try the below sample on your end and let us know if it
is suites your requirement or not.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Pdf_Sample_MultipleImage228932820
Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/Sample_MultiplImage-533658491
Kindly please try the above solution on your end and let
us know if it suits your requirement.
Regards,
Gowthamraj K