Change font size; checklist box items are on top of each other - font-size

We remote into our work environment. When working from home the monitor scale looks different than at work. I've spent hours trying to get them to look the same and failed. So I would like to add a scaler(font increaser/decreaser) to my program. The concept is to change the font size of the form and the rest will scale. It seems to work fine except the checklist box(See screenshots). The items are almost stacked on top of each other. I can't seem to get it to update or redraw itself. I'm writing in VB.NET by the way(I know:)). I've tried CheckListBox.Update(); CheckListBox.Refresh(); CheckListBox.ResetText() and all have failed. Is there a way to separate them? perhaps my approach is wrong. What do you think?
Initial Run Tiny
Scale up
VB.NET
Private Sub Btn_Scale_Up_Click(sender As Object, e As EventArgs) Handles Btn_Scale_Up.Click
Dim FntSize as Integer = Font.Size
FntSize += 1
Me.Font = New Font("Arial", FntSize)
FrmResize.ResizeAllControls(Me)
'CLBox_ColumsForDescription.Update()
'CLBox_ColumnsForDescription.Refresh()
'CLBox_ColumnsForDescription.ResetText()
Me.Update()
End Sub
Private Sub Btn_Scale_Down_Click(sender As Object, e As EventArgs) Handles Btn_Scale_Down.Click
Dim FntSize as Integer = Font.Size
FntSize -= 1
Me.Font = New Font("Arial", FntSize)
FrmResize.ResizeAllControls(Me)
'CLBox_ColumsForDescription.Update()
'CLBox_ColumnsForDescription.Refresh()
'CLBox_ColumnsForDescription.ResetText()
Me.Update()
End Sub
Public Class ResizerForm1
Public Sub ResizeAllControls(ThisCtrl as Control)
For Each Ctl as Control in ThisCtrl.Controls
If Ctl.Name.Contains("CLBox_ColumsForDescription") Then
'--Size
Ctl.Width = Int(ParentWidth - Ctl.Location.X - 30)
Ctl.Height = Int(ParentHeight - Ctl.Location.Y - (ParentHeight - Ctl.Parent.Controls.Item("Btn_Below").Location.Y))
'--Position
Ctl.Top = Int(Ctl.Parent.Controls.Item("TxtBox_Above").Location.Y + Ctl.Parent.Controls.Item("TxtBox_Above").Height + 5)
Ctl.Left = 15
'Ctl.Update()
'Ctl.Refresh()
End If
Next
End Sub
End Class

Related

Creating a checkbox and printing it to pdf file is not working using pdfbox 1.8.9 api

