Hello,
 
The
following sample does not work with the latest iTextSharp. The produced PDF
file has not the related XObjects of the image file. So the Adobe reader is not
able to show the image.
But this
code works fine with iTextSharp 5.4.1.
I found a
simple solution for that: I have to move the lines after the `pdfDoc.Open`
before it, to make it work.
 
using
System.Diagnostics;
using
System.IO;
using
iTextSharp.text;
using
iTextSharp.text.pdf;
 
namespace
OptimizeImageSizes
{
    public class PageEvents :
PdfPageEventHelper
    {
        public override void
OnStartPage(PdfWriter writer, Document pdfDoc)
        {
            base.OnStartPage(writer, pdfDoc);
 
            var table = new PdfPTable(1);
            var img =
Image.GetInstance("myImage.png");
            var cell = new PdfPCell(img,
false);
            table.AddCell(cell);
            pdfDoc.Add(table);
        }
    }
 
    public static class CrashWith534
    {
        public static void Test()
        {
            using (var pdfDoc = new
Document(PageSize.A4))
            {
                var pdfWriter =
PdfWriter.GetInstance(pdfDoc, new FileStream("Test.pdf",
FileMode.Create));
                pdfWriter.PageEvent = new
PageEvents();
 
                pdfDoc.Open();
 
                pdfWriter.SetPdfVersion(new
PdfName("1.5"));
                pdfWriter.SetFullCompression();
            }
 
            Process.Start("Test.pdf");
        }
    }
}
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to