PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Concatenate after Creating Form Docs http://forum.pdfsharp.com/viewtopic.php?f=2&t=4308 |
Page 1 of 1 |
Author: | ChrisThornton [ Tue Dec 14, 2021 7:27 pm ] |
Post subject: | Concatenate after Creating Form Docs |
Nuget package 1.50.5147 I have recently used PDF sharp to create tickets by gathering information from a data reader and using an Acroform template to create a document for each line of date required as an Acrofo. This has worked fine and I finish with a set of flatenned files eg: Doc1034-1.pdf, Doc1034-2.pdf and Doc1034-3.pdf. All good! I then try to concatenate the files to end up a 3 page document eg: DOC1034-0.pdf That is where I have problems. My individual files all open properly in Acrobat Reader and have all the correct information including a Barcode. However my concatenated file does not show any date in the field when files are opened in Acrobat. But ... when selected in File Explorer, the preview shows the data fields (although the barcode is shown in standard font) I have tried several processes to create this file: a) create all individual files and then try to concatenate b) create each file and insert into output document before creating next file and c) Create individual files and then draw them to the output document.In all processes I have used the flatten method to 'fix' the form All methods have the same consistent result so it is clearly something I dont understand about the concatenate process or layout. Can someone give me some suggestion where I am going wrong? Public Sub CreateTix(intPTTransID As Integer) Dim intAATransId, intAAItem As Integer Dim strAATixNo, strAAWhCh, strAACust, strAAParty, strAALeadTix, strAADocType, strAABarcode, strOPname, strOPfinalName As String Dim strIPtixpath As String = strNamePath & "\PDTIX" Dim strOPtixPath As String = strNamePath & "\PDTIX\Created" ' GATHER INFO Dim strCreateDocsSelectString As String = "SELECT * FROM ProcDocsSH WHERE TransID = " & IntTransID Dim conCreateDocs As New OleDbConnection conCreateDocs.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & strDataFolder & "\" & strData1File conCreateDocs.Open() Dim cmdCreateDocsCommand As OleDbCommand = New OleDbCommand(strCreateDocsSelectString, conCreateDocs) cmdCreateDocsCommand.CommandType = CommandType.Text Dim rdrCreateDocsReader As OleDbDataReader = cmdCreateDocsCommand.ExecuteReader Dim rowcounter As Integer = 0 Dim totRows As Integer = 0 Try If rdrCreateDocsReader.HasRows Then While rdrCreateDocsReader.Read() strAADocType = rdrCreateDocsReader("ItemDesc") If strAADocType <> "MA" And strAADocType <> "MU" And strAADocType <> "EA" And strAADocType <> "EU" Then rowcounter += 1 intAAItem = rowcounter intAATransId = IntTransID strAACust = rdrCreateDocsReader("PFCust") strAATixNo = rdrCreateDocsReader("PFTixNo") strAAWhCh = rdrCreateDocsReader("PFWhCh") strAAParty = rdrCreateDocsReader("PFParty") strAALeadTix = rdrCreateDocsReader("PFLeadTixNo") strAABarcode = "*" & strAATixNo & "*" strOPname = "Doc" & intAATransId.ToString & "-" & intAAItem.ToString & ".pdf" ' CREATE SINGLE PDF File.Copy(strIPtixpath & "\" & strAADocType & "PFTemplate.pdf", strOPtixPath & "\" & strOPname, True) Dim document As PdfDocument = Pdf.IO.PdfReader.Open(strOPtixpath & "\" & strOPname, IO.PdfDocumentOpenMode.Modify) If document.AcroForm.Elements.ContainsKey("/NeedAppearances") = False Then document.AcroForm.Elements.Add("/NeedAppearances", New PdfSharp.Pdf.PdfBoolean(True)) Else document.AcroForm.Elements("/NeedAppearances") = New PdfSharp.Pdf.PdfBoolean(True) End If Dim currentfield As AcroForms.PdfTextField 'SetAttr value of fields currentfield = document.AcroForm.Fields("PFStubCust") Dim fieldvalue As PdfString = New PdfString(strAACust) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFCust") fieldvalue = New PdfString(strAACust) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFStubTixNo") fieldvalue = New PdfString(strAATixNo) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFLTixNo") fieldvalue = New PdfString(strAATixNo) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFRTixNo") fieldvalue = New PdfString(strAATixNo) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFStubParty") fieldvalue = New PdfString(strAAParty) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFParty") fieldvalue = New PdfString(strAAParty) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFStubTrans") fieldvalue = New PdfString(intAATransId.ToString) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFTrans") fieldvalue = New PdfString(intAATransId.ToString) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFWhCh") fieldvalue = New PdfString(strAAWhCh) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFStubWhCh") fieldvalue = New PdfString(strAAWhCh) currentfield.Value = fieldvalue If strAADocType = "MC" Or strAADocType = "EC" Then currentfield = document.AcroForm.Fields("PFStubLeadTixNo") fieldvalue = New PdfString(strAALeadTix) currentfield.Value = fieldvalue currentfield = document.AcroForm.Fields("PFLeadTixNo") fieldvalue = New PdfString(strAALeadTix) currentfield.Value = fieldvalue Else currentfield = document.AcroForm.Fields("PFBarcode") fieldvalue = New PdfString(strAABarcode) currentfield.Value = fieldvalue End If document.Flatten() document.Save(strOPtixPath & "\" & strOPname) document.Close() End If End While ' NOW JOIN ALL PDFs INTO ONE DOCUMENT in separate routine Dim joineddoc As Pdf.PdfDocument = New PdfDocument Dim intcdi As Integer totRows = rowcounter strOPfinalName = strOPtixPath & "\DOC" & intAATransId.ToString & "-0.pdf" For intcdi = 1 To totRows Dim IPdocument As PdfDocument = Pdf.IO.PdfReader.Open(strOPtixPath & "\Doc" & intAATransId.ToString & "-" & intcdi.ToString & ".pdf", IO.PdfDocumentOpenMode.Import) Dim page As PdfPage = IPdocument.Pages(0) If intcdi = 1 Then joineddoc.Version = IPdocument.Version joineddoc.PageLayout = IPdocument.PageLayout End If joineddoc.InsertPage(intcdi - 1, page) Next joineddoc.Save(strOPfinalName) End If Catch ex As Exception MsgBox("Create documents routine" & ex.Message & ex.StackTrace) End Try Process.Start(strOPfinalName) End Sub |
Author: | ChrisThornton [ Wed Dec 22, 2021 9:03 am ] |
Post subject: | Re: Concatenate after Creating Form Docs |
OK - Time for an update:- I think I know some of the factors that are preventing my process from concatenating these documents: I have read that a Document may not have fields with the same name - which is logical. In a single document , that would be no problem but as soon as I add a page that had the same named fields then there is a conflict. I had hoped to avoid this problem but flattening each page before saving but I have also read in this forum that the Flatten function makes the fields Read Only but does not absorb the field into the page. The field remains as a field. I have not investigated any further why File Explore preview can see fields but Acrobat can not. I shall look for another way to complete my documents. Thanks to those people who have taken an interest. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |