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

pdfsharpcore file size grows thrice after edit and save for header and footer #422

Open
Roopeshpm opened this issue Feb 6, 2024 · 0 comments

Comments

@Roopeshpm
Copy link

I was working on a project where user will upload a PDF document which will be around 35mb and it will be stored in ECS bucket.
While user tries to download the same file from back end we will open the document programmatically and update each page header and footer with some predefined text For ex:User name and document valid date.
After that we will save the file and send back to user.
But once we update the file and save, size grows near to three times. For a 35mb file it will become around 99mb.
Can you please help me to solve this. for a simple header and footer change if file grows to three times then my client will raise concerns.

public MemoryStream UpdatePDFFromStream(MemoryStream ms)
{
var exportMarkingText = "Company Proprietary. Copyright © The Company";
XFont font = new XFont("Calibri", 14, XFontStyle.Bold);
PdfDocument PDFDoc = PdfReader.Open(ms, PdfDocumentOpenMode.Modify);
for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
{
PdfPage page = PDFDoc.Pages[Pg];
XGraphics gfx = XGraphics.FromPdfPage(page);
//check pdf's rotation angle
var fileRotationAngle = PDFDoc.Pages[0].Rotate;
XPoint point = new XPoint(0, 0);

if (fileRotationAngle == 90)
{
point = new XPoint(60 - PDFDoc.Pages[0].Width, 50);
gfx.RotateTransform(-fileRotationAngle);
}
else if ((fileRotationAngle == 0))
{
//point = new XPoint(60, 12);
point = new XPoint(80, 12);

}
else
{

}
XPoint pointFooter = new XPoint(80, 780);
gfx.DrawString(exportMarkingText, font, XBrushes.Black, point);
//sample test. will change as per user requirements
gfx.DrawString("Not Valid after Sept-30-2024", font, XBrushes.Black, pointFooter);

}

PDFDoc.Save(ms);
return ms;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant