PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 12:42 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Jun 25, 2021 2:20 pm 
Offline

Joined: Fri Jun 25, 2021 11:09 am
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 28, 2021 3:41 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 29, 2021 12:20 pm 
Offline

Joined: Fri Jun 25, 2021 11:09 am
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 30, 2021 5:54 pm 
Offline

Joined: Wed Jun 10, 2020 7:15 pm
Posts: 7
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 136 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group