How to avoid non-printing items from printing after flattening PDF - itext7

I recently upgraded from iText5 to iText7.
I'm using iText7 to flatten documents to remove interactivity. I expected that the printed document would look the same before and after flattening. Unfortunately that's not the case.
The source pdf has non-printing Button objects that are set to "Visible but doesn't print". After flattening, the undesired fields do print.
Is there a setting I'm missing, or do I need to remove non-printing buttons, fields etc before flattening?
Public Shared Function FlattenPdf(SourcePath As String, DestPath As String) As String
Using reader As New Pdf.PdfReader(SourcePath)
Using writer As New Pdf.PdfWriter(DestPath)
'Opens PDF document in the stamping mode
Dim pdfDoc As New Pdf.PdfDocument(reader, writer)
Dim form As Forms.PdfAcroForm = Forms.PdfAcroForm.GetAcroForm(pdfDoc, createIfNotExist:=True)
'flatten the form to remove editing options
form.FlattenFields()
pdfDoc.Close()
End Using
End Using
Return DestPath
End Function

Related

How do I add a save feature to a datagridview?

Hi i am fairly new to visual studio and I am having some trouble adding a save feature to my program. Basically what my program does is set event reminder for the user (it's like a daily planner but with no notifications). I have got the "add event', "delete", and "update buttons to work on the program and now all I have left is the "save" and "load" key. What I am trying to do is find a way to save the DataGridView so it can be opened back up in the program at a later date using the "load" key. If it would be easier to just remove the "load" and save the info right into the event reminder application, I could go that route but I don't have the first idea how to do that. This is what I have right now for the code in the main form:
Public Class MainForm1
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If DataGridView1.Columns(e.ColumnIndex).Name = "Delete" AndAlso Me.DataGridView1.Rows(e.RowIndex).IsNewRow = False Then
Me.DataGridView1.EndEdit()
Me.DataGridView1.Rows.RemoveAt(e.RowIndex)
End If
If DataGridView1.Columns(e.ColumnIndex).Name = "Column4" AndAlso Me.DataGridView1.Rows(e.RowIndex).IsNewRow = False Then
Dim Update As UpdateWindow
Update = UpdateWindow
Update.Show()
End If
End Sub
Private Sub dltBtn_Click(sender As Object, e As EventArgs)
Dim dltBtn As dltWindow
dltBtn = dltWindow
dltBtn.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Button1 As addBtn
Button1 = addBtn
Button1.Show()
End Sub
Private Sub UptBtn_Click(sender As Object, e As EventArgs)
Dim UptBtn As UpdateWindow
UptBtn = UpdateWindow
UptBtn.Show()
End Sub
Dim thisFilename As String = Application.StartupPath & "\Event reminder.dat"
Private Sub saveBtn_Click(sender As Object, e As EventArgs) Handles saveBtn.Click
Me.Validate()
Me.SaveGridData(DataGridView1, thisFilename)
End Sub
Private Sub BtnLoad_Click(sender As Object, e As EventArgs) Handles BtnLoad.Click
Me.LoadGridData(DataGridView1, thisFilename)
End Sub
Private Sub SaveGridData(ByRef ThisGrid As DataGridView, ByVal thisFilename As String)
ThisGrid.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
ThisGrid.SelectAll()
IO.File.WriteAllText(thisFilename, ThisGrid.GetClipboardContent().GetText.TrimEnd)
ThisGrid.ClearSelection()
End Sub
Private Sub LoadGridData(ByRef ThisGrid As DataGridView, ByVal Filename As String)
ThisGrid.Rows.Clear()
For Each THisLine In My.Computer.FileSystem.ReadAllText(Filename).Split(Environment.NewLine)
ThisGrid.Rows.Add(Split(THisLine, " "))
Next
End Sub
End Class
I have gone on the other forums and asked about how to do this and they all said the bind the datagridview to a data table. If that is the route I have to go, how do I go about it? If anyone has some examples or code I could try out I would be much appreciative.
The problem I can see in the posted code is between the LoadGridData and the SaveGridData methods. When the LoadGridData method runs, it reads a file where each line is “Split” on spaces “ “. This is fine and if the file is properly “space” delimited it works as expected. So let us assume everything works and the data displays in the grid properly.
Then the user presses the saveBtn which calls the SaveGridData method. The code appears to “select” all the cells in the DataGridView to the clipboard, then proceeds to write the clipboard text to the SAME file name used when loading the grid. This also appears to work as expected.
The problem with this is that when the code copies all the cells of the DataGridView to the clipboard then, writes this copied clipboard text; it will use a “Tab” delimiter. The file Event reminder.dat which was read in using a “space” delimiter will be overwritten with a “tab” delimiter and not a “space” delimiter. Therefore, then next time the load method is run… it will fail.
If the load and save button are going to read the same file, then they MUST both agree on what character is used as a delimiter. You can use whatever character you want as a delimiter. You can use a “space” as the posted code does, however this limits each type to a string with no spaces. If one of the fields is a home address, chances are good, there will be a space in the string. Using a “space” as a delimiter is not necessarily the best of choices.
A simple solution is available with the current code. Currently if the file Events reminder.dat is space delimited and reads in properly to the data grid view, then it should be easy to replace the space delimiter with something else. In this case, since the SaveGridData method is delimiting the fields with a “tab” then we simply need to change the load method to “split” on “Tabs” and not “spaces” when reading back the file.
Step 1 – make a copy of Events reminder.dat
Step 2 – Run the program, press the load button and make sure all the data is properly loaded into the grid.
Step 3 – If the data is displayed properly in the grid, press the save button. (Updates file with tab delimiters)
Step 4 – Exit the program and make the change below in the LoadGridData method.
ThisGrid.Rows.Add(Split(THisLine, vbTab))
Step 5 – Run the program. Now both the load and write methods agree on what character (Tab) is used as a delimiter.
Lastly, to comment on using a DataTable the answer would be yes. DatagridViews and DataTables play nicely together. Hope this helps.
You may want to take a “Tour” of Stackoverflow to see how it works.

how to set the line space for list?

so just look at the iText Jump-Start Tutorial of Chapter 1: Introducing basic building blocks Figure 1.2: List example, how to set the line space for the generated lists?
Line spacing is controlled by LEADING property in iText7.
One of the ways to specify leading would be to use setFixedLeading or setMultipliedLeading on iText7's Paragraph class and then add those Paragraph instances directly to ListItem instances.
A helper method for creating such a list item based on a text string looks as follows:
private ListItem createListItemWithLeading(String text) {
Paragraph paragraph = new Paragraph(text);
paragraph.setFixedLeading(30);
paragraph.setMargin(0);
ListItem listItem = new ListItem();
listItem.add(paragraph);
return listItem;
}
Another way, as there is currently no setFixedLeading or setMultpliedLeading setters on other elements than Paragraphs, would be to set this property manually to the list:
list.setProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, 2.5f));
// Add the list
document.add(list);
Please be careful when use setProperty directly and do it at your own risk. The preferred way is still to use getters/setters provided in the public API.

Access 2013: Send the form's current record only to a PDF using a report

I have a form where users input all of their data. There is a 'Save' button which saves the record, and leaves the form up and active.
Before I close the form, I need to take that newly saved record and output the associated report to a PDF file.
My problem right now is that the output to the PFD is sending all records in the table, not just the record in the form.
Here is my code at this point.
Private Sub cmdSave_Click()
Dim outl As Outlook.Application
Dim mi As Outlook.MailItem
Dim strWhere As String
Cause = "SaveButton"
DoCmd.RunCommand acCmdSaveRecord
'Save the Record
Me.btnClose.SetFocus
If Me.DateOfVisit <> "" Then
Me.RepStatus = "Report Saved!"
Me.btnNewReport.Visible = True
'Now, print the report to a PDF File
DoCmd.OutputTo acOutputReport, "rptReports", acFormatPDF,"C:\ReportTest.pdf", False
End If
End Sub
As a side note, it is required that the users would not see a report pop up on the screen and then quickly disappear.
Thanks for any assistance.
Looks like I finally noodled it out.
I added the following lines and now it is working.
Turns out that the OutputTo has no way to pass in any search criteria.
So, I opened the report in Hidden mode so the users don't see anything and then use the OutputTo to send it to a PDF.
'Now, print the report to a PDF File
DoCmd.OpenReport "rptReports", acViewReport, , "[ReportID] = " & [ReportID], acHidden
DoCmd.OutputTo acOutputReport, "rptReports", acFormatPDF, "C:\TG QUOTE SYSTEM\Meeting Reports\ReportTest.pdf", False
DoCmd.Close acReport, "rptReports"
End If
Thanks all.

how to send contents of a textbox in vb6 to a notepad document

