PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Missing text on certain uncorrupted pages https://forum.pdfsharp.net/viewtopic.php?f=2&t=4268 |
Page 1 of 1 |
Author: | nacca [ Fri Jun 25, 2021 2:20 pm ] |
Post subject: | Missing text on certain uncorrupted pages |
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 |
Author: | TH-Soft [ Mon Jun 28, 2021 3:41 pm ] |
Post subject: | Re: Missing text on certain uncorrupted pages |
nacca wrote: 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 Open the file in Adobe Reader, then select File / Save as to create a copy of that file.If adding text works with this copy, then assume the file is corrupted. If it still does not work then the file can still be corrupted. |
Author: | nacca [ Tue Jun 29, 2021 12:20 pm ] |
Post subject: | Re: Missing text on certain uncorrupted pages |
i've opened it in adobe and saved and after that pdfsharp can write on it, the strange thing is that if i draw lines on the uncorrupted file they appears without problems also, it doesn't throw any exception, there is a way that can tell me if the text has been added or if the file were currupted? Thanks a lot for your time, nacca |
Author: | wiliek [ Wed Jun 30, 2021 5:54 pm ] |
Post subject: | Re: Missing text on certain uncorrupted pages |
What if you draw an image on the page? What if you highlight the page? Do you see outlines of the text? Can you upload a sample pdf? I think the document is not flattened and text gets written to a base layer and the rest of the document 'overwrites' it. But images and shapes are written differently so they show up on top layer so to speak. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |