Rank: Newbie
Groups: Registered
Joined: 5/26/2017(UTC) Posts: 6  Location: nm
|
Hello, What I have. The application currently works using the Migradoc libraries, but they produce a fair number of PDF that cannot be read by adobe. It loads a tiff and gets the dpi etc from construction blueprints. It then makes a single page pdf and saves it. DPI is a must here, as the resulting file are used in estimating software, as is page width of the pdf and so on. Here is the desired behavior. Load an image based on processing options, and then this Code:
using(Bitmap InsetImage = Blueprint as Bitmap)
{
using(PdfDocument docu = PdfDocument.CreateNew())
{
docu.Pages.InsertPageAt(0,pagewidth,pageheight);
var image = InsertImageToPage(docu,docu.Pages[0],InsetImage,new PointF(0,0));
docu.Save(tmpPath,Patagames.Pdf.Enums.SaveFlags.NoIncremental);
}
}
static public PdfImageObject InsertImageToPage(PdfDocument doc, PdfPage page, System.Drawing.Bitmap bmp, PointF atPoint)
{
var bi = bmp.LockBits(
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
//Create PdfBitmap object from .Net bitmap
var bitmap = new PdfBitmap(
bmp.Width,
bmp.Height,
Patagames.Pdf.Enums.BitmapFormats.FXDIB_Rgba,
bi.Scan0,
bi.Stride);
//Create pdf image object and then set PdfBitmap object into it.
var image = PdfImageObject.Create(doc);
image.SetBitmap(bitmap);
//Scale image object to it's actual width and heihgt
image.SetMatrix(bmp.Width, 0, 0, bmp.Height, (float)atPoint.X, (float)atPoint.Y);
page.PageObjects.InsertObject(image);
bmp.UnlockBits(bi);
return image;
}
That mess produces a bank white page with the proper dimensions. I previously tried the code found here. https://forum.patagames....ge-into-newly-added-pageI have also read the API docs and am having no luck at all. I don't/can't start with a pre-existing pdf, which every single example shows. I've been at this for about a week with no luck at all. Is there a simple example of: Create PDF Add Page[0] Stuff an indexed Tiff in there Set height width and dpi Save that bad boy. Or at least an explanation that can help me understand why the data from InsertImageINto Page isn't doing it's thing. Should I be using the return? Am I passing the page wrong?
|