iTextSharp : image in cell doesn't expand - image

Hi I'm using iTextSharp 535 .
I have a table with 4rows and 3 columns with images added into paragraphs as chunks.
The image size has been resized at 640x480 , the cell with the image has a fixed height.
Dim fra As New Phrase()
Dim imageBytes = ResizeImage(Base64Value)
ImageB = iTextSharp.text.Image.GetInstance(imageBytes)
Dim Pimg As New Paragraph(vbCrLf)
Pimg.Add(New Chunk(ImageB, 0, 0, True))
Pimg.Alignment = Element.ALIGN_CENTER
fra.Add(Pimg)
Dim cell2 = New PdfPCell(fra)
cell2.FixedHeight = 320
table.AddCell(cell2)
But I get a strange result: the image doesn't expand in the next page but it is placed small at the end of it.

Related

The Picture Can't Be Display in The Cell of a Table Inserted in xceed Word Doc Header or Footer

In xceed Words for Net v2.3, I construct a one row table with two cells. I place a picture in the two cells of the table. When I add the table to the document the table is displayed with the pictures. When I add the table to the header or the footer, “The Picture Can’t Be Displayed.”
VB Code looks like this:
document = xceed.Words.NET.DocX.Create(mstream)
' set margins
document.MarginTop = 72
document.MarginBottom = 72
document.MarginLeft = 40
document.MarginRight = 40
' get the logo
Dim LogoDrawing As System.Drawing.Image
LogoDrawing = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/Images/" & LogoGif))
Dim LogoImage As Xceed.Words.NET.Image
LogoImage = document.AddImage(HttpContext.Current.Server.MapPath("~/Images/" & LogoGif))
Dim LogoPicture As Xceed.Words.NET.picture = LogoImage.CreatePicture(LogoDrawing.Height, LogoDrawing.Width)
' set up the header table
Dim hdtb As Xceed.Words.NET.Table = document.AddTable( 1, 2 )
Dim widths(2) As Single
widths(0) = 300
widths(1) = 300
hdtb.SetWidths(widths)
hdtb.Rows(0).Cells(0).Paragraphs(0).Append("").AppendPicture(LogoPicture)
hdtb.Rows(0).Cells(1).Paragraphs(0).Append("").AppendPicture(LogoPicture)
' generate header
document.AddHeaders()
document.Headers.Odd.InsertParagraph().Append("").InsertTableAfterSelf(hdtb)
document.Headers.Even.InsertParagraph().Append("").InsertTableAfterSelf(hdtb)
document.InsertTable(hdtb)
' generate footer
document.AddFooters()
document.Footers.Odd.InsertParagraph.Append("").InsertTableAfterSelf(hdtb)
document.Footers.Even.InsertParagraph.Append("").InsertTableAfterSelf(hdtb)
Thanks for your help.

Fastest way to save bitmap image to PDF using pdfsharp

I need to create a pdf file from several bitmap images. I am currently using the following code:
Dim size As New XSize(0,0)
For k = 0 to theBMPList.Count-1
Dim oPage As New PdfPage()
doc.Pages.Add(oPage)
Dim xgr As XGraphics = XGraphics.FromPdfPage(oPage)
Dim img As XImage = XImage.FromGdiPlusImage(theBMPList(k))
size = new XSize(theBMPList(k).Width, theBMPList(k).Height)
oPage.Height = size.Height
oPage.Width = size.Width
xgr.DrawImage(img, 0,0, size.Width-5, size.Height-5)
Next
This works fine but is very slow. Is there a better/faster way to do this?

iText header: add logo img on the left side and text on the right side

I´m new to iText.
I would like to make a header that will be the same on each page.
The page header will look something like this:
logo.jpg some text
How can I do that?
I have read this link:
http://developers.itextpdf.com/question/how-generate-report-dynamic-header-pdf-using-itextsharp
and I have a problem because I cant add an image to pharse.
Image image = Image.GetInstance(Server.MapPath(mclLogo));
phrase.Add(image);
Throws the Error:
Insertion of illegal Element: 32
Edit: I have tried with paragraph and glue:
Paragraph paragraph = new Paragraph();
paragraph.Add(image);
paragraph.Add(new Chunk(glue));
paragraph.Add("text on the right");
and the output is 2 lines.
somthing link this:
logo.jpg
some text
edit 2:
I have read this:
http://developers.itextpdf.com/content/itext-7-jump-start-tutorial/chapter-1-introducing-basic-building-blocks
espacially the part:
Image fox = new Image(ImageDataFactory.create(FOX));
Image dog = new Image(ImageDataFactory.create(DOG));
Paragraph p = new Paragraph("The quick brown ")
.add(fox)
.add(" jumps over the lazy ")
.add(dog);
document.add(p);
but I use iText5 and I dont find any way how to make a picture and text in the same line.
Try below code, which works with two different Header plot which plotted at right end with image and Left end one with text.
public override void OnStartPage(PdfWriter writer, iTextSharp.text.Document document)
{
PdfPTable HeaderPlot = new PdfPTable(new float[] { 10F });//Header plot 1
PdfPTable HeaderPlot2 = new PdfPTable(new float[] { 10F });//Header plot 2
PdfPCell cell;//cell 1
PdfPCell cell2;// cell 2
HeaderPlot.TotalWidth = 570F; //width for Header plot 1
HeaderPlot2.TotalWidth = 570F;//width for Header plot 2
cell = new PdfPCell();
cell2 = new PdfPCell();
string path = headerpath;
FileInfo f2 = new FileInfo(path);
FileStream fs = new FileStream(f2.FullName,
FileMode.Open, FileAccess.Read);
BinaryReader rdr = new BinaryReader(fs);
byte[] fileData = rdr.ReadBytes((int)fs.Length);
Image image = Image.GetInstance(fileData);
image.ScaleAbsolute(80, 40); //adjusting image size
image.Alignment = Element.ALIGN_CENTER;
cell = new PdfPCell(image)
{
Border = 0,
HorizontalAlignment = Element.ALIGN_TOP,
VerticalAlignment = Element.ALIGN_TOP
};//Header image position
Font font = FontFactory.GetFont("Calibri Light", 8f, Font.NORMAL,
iTextSharp.text.BaseColor.BLACK);//Initializing font
cell2 = new PdfPCell(new Phrase("Text", font))
{
Border = 0,
HorizontalAlignment = Element.ALIGN_LEFT,
VerticalAlignment = Element.ALIGN_TOP
};//Header Text position
HeaderPlot.AddCell(cell);//adding cell 1 to Headerplot 1
HeaderPlot.WriteSelectedRows(0, -1, 480, 835,
writer.DirectContent);//Position of the header on right end, coordinates on right end(480,835)
HeaderPlot2.AddCell(cell2);//adding cell 2 to Headerplot 2
HeaderPlot2.WriteSelectedRows(0, -1, 40, 835,
writer.DirectContent);//Position of the header on left end, coordinates on left end(40,835)
}

Excel VBA Issues with portrait mode pictures AddPicture

I am having issues with inserting a picture in portrait mode using VBA. If the picture is in landscape mode, then the picture is inserted into the associated shape in column B. However, if the picture is in portrait, then the picture is offset 25 columns to column AA. Any help is greatly appreciated!
Sub cmdInsert1_Click()
Dim myPicture As String, MyObj As Object
Range("b5").Select
myPicture = Application.GetOpenFilename("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", , "Select Picture to Import")
If myPicture = "False" Then Exit Sub
Set MyObj = ActiveSheet.Shapes.AddPicture(myPicture, False, True, Range("B5").Left, Range("B5").Top, -1, -1)
With MyObj
.Height = 293
.Locked = False
End With
Set MyObj = Nothing
End Sub
Windows "remembers" the orientation of the picture, so what is in the Top Left corner of your screen may not actually be the Top Left corner of the picture. You will need to check the .Rotation property of your picture. If it's rotated (ie, not 0), you will need to adjust your code accordingly. For example:
If myObj.Rotation = 0 Or myObj.Rotation = 180 Then
.Height = 293
Else
.Width = 293
End If
Edit: Forgot to account for it merely being upside down

VBA: Copy cells, paste as a picture, then save as a picture?

I have the following code:
Range("A1:M28").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Sheets.Add.Name = "Without Formatting"
Worksheets("Without Formatting").Paste _
Destination:=Worksheets("Without Formatting").Range("A1:M28")
That copies some cells then pastes them as a picture in another worksheet, is there a way of saving the picture (preferably as a jpeg) into a specific location so that I can then use the picture in an email?
I have used the following in the past. It copies the cells as an image, creates a new chart, paste the image into the chart, export the chart as an image then deletes the chart.
Range("A1:M28").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set cht = ActiveSheet.ChartObjects.Add(0, 0, Rng.Width + 0.01, Rng.Height + 0.01)
cht.Name = "tempchart"
cht.Chart.Paste
ActiveChart.Shapes.Range(Array("chart")).Select
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Line.Visible = msoFalse
ActiveSheet.ChartObjects("tempchart").Activate
ActiveSheet.Shapes("tempchart").Fill.Visible = msoFalse
ActiveSheet.Shapes("tempchart").Line.Visible = msoFalse
cht.Chart.Export strPath & "c:\filepath\imagename.jpg"
ActiveSheet.ChartObjects.Delete
Hopefully that will help,

Resources