I am trying to send the data inserted into a textbox into a notepad document so that the data can be held for future reference, as i am trying to create an assessment date reminder as i am a student.
But whenever i try to send the data with this code by writing data = "txtAssign_Name, txtAssign_Due" when i check the notepad after running the program, all that is in the document is txtAssign_Name, txtAssign_Due.
Private Sub Form_Load()
Dim Data As String
txtAssign_Name.Text = ""
txtAssign_Due.Text = ""
Data = ""
Open "F:\Personal\date calender test - Copy\test.txt" For Output As #1
Print #1, Data
Close #1
End Sub
Try this:
Data = txtAssign_Name.Text & ", " & txtAssign_Due.Text
(In the lines above, you will want to NOT set those values to "")
Note - using the built in VB6 writing to text files will result in your output being formated in a way so that VB6 can read it back in again. So all strings will have quotes aroud them, other values are displayed in a variety of odd ways, commas seperate all values.
If the output text file is desired to be primarily for human use, then I find using the richtextbox control a better way of creating the file. Add it from Project -> Components -> Controls -> Microsoft Rich Textbox Control 6.0
Add the Rich text box to your form (you can set visible = false if you don't want users to see it). Add your data to it something like this:
RichTextBox1.text = txtAssingn_Name.text & ", " & txt_Assing_Due.text
' If you need to add more things, add them on to the end like this
RichTextBox1.text = richtextbox1.text & vbcrlf & "More text on the next line"
Then, when all the data is added, you just do this
RichTextBox1.SaveFile "C:\Test.txt", rtfText
rtfText is a visual basic constant, that tells the RTB to save as plain text. The alterntaive is rtfRTF. You can learn more about the RTB on MSDN
OK, so a comment above states that you want to be able to read the data back into VB.
The code as it shown in the question will just output a blank text file, as the variable Data is set to "", so that is all that will be output.
What you need is something like this
private Sub SaveData()
dim SaveFile as integer
SaveFile = Freefile ' This gets a file number not currently in use
Open "F:\Personal\date calender test - Copy\test.txt" For Output As #Savefile
write #SaveFile, txtAssign_Name.Text, txtAssign_Due.Text
close #savefile
end sub
And call SaveData in the appropriate place. NOT form load, as the user won't have entered anything at this point. Either after the user has pressed a button, or on Form_Unload if you want it to autosave on form close.
To populate your form again, something like this
private sub LoadData()
dim LoadFile as integer
dim StringData as string
loadfile = freefile
Open "F:\Personal\date calender test - Copy\test.txt" For Input As #loadfile
input #loadfile, StringData
txtAssign_Name.Text = StringData
input #loadfile, StringData
txtAssign_Name.Text = stringdata
close #loadfile
end sub
You should also add error handing whenever working with files. VB6 is quite particular and its very easy to throw an exception when dealing with files.

How can I remove a line of text from a text file in VB6? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to read a file and write into a text file?
I have a search facility where items are displayed in a ListView. These items are read in from a file. When I select an item in the ListView I want to be able to remove it from the text file as well.
At the moment, it is is only removed from the ListView but when I search again it still displays so it isn't being deleted from the text file.
Basically my program is a list of products with their barcodes and quantities. The user can search for an item, which is displayed in the listview, then edit it to add or reduce the quantity. When they click save it is written to the file. That is all working fine, but it is now showing the item twice, same barcode and product name and different quantities.
I tried to use the replace function but that is just adding empty lines of text to my file.
I have also gotten advice to copy the file and remove the selected item. I'm unsure how to do this. Does anyone have any alternative ways to do this?
Here is my code:
Private Sub cmdEdit_Click()
Dim barcode As String
Dim prodNum As String
Dim unknown As String
Dim desc As String
Dim size As String
Dim costPrice As String
Dim retailPrice As String
Dim deptCode As String
Dim dept As String
Dim subDeptCode As String
Dim subDept As String
Dim quantity As String
Dim barcodeYes As String
Dim Number As String
Dim i As Single
ListView1.ListItems.Remove ListView1.SelectedItem.Index
Open "D:\VB\EXPORT PRODUCT FILE.CSV" For Input As #3
Input #3, barcode, prodNum, unknown, desc, size, costPrice, retailPrice, deptCode, dept, subDeptCode, subDept, quantity, barcodeYes, Number
AddQuantity.Show
AddQuantity.txtName.Text = ListView1.SelectedItem
AddQuantity.txtBarcode.Text = ListView1.SelectedItem.SubItems(1)
AddQuantity.txtQuantity.Text = ListView1.SelectedItem.SubItems(2)
Close #3
End Sub
Thanks
The only way to remove something from the middle of a file is to rewrite eveything from that point onwards.
You haven't showed your code to write to the file but I assume you're appending.
You'll need to change this to load all data, change the entry you want then save it all again.
Alternatively, use a database which is designed for this kind of use.

Resources