Black background when inserting an image in PDF ITEXTSHARP - itext

I am getting a black background when I insert a image into PDF using ITextSharp version 5.5.8.0 as shown in the image:
I tried setting a white background but still no impact.
Below is the VB.NET code where I am inserting the image.My goal is to have a white background instead of the black.
Dim cb As PdfContentByte = stamper.GetUnderContent(1)
Dim structureeditor As New StructureEditor
Dim temp As System.Drawing.Image = structureeditor.StructureToImage(Me.queryMoleculeTxt.Text)
Dim compoundstructure As Image = Image.GetInstance(temp, System.Drawing.Imaging.ImageFormat.Jpeg)
' White background is set
compoundstructure.BackgroundColor = BaseColor.WHITE
compoundstructure.SetAbsolutePosition(30, 150)
cb.AddImage(compoundstructure)

Related

iText 7 Adding colored text and fill to a rectangle

I am trying to add colored text to a rectangle and fill color in the rectangle but the
text seems to be behind the rectangle and so is not visible even though I can select it.
Paragraph = new Paragraph("The quick brown fox");
PdfCanvas canvas = new PdfCanvas(pdfDoc.addNewPage());
Rectangle rect = new Rectangle(ps.getWidth() - 90, ps.getHeight() - 100, 50, 50);
new Canvas(canvas, pdfDoc, rect)
.setFontColor(ColorConstants.WHITE)
.setFontSize(12)
.add(p);
canvas.rectangle(rect)
.setFillColor(ColorConstants.LIGHT_GRAY)
.fillStroke();
You first draw the text and then fill the rectangle. Thus, obviously the text ends up behind the rectangle.
Switch the order of your instructions, first fill the rectangle rect on your PdfCanvas canvas and then add the Paragraph p to the Canvas on canvas.

ActiveReports Change Image size at runtime

I have an image that is 300px width and has to be set at runtime. At design time, the image is a different size and depending on a flag, the image has to be changed. How do I set the image width in C#/VB.NET.
I cast the object as a Picture. The Width property only takes a SINGLE value and presume its inches. How do I tell the picture control that I'm passing in is the pixel size not inches?
Here's an example of how you can set the size in pixels, convert it to inches (as the GrapeCity Team suggests), and apply it to your picture based on a conditional variable:
The following code is added in the Script section of your report:
Sub Detail_Format
Dim intSizeInPixels As Integer = 300
Dim dblSizeInInches as Double = intSizeInPixels / 96
Dim mfFlag As Boolean = True
If mfFlag Then
Picture1.Width = dblSizeInInches
End If
End Sub

How to place text on foreground of rectangle

I have existing pdf document with white rectangle at top right coner. Hidden textfield is placed on rectangle. I have to put some text on the rectangle instead of hidden field. Here is my C# code:
public void setTextOverField(String sFieldName, String sText)
{
IList<AcroFields.FieldPosition> positions = this._stamper.AcroFields.GetFieldPositions(sFieldName);
Rectangle rect = positions[0].position;
PdfContentByte cb = this._stamper.GetOverContent(positions[0].page);
cb.BeginText();
cb.SetFontAndSize(this._font, this._fontSize);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, sText, (rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2, 0);
cb.EndText();
}
Now the text is hidden under the white rectangle. If I make the rectangle transparent the text become visible.
How to bring text on foreground?

beginBitmapFill to Fill shape as a background cover works

I'm building a game with createjs and I'm trying to do something like this:
var IMG = loader.getResult("imageID");
this.model.graphics.beginBitmapFill(IMG).drawRect(0, 0, window.width , window.height);
The image should cover the background no matter what size the image is. Any ideas how this can be accomplished?

Does iText honors color transparency?

I'm using iText 5.2.1 and I tried to use the BaseColor constructor with alpha channel, that is
public BaseColor(final int red, final int green, final int blue, final int alpha)
but when I actually draw text or shapes it seems that the alpha channel isn't taken into account.
For example if I try this
Font f = ....;
f.setColor(new BaseColor(130, 130, 130, 50);
PdfContentByte cb = writer.getDirectContent();
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("my text", f),
refPointX, refPointY, 0);
the text it's written with the color specified but without the alpha information, that is with the color with 100% opacity.
The same thing happens if I try to draw some shape and I specify a fill color with transparency.
In the book iText in Action second edition there's nothing about transparency in colors.
Am I wrong?
I've found something in itext mailing list, I tried and... works!
It's a undocumented feature. Anyway the following code does what I need:
PdfContentByte cb = writer.getDirectContent();
PdfGState gState = new PdfGState();
gState.setFillOpacity(0.1f);
cb.setGState(gState);
If a draw text or shapes, they have 10% opacity. With gState.setStrokeOpacity I can also set opacity on strokes.