Hi
I put my hope to anyone experienced in the PdfSharp class library or perhaps can find an answer anyway. Please provide some code example, I have tried many variations and have already seen most of the existing errors.
I have some problems adding new pages. I want to add new pages only if needed and measured by
the XParagraph (text) length. If the length doesnt fit on one page, a new page must be added.
Also the header and footer need to be added to every new page.
It is probably easy to solve if I know how to do that, but I dont.
I only use the PdfSharp library, not MigraDoc.
Here is some sample code I have been working with....
protected void btnCreate_Click(object sender, EventArgs e)
{
PdfPage pdfPage = new PdfPage();
pdfPage.Orientation = PdfSharp.PageOrientation.Portrait;
pdfPage.Size = PdfSharp.PageSize.A4;
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.Pages.Add(pdfPage);
pdfDocument.PageLayout = PdfPageLayout.SinglePage;
pdfDocument.PageMode = PdfPageMode.UseOutlines;
// Strängvärden från textboxar
header = TextBox_rubrik.Text.ToString();
text = TextBox_text.Text;
footer = TextBox_fot.Text;
fileName = TextBox_filename.Text.ToString();
linkText = TextBox_linktext.Text;
XFont fontHeader = new XFont("Arial", 16, XFontStyle.Bold);
XFont fontText = new XFont("Arial", 11, XFontStyle.Regular);
XFont fontFot = new XFont("Arial", 10, XFontStyle.Regular);
XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
XTextFormatter tf = new XTextFormatter(gfx);
// Position av ruta XRect: indrag vänstermarginal, indrag toppmarginal, bredd, höjd
XRect rect = new XRect();
int pageCount = pdfDocument.PageCount;
for (int idx = 0; idx < pageCount; idx++)
{
PdfPage page = pdfDocument.AddPage();
}
rect = new XRect(40, 40, 505, 60);
tf.Alignment = XParagraphAlignment.Center;
tf.DrawString(header, fontHeader, XBrushes.Black, rect, XStringFormats.TopLeft);
tf.DrawString(header, fontHeader, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(40, 80, 505, 682);
tf.Alignment = XParagraphAlignment.Left;
tf.DrawString(text, fontText, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(40, 802, 505, 40);
tf.Alignment = XParagraphAlignment.Center;
tf.DrawString(footer, fontFot, XBrushes.Black, rect, XStringFormats.TopLeft);
string fileFolder = Server.MapPath("~/document_folder/");
fileName = fileName + ".pdf";
pdfDocument.Save(fileFolder + fileName);
// print link on ASP.NET page
fileLink.InnerHtml += "<a href='document_folder/" + fileName + "'>" + linkText + "</a><br />";
pdfDocument.Close();
}
thanks in advance