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 [ 175.85 KiB | Viewed 11256 times ]
iTextSharp Example on browser (chrome and firefox were tested with the same results):
Attachment:
iTextSharpAcroOnChrome.png [ 170.39 KiB | Viewed 11256 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