Error reading Xref entry while opening PDF as embedded document

Error reading Xref entry while opening PDF as embedded document

Forum member · Mar 28, 2008
Getting error "Error reading Xref entry" while opening merged PDF document as embedded document. Please note that I am using PdfDocument object and Linearize property of MergedDocument.

Re: Error reading Xref entry while opening PDF as embedded document

Support · Mar 28, 2008
Hello, Can you please send over the PDF document you are merging and the code you are using to our [^a|mailto:support@cete.com|Support Team^] so that they can look into it. Thanks, ceTe Software Support Team.

Re: Error reading Xref entry while opening PDF as embedded document

Forum member · Mar 31, 2008
I am sorry but due to the confidentiality of the document, I cannot send the pdf file: I observed the following while fixing the issue: - When I use MergedDocument's PdfFormat = PdfFormat.Linearized, I get that error. It works fine if I remove that line, as long as the file size is below 500MB. Here's the code I used: protected void GenerateCertificate(Dictionary<string, string> poQSKeyValues) { try { //certificate template path (Virtual Path) string sTemplateFormPath = poQSKeyValues["tp"]; string sTempFolderPath = ""; //Check if defined in Web.config otherwise hardcode if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["tempfolderpath"])) { sTempFolderPath = "Data\\temp\\"; } else { sTempFolderPath = ConfigurationManager.AppSettings["tempfolderpath"]; } //certificate output file path (Virtual Path, to specify file src in embed tag) m_sOutputFormVirtualPath = sTempFolderPath + poQSKeyValues["cid"] + "_Certificate.pdf"; //certificate output file path (Actual Path) string sOutputFormPath = Server.MapPath(m_sOutputFormVirtualPath); //User PdfDocument to enhance performance. Recommended on DynamicPDF web site. PdfDocument oPDFDoc = new PdfDocument(Server.MapPath(sTemplateFormPath)); //Instantiate MergeDocument class with template document path and set its properties MergeDocument oDocument = new MergeDocument(oPDFDoc); //Set form properties oDocument.Form.IsReadOnly = true; oDocument.PdfFormat = PdfFormat.Linearized; oDocument.Sections.Begin(); //Loop through fields and replace any of the values from the values stored in dictionary foreach (FormField oField in oDocument.Form.Fields) { //Parse individual field value to determine if value needs replacing System.Text.RegularExpressions.Regex oRegex = new System.Text.RegularExpressions.Regex(@"\{(\w)*\}"); System.Text.RegularExpressions.MatchCollection oMatches = oRegex.Matches(oField.Value); foreach (System.Text.RegularExpressions.Match oMatch in oMatches) { if (poQSKeyValues.ContainsKey(oMatch.Value.Substring(1, oMatch.Value.Length - 2))) { oField.Value = oField.Value.Replace(oMatch.Value, poQSKeyValues[oMatch.Value.Substring(1, oMatch.Value.Length - 2)]); } } } oDocument.Draw(sOutputFormPath); oDocument = null; oPDFDoc = null; } catch (Exception err) { throw err; } } Ultimately, I was able to fix the issue by reducing the PDF file size(from 1.5mb to 276kb), and not using Linearized property.