logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Cecil  
#1 Posted : Friday, May 26, 2017 7:30:42 AM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
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-page

I 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?

Cecil  
#2 Posted : Friday, May 26, 2017 8:38:56 AM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
Location: nm

A quick update, having looked through the other examples I've added this code
Code:

page.GenerateContent();


Which is generating a page now. However, while the pdf page is 36inches wide and 24 tall, as it should be, it is only rendering the bottom left corner of the blueprints. Roughly 1/16 of the size. How do I fix that part?
Paul Rayman  
#3 Posted : Sunday, May 28, 2017 4:20:53 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Could you please provide a full code and your tiff image.
You can send it to pr@patagames.com

It seems the original image and a page that you are created has different size.
Try to pass into SetMatrix method the page's size instead of image's size.

image.SetMatrix(page.Width, 0, 0, page.Height, (float)atPoint.X, (float)atPoint.Y);

Cecil  
#4 Posted : Tuesday, May 30, 2017 7:51:31 AM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
Location: nm

I sent that code, the Tif and the pdf it made
Paul Rayman  
#5 Posted : Tuesday, May 30, 2017 2:11:03 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Are you tried to make changes with the matrix, as suggested above?

Edited by user Tuesday, May 30, 2017 2:12:43 PM(UTC)  | Reason: Not specified

Cecil  
#6 Posted : Tuesday, May 30, 2017 4:05:36 PM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
Location: nm

Originally Posted by: Paul Rayman Go to Quoted Post
Are you tried to make changes with the matrix, as suggested above?


Yes, I have adjusted the matrix, utilizing the code provided above, taken from the example provided. (line 37)

The result yielded is that right side of the image is simply not present after lockBits(), or maybe after the matrix transform. I am not sure, since I am in fact using the resulting image as my output. (line 19)

The data doesn't seem to be making it through the steps. This is evidenced by the fact that the image data, when shrunk or enlarged continues to see the exact same loss. I iterated through 243 images to check as well, there was no change.

In the example I sent to the above poster, I showed the original image, and the created pdf(with the rigthmost ~10% missing).

The code above is directly based off of the example provided by patagames on the pdfium forum.It contains the routine which, when called uses the matrix transform to size the image. This is not my code, it's actually yours.


Thanks for any help you can provide.
Paul Rayman  
#7 Posted : Tuesday, May 30, 2017 4:22:51 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Please read this article
https://blog.patagames.com/post/how-to-create-a-pdf-from-multiple-scanned-pages-in-your-c-code

I have tested the code in this article with your tiff file. It's produce correct PDF which can be opened by Adobe Reader.

The article contains a detailed explanation of how your task can be solved.
Cecil  
#8 Posted : Tuesday, May 30, 2017 9:04:47 PM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
Location: nm

Thanks,
I'll run it through as soon as i get the chance.
Cecil  
#9 Posted : Wednesday, May 31, 2017 9:34:39 AM(UTC)
Quote
Cecil

Rank: Newbie

Groups: Registered
Joined: 5/26/2017(UTC)
Posts: 6
United States
Location: nm

Originally Posted by: Paul Rayman Go to Quoted Post
Please read this article
https://blog.patagames.com/post/how-to-create-a-pdf-from-multiple-scanned-pages-in-your-c-code

I have tested the code in this article with your tiff file. It's produce correct PDF which can be opened by Adobe Reader.

The article contains a detailed explanation of how your task can be solved.


That was amazingly easy to follow and to adapt to my needs. It is also running about 700% faster than PDFSharp and more reliably than the Adobe SDK...
I am going to see what the boss will do about a license for me!

Thank you so much!!!

If my classes were as easy to understand as the blog post you wrote, this would be done ages ago.

You pretty much just saved my job by the way!

Thanks!
Quick Reply Show Quick Reply
Users browsing this topic
Guest (2)
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.