I'm using grails with pdfbox plugin. I'd like to print checkboxes in pdf some are checked and some are not.
To print checkbox I did not a direct way(Even by using PDCheckbox class). So I've used the other way to print the checkbox with tick mark using the below code:
public static writeInputFieldToPDFPage( PDPage pdPage, PDDocument document, Float x, Float y, Boolean ticked) {
PDFont font = PDType1Font.HELVETICA
PDResources res = new PDResources()
String fontName = res.addFont(font)
String da = ticked?"/" + fontName + " 10 Tf 0 0.4 0 rg":""
COSDictionary acroFormDict = new COSDictionary()
acroFormDict.setBoolean(COSName.getPDFName("NeedAppearances"), true)
acroFormDict.setItem(COSName.FIELDS, new COSArray())
acroFormDict.setItem(COSName.DA, new COSString(da))
PDAcroForm acroForm = new PDAcroForm(document, acroFormDict)
acroForm.setDefaultResources(res)
document.getDocumentCatalog().setAcroForm(acroForm)
PDGamma colourBlack = new PDGamma()
PDAppearanceCharacteristicsDictionary fieldAppearance =
new PDAppearanceCharacteristicsDictionary(new COSDictionary())
fieldAppearance.setBorderColour(colourBlack)
if(ticked) {
COSArray arr = new COSArray()
arr.add(new COSFloat(0.89f))
arr.add(new COSFloat(0.937f))
arr.add(new COSFloat(1f))
fieldAppearance.setBackground(new PDGamma(arr))
}
COSDictionary cosDict = new COSDictionary()
COSArray rect = new COSArray()
rect.add(new COSFloat(x))
rect.add(new COSFloat(new Float(y-5)))
rect.add(new COSFloat(new Float(x+10)))
rect.add(new COSFloat(new Float(y+5)))
cosDict.setItem(COSName.RECT, rect)
cosDict.setItem(COSName.FT, COSName.getPDFName("Btn")) // Field Type
cosDict.setItem(COSName.TYPE, COSName.ANNOT)
cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"))
if(ticked) {
cosDict.setItem(COSName.TU, new COSString("Checkbox with PDFBox"))
}
cosDict.setItem(COSName.T, new COSString("Chk"))
//Tick mark color and size of the mark
cosDict.setItem(COSName.DA, new COSString(ticked?"/F0 10 Tf 0 0.4 0 rg":"/FF 1 Tf 0 0 g"))
cosDict.setInt(COSName.F, 4)
PDCheckbox checkbox = new PDCheckbox(acroForm, cosDict)
checkbox.setFieldFlags(PDCheckbox.FLAG_READ_ONLY)
checkbox.setValue("Yes")
checkbox.getWidget().setAppearanceCharacteristics(fieldAppearance)
pdPage.getAnnotations().add(checkbox.getWidget())
acroForm.getFields().add(checkbox)
}
This code is working fine in my application, this method is adding checkboxes with tick marks also.
But I can see those rectangle checkboxes or tick marks in only pdf readers, not in all other readers(Like chrome default pdf viewer), and even when I try to print the pdf its not printing the checkboxes, rather its printing some random ASCII numbers.
Please let me know if there is any other way to do this or even if I have to refactor the code.
What is wrong
Your AcroForm checkbox field construction is wrong: You treat it as a text field for which a PDF reader should create an appearance based on the default appearance (DA) value of the field in particular if NeedAppearances is true.
Checkboxes are different, though: you do have to supply an appearance stream at least for the on state, cf. the specification ISO 32000-1:
A check box field represents one or more check boxes that toggle between two states, on and off, when manipulated by the user with the mouse or keyboard. Its field type shall be Btn and its Pushbutton and Radio flags (see Table 226) shall both be clear. Each state can have a separate appearance, which shall be defined by an appearance stream in the appearance dictionary of the field’s widget annotation (see 12.5.5, “Appearance Streams”). The appearance for the off state is optional but, if present, shall be stored in the appearance dictionary under the name Off. Yes should be used as the name for the on state.
(ISO 32000-1 section 12.7.4.2.3 "Check Boxes")
Thus, instead of constructing a DA entry you have to construct an AP ("appearances") entry, itself a dictionary with at least a N ("normal appearances") entry, itself a dictionary with at least an entry for the on state appearance which is recommended to be called Yes.
The specification provides an example which shows a typical check box definition:
1 0 obj
<< /FT /Btn
/T (Urgent)
/V /Yes
/AS /Yes
/AP << /N << /Yes 2 0 R /Off 3 0 R>>
>>
endobj
2 0 obj
<< /Resources 20 0 R
/Length 104
>>
stream
q
0 0 1 rg
BT
/ZaDb 12 Tf
0 0 Td
(4) Tj
ET
Q
endstream
endobj
3 0 obj
<< /Resources 20 0 R
/Length 104
>>
stream
q
0 0 1 rg
BT
/ZaDb 12 Tf
0 0 Td
(8) Tj
ET
Q
endstream
endobj
(The resources in 20 0 obj appear to include a font resource named ZaDb referencing ZapfDingbats.)
By the way, you mention that there is a PDF viewer which actually displays a tick for your document as is. You might want to inform their development that they are doing the wrong thing there.
An example
In a comment you asked for sample code and indicated that it was ok if it were for a current 2.0.x version of PDFBox. So I tried it and came up with this code:
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDAcroForm acroForm = new PDAcroForm(document);
document.getDocumentCatalog().setAcroForm(acroForm);
COSDictionary normalAppearances = new COSDictionary();
PDAppearanceDictionary pdAppearanceDictionary = new PDAppearanceDictionary();
pdAppearanceDictionary.setNormalAppearance(new PDAppearanceEntry(normalAppearances));
pdAppearanceDictionary.setDownAppearance(new PDAppearanceEntry(normalAppearances));
PDAppearanceStream pdAppearanceStream = new PDAppearanceStream(document);
pdAppearanceStream.setResources(new PDResources());
try (PDPageContentStream pdPageContentStream = new PDPageContentStream(document, pdAppearanceStream))
{
pdPageContentStream.setFont(PDType1Font.ZAPF_DINGBATS, 14.5f);
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset(3, 4);
pdPageContentStream.showText("\u2714");
pdPageContentStream.endText();
}
pdAppearanceStream.setBBox(new PDRectangle(18, 18));
normalAppearances.setItem("Yes", pdAppearanceStream);
pdAppearanceStream = new PDAppearanceStream(document);
pdAppearanceStream.setResources(new PDResources());
try (PDPageContentStream pdPageContentStream = new PDPageContentStream(document, pdAppearanceStream))
{
pdPageContentStream.setFont(PDType1Font.ZAPF_DINGBATS, 14.5f);
pdPageContentStream.beginText();
pdPageContentStream.newLineAtOffset(3, 4);
pdPageContentStream.showText("\u2718");
pdPageContentStream.endText();
}
pdAppearanceStream.setBBox(new PDRectangle(18, 18));
normalAppearances.setItem("Off", pdAppearanceStream);
PDCheckBox checkBox = new PDCheckBox(acroForm);
acroForm.getFields().add(checkBox);
checkBox.setPartialName("CheckBoxField");
checkBox.setFieldFlags(4);
List<PDAnnotationWidget> widgets = checkBox.getWidgets();
for (PDAnnotationWidget pdAnnotationWidget : widgets)
{
pdAnnotationWidget.setRectangle(new PDRectangle(50, 750, 18, 18));
pdAnnotationWidget.setPage(page);
page.getAnnotations().add(pdAnnotationWidget);
pdAnnotationWidget.setAppearance(pdAppearanceDictionary);
}
// checkBox.setReadOnly(true);
checkBox.check();
// checkBox.unCheck();
document.save(new File(RESULT_FOLDER, "CheckBox.pdf"));
document.close();
(CreateCheckBox test testCheckboxForSureshGoud)
Be sure to use either
checkBox.check();
or
checkBox.unCheck();
as otherwise the state of the box is undefined.
#mkl has a good answer, but I think it can be simplified a little bit in case you already have a Document and just want to add a PDCheckbox (scala):
def addCheckboxField(
doc: PDDocument,
form: PDAcroForm,
name: String,
pg: Int, // page number
x: Float,
y: Float,
width: Float,
height: Float
) = {
val normalAppearances = new COSDictionary()
normalAppearances.setItem(
"Yes", {
val appearanceStream = new PDAppearanceStream(doc)
appearanceStream.setResources(new PDResources())
appearanceStream
}
)
val appearanceDictionary = new PDAppearanceDictionary()
appearanceDictionary.setNormalAppearance(new PDAppearanceEntry(normalAppearances))
appearanceDictionary.setDownAppearance(new PDAppearanceEntry(normalAppearances))
val field = new PDCheckBox(form)
field.setPartialName(name)
val widget = field.getWidgets.get(0)
widget.setAppearance(appearanceDictionary)
form.getFields.add(field)
val page = doc.getPage(pg)
widget.setRectangle(new PDRectangle(x, y, width, height))
widget.setPage(page)
widget.setPrinted(true)
page.getAnnotations().add(widget)
// do what you want with it
field.unCheck()
}
It's likely there are other simplifications that can be made, but this is what worked for me.
PdfBox version: 2.0.21

Connecting a grid up with rope constraints

I'm trying to make a kind of "cloth simulation" by using ROBLOX's new rope constraints and a grid of parts.
Currently, I've made a 10x10 grid of .4x.4x.4 blocks and now I want to connect each one up with rope constraints.
I've named each part in the grid after their row and column (eg: first part in the grid being 1 1, last one being 10 10)
and then I get the parts around each individual grid part using their name and string manipulation.
I then insert 4 attachments into each part and 4 rope constraints.
Here's the code (ab stands for above, be stands for below, etc) :
for i2 = 1, #gParts do
local ab = tostring(tonumber(gParts[i2].Name:match("^(%S+)"))-5).." "..tostring(tonumber(string.sub(gParts[i2].Name,-1))-1)
local be = tostring(tonumber(gParts[i2].Name:match("^(%S+)"))+5).." "..tostring(tonumber(string.sub(gParts[i2].Name,-1))+1)
local le = tostring(tonumber(gParts[i2].Name:match("^(%S+)"))-1).." "..tostring(tonumber(string.sub(gParts[i2].Name,-1)))
local ri = tostring(tonumber(gParts[i2].Name:match("^(%S+)"))+1).." "..tostring(tonumber(string.sub(gParts[i2].Name,-1)))
for i3 = 1, 4 do
local atchm = Instance.new("Attachment",gParts[i2])
local ropeconst = Instance.new("RopeConstraint",gParts[i2])
end
end
Rope constraint has 2 main properties I need to use; attachment 1 and attachment 2.
I've never really messed with the new constraints, but I believe this should work.
Do keep in mind that the constraints are a new Instance in Roblox, and that they are likely still experimental.
X = 10;
Y = 10;
spread = 4;
--Spread is the Length of the Constraint. You may have to increase this, especially if it's stiff.
function createAttachments()
--This is under the assumption that gParts is a table filled with the Part Instances
for i,v in pairs(gParts) do
local atch = Instance.new("Attachment",v);
end;
end;
function connectConstraints(part,x,y)
if x ~= X then
connectRight = x+1.." "..y;
end;
if y ~= Y then
connectDown = x.." "..y+1;
end;
if connectRight ~= nil then
local ropeconst = Instance.new("RopeConstraint",part);
ropeconst.Length = spread;
ropeconst.Attachment0 = part.Attachment;
ropeconst.Attachment1 = connectRight.Attachment;
end;
if connectLeft ~= nil then
local ropeconst = Instance.new("RopeConstraint",part);
ropeconst.Length = spread;
ropeconst.Attachment0 = part.Attachment;
ropeconst.Attachment1 = connectLeft.Attachment;
end
end
createAttachments();
connectConstraints();
If this does not work for you, please let me know. I can contact you from the site itself if needed.

How to split a multi-frame TIFF image in pagewise in .NET 2.0?

I want to split multlipage tiff image in page wise.
I have written following code.
Dim pagecount, ImagePageCount As Integer
Dim activePage As Integer
Dim sourceImage As System.Drawing.Image = Nothing
Dim fImage As Bitmap = Nothing
Dim pageLoad As Boolean = False
Try
fImage = New Bitmap(tempFilePath)
sourceImage = fImage
pagecount = sourceImage.GetFrameCount(FrameDimension.Page)
pageLoad = True
Catch ex As Exception
pageLoad = False
Throw
End Try
Try
If pageLoad = True Then
If pagecount <> 0 Then
For ImagePageCount = 0 To pagecount - 1
sourceImage.SelectActiveFrame(FrameDimension.Page, ImagePageCount)
activePage = ImagePageCount + 1
Dim img1 As Drawing.Bitmap = CType(sourceImage.Clone, Drawing.Bitmap)
Dim tempPageFile As String = Path.Combine(Path.GetTempPath(), String.Format("{0}_{1}_{2:00000000}_{3}.tif", Convert.ToString(indexEntry.GetFrameNumber()), Convert.ToString(indexEntry.GetCaseNumber()), document.ISN, activePage))
img1.Save(tempPageFile)
zip.AddFile(tempPageFile, "")
Next
End If
sourceImage.Dispose()
fImage.Dispose()
End If
Mostly it works but when image with different size(in pixels) came that time sourceImage.SelectActiveFrame(FrameDimension.Page, ImagePageCount) fails.
I have observed that it happens only when first page's size is smaller than rest of the pages.
Any thoughts on this.
Thanks
The page size should not affect it. Testing similar code with a 3-page TIFF file where the first page was smaller than the other 2 worked in a .NET 2.0 program.
However, since TIFF can have a different compression format for each page, most likely the failure happens if you hit a page that's not supported by GDI+ on your operating system.
The test file that worked has all 3 pages saved with LZW compression.
See the following post for a discussion of how different Windows versions support different sub-types of TIFF:
C# Generic GDI+ Error when using Image.Save()

How to see Items in a ListBox Longer than the width of the control

I have a List Box which have certain dimentions
Some of the Items are loger than the width of the ListBox control.
When I pass the mouse over these Items I want to see all the name.
I'm using vb.net
Try this:
Private Sub ListBox1_MouseMove (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
Dim ListMousePosition As Point = Me.ListBox1.PointToClient(Me.MousePosition)
Dim itemIndex As Integer = Me.ListBox1.IndexFromPoint(ListMousePosition)
If itemIndex > -1 Then
Dim s As String = Me.ListBox1.Items(itemIndex).ToString()
Dim g As Graphics = Me.ListBox1.CreateGraphics()
If g.MeasureString(s, Me.ListBox1.Font).Width > Me.ListBox1.ClientRectangle.Width Then
Me.ToolTip.SetToolTip(Me.ListBox1, s)
else
Me.ToolTip.SetToolTip(Me.ListBox, "")
End If
g.Dispose()
End If
End Sub

Is it possible to use an offset when using the Symfony sfPager class?

I would like to disregard the first n items in a pager list of items. I.e. they are being used elsewhere in the design.
So my pager list needs to be as such:
Page 1: Items 8 - 17
Page 2: Items 18 - 27
Page 3: Items 28 - 37
...
However, setting an offset or limit in the criteria object does nothing. I presume they are used by the pager itself.
Is it possible to add a offset to the pager class in some other way?
Ok, I have got around the problem by modifying sfPropelPager.class.php and putting it into a new class file which I have named atPropelPagerOffset.class.php
It works in exactly the same way apart from it takes an extra parameter, $offset
So the top of the file looks like:
protected
$criteria = null,
$peer_method_name = 'doSelect',
$peer_count_method_name = 'doCount',
$offset = 0;
public function __construct($class, $maxPerPage = 10, $offset = 0)
{
parent::__construct($class, $maxPerPage);
$this->setCriteria(new Criteria());
$this->tableName = constant($class.'Peer::TABLE_NAME');
$this->offset = $offset;
}
Then I have made this tiny change around line 50
$c->setOffset($offset+$this->offset);
Works a treat!
Simpler solution would be a custom select method:
$pager->setPeerMethod('doSelectCustom');
and then put your logic in the model Peer Class:
public static function doSelectCustom($c)
{
$c2 = clone $c;
$offset = $c2->getOffset();
$limit = $c2->getLimit();
$someCustomVar = someClass::someMethod();
if ($offset == 0) // we are in the first page
{
$c2->setLimit($limit - $someCustomVar);
$c2->add(self::SOMECOLUMN, false);
} else $c2->setOffset($offset - $someCustomVar);
return self::doSelectRS($c2); // or doSelect if you wanna retrieve objects
}

Resources