Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put Text in bottom Landscape page wrong #98

Open
JorgelGtzGtz opened this issue Aug 7, 2019 · 1 comment
Open

Put Text in bottom Landscape page wrong #98

JorgelGtzGtz opened this issue Aug 7, 2019 · 1 comment
Labels
not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) question

Comments

@JorgelGtzGtz
Copy link

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.

POSITION

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;
    }
@ThomasHoevel ThomasHoevel added not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) question labels Aug 14, 2019
@Spiker985
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not repro As a matter of principle we only investigate non-trivial issues that are replicable (VS solution) question
Projects
None yet
Development

No branches or pull requests

3 participants