Hi at all, i love your work
I'm using PDF Sharp 1.50.5147 (NuGet) on a c# application
My app take a PDF and split it in single pages pdf, applies a text and save them
It works like a charm but on certain files it will not add the text, the strange thing is that PDF Sharp can open those files so i assume that aren't corrupted
I've tried the following:
- draw a line in the pdf after the text => text no, line yes
- change size font => text no
- change position => text no
- change color => text no
- save the file with chrome (print as pdf) => text yes
furthermore, there are no errors/exceptions when the text isn't in the document
what can i try? i can send the pdf but it contains private info so i will not share it here
The code i used is the following but i don't think it's worng (it works on the great majority of files) :
Code:
static void splitPDF(string fileName)
{
PdfDocument PDFDoc = PdfReader.Open(@"C:\Users\nacca\Desktop\a\" + fileName, PdfDocumentOpenMode.Import);
for (int Pg = 0; Pg < PDFDoc.Pages.Count; Pg++)
{
string progr = nextProgressive();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(1252);
PdfSharp.Pdf.PdfDocument PDFNewDoc = new PdfSharp.Pdf.PdfDocument();
PdfPage page = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Arial", 20);
gfx.DrawString(progr, font, XBrushes.Red,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
PDFNewDoc.Save(@"C:\Users\nacca\Desktop\a\b\" + progr + "_" + fileName + ".pdf");
PDFNewDoc.Dispose();
}
PDFDoc.Dispose();
}
Thanks a lot,
nacca