PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Dec 08, 2019 12:05 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Nov 28, 2019 12:11 pm 
Offline

Joined: Tue Aug 06, 2019 10:45 am
Posts: 21
I asked a Similar question a while back, but I have a pdf that doesn't show correctly on the browser window.

The problem itself is that I have a pdf that has acrofields, but I copy that pdf, and fill the acroform acordingly to the data I have, the problem is when I try to show it to the user (through a web browser, since I'm this in ASP.NET).
the text doesn't come formatted correctly, but, if the user downloads the pdf and opens it on the computer, it is correctly formatted.

I don't know why this happens, the pdf I had filled the form using itextsharp shows correctly.

Examples:

PdfSharp Example on browser (chrome and firefox were tested with the same results):
Attachment:
PdfSharpAcroOnChrome.png
PdfSharpAcroOnChrome.png [ 175.85 KiB | Viewed 45 times ]


iTextSharp Example on browser (chrome and firefox were tested with the same results):
Attachment:
iTextSharpAcroOnChrome.png
iTextSharpAcroOnChrome.png [ 170.39 KiB | Viewed 45 times ]



the acroform was filled using pdfsharp and heres a snippet of the code I'm using to make it work, just in case it helps with something:


Code Sample used to get the template copy and set the '/NeedAppearances' attribute
Code:
    using (var fs = new FileStream(ReportPath + newfile, FileMode.Create))
    {
        // Get the template and copy it to another document
        PdfSharp.Pdf.PdfDocument myTemplate = PdfSharp.Pdf.IO.PdfReader.Open(pdfTemplateMod22, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
        PdfSharp.Pdf.PdfDocument newDoc = (PdfSharp.Pdf.PdfDocument)myTemplate.Clone();

        var acroFields = newDoc.AcroForm.Fields;

        //Ensure the new values are displayed
        if (newDoc.AcroForm.Elements.ContainsKey("/NeedAppearances"))
            newDoc.AcroForm.Elements["/NeedAppearances"] = new PdfSharp.Pdf.PdfBoolean(true);
        else
            newDoc.AcroForm.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));

        FuncoesAuxiliaresPdf.SetVarsModelo22(acroFields);

        if (newDoc.AcroForm != null)
            newDoc.Flatten();   // NOTE: doc.AcroForm is null after flattening ! and the pdf is not editable

        newDoc.Save(fs);
        url = "../relatorios/temporarios/" + newfile;
    }


Code Sample on how I am putting value on the acro fields
Code:
    #region Página 1 Modelo 22
    DateTime dataTrb = GlobalFunctions.GetDate(period);

    #region Quadro 01
    // Preciso obter a DAT_INI_TRB
    DateTime dataIniTrb = dataTrb.AddYears(-1).AddDays(1);
    ((PdfTextField)pdfFormFields["DAT_INI_TRB_Ano"]).Value = new PdfString(dataIniTrb.ToString("yyyy"));
    (PdfTextField)pdfFormFields["DAT_INI_TRB_Mes"]).Value  = new PdfString(dataIniTrb.ToString("MM"));
    ((PdfTextField)pdfFormFields["DAT_INI_TRB_Dia"]).Value  = new PdfString(dataIniTrb.ToString("dd"));

    DateTime dataFimTrb = dataTrb;
    ((PdfTextField)pdfFormFields["DAT_FIM_TRB_Ano"]).Value = new PdfString(dataFimTrb.ToString("yyyy"));
    ((PdfTextField)pdfFormFields["DAT_FIM_TRB_Mes"]).Value = new PdfString(dataFimTrb.ToString("MM"));
    ((PdfTextField)pdfFormFields["DAT_FIM_TRB_Dia"]).Value  = new PdfString(dataFimTrb.ToString("dd"));

    ((PdfTextField)pdfFormFields["Ano"]).Value = new PdfString(Space(dataFimTrb.ToString("yyyy"), 3));
    #endregion Quadro 01



Some help regarding this matter would be appretiated, since the last time I asked something regarding this subject, It wasn't ansered.

Thank you in advance


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 30, 2019 12:46 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 508
Location: CCAA
IRlyDunno wrote:
Some help regarding this matter would be appretiated, since the last time I asked something regarding this subject, It wasn't ansered.
It seems the majority here has no experience with AcroForms and cannot help.

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


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 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