You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello I try to put text in Landscape page in the bottom, but not work. I attach example and I mark with yellow without text where is the correct position to put the text.
This is my code :
public static bool PdfSharpStampPdf(string[] files, string textStamp, out string message)
{
bool result = false;
message = string.Empty;
try
{
foreach (var file in files)
{
// Open the document
using (PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import))
{
PdfDocument PDFNewDoc = new PdfDocument();
// Iterate pages
foreach (PdfPage page in inputDocument.Pages)
{
PdfPage pp = PDFNewDoc.AddPage(page);
string stampText = Path.GetFileNameWithoutExtension(file) + " " + textStamp;
XGraphics gfx = XGraphics.FromPdfPage(pp);
XRect rect = new XRect();
if (page.Orientation == PdfSharp.PageOrientation.Landscape)
{
rect.X = 0;
rect.Y = 0;
rect.Width = pp.Width;
rect.Height = pp.Height;
}
else
{
rect.X = 0;
rect.Y = 0;
rect.Width = pp.Width;
rect.Height = pp.Height;
}
XFont font = new XFont("Arial", 8, XFontStyle.Regular);
if (page.Orientation == PdfSharp.PageOrientation.Landscape)
{
gfx.DrawString(stampText, font, XBrushes.Black, rect, XStringFormats.BottomCenter);
}
else {
gfx.DrawString(stampText, font, XBrushes.Black, rect, XStringFormats.BottomCenter);
}
}
PDFNewDoc.Save(file);
}
}
result = true;
}
catch (Exception ex)
{
result = false;
message = String.Format("Error PdfSharp occured for stamp Documents Exception: {0}", ex.Message);
}
return result;
}
The text was updated successfully, but these errors were encountered:
@JorgelGtzGtz
I know this is old. But why even check for the orientation change on the page if you're just going to execute the exact same code, with the exact same values in the variables?
@ThomasHoevel You may want to mark this issue as closed.
Hello I try to put text in Landscape page in the bottom, but not work. I attach example and I mark with yellow without text where is the correct position to put the text.
This is my code :
public static bool PdfSharpStampPdf(string[] files, string textStamp, out string message)
{
bool result = false;
message = string.Empty;
try
{
foreach (var file in files)
{
// Open the document
using (PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import))
{
PdfDocument PDFNewDoc = new PdfDocument();
// Iterate pages
foreach (PdfPage page in inputDocument.Pages)
{
PdfPage pp = PDFNewDoc.AddPage(page);
string stampText = Path.GetFileNameWithoutExtension(file) + " " + textStamp;
XGraphics gfx = XGraphics.FromPdfPage(pp);
XRect rect = new XRect();
if (page.Orientation == PdfSharp.PageOrientation.Landscape)
{
rect.X = 0;
rect.Y = 0;
rect.Width = pp.Width;
rect.Height = pp.Height;
}
else
{
rect.X = 0;
rect.Y = 0;
rect.Width = pp.Width;
rect.Height = pp.Height;
}
The text was updated successfully, but these errors were encountered: