开发者

abcPDF is malforming my image after adding it to a pdf

I'm getting a byte array representing a TIFF file from my server, converting it into an XImage, and then adding it to a开发者_开发百科 new pdf document. The image in question is 1280x800 (it was a screenshot) and is being stretched out and lengthened to fit the height and width of a standard pdf page. How do I fix this?

abcPDF is malforming my image after adding it to a pdf


Try this:

    doc.MediaBox.String = img.BoundingBox.String;
    doc.Rect.String = doc.MediaBox.String;

where doc is Doc and img is XImage


The particular problem you have is due to having the printer set to Portrait.

Being a PDF object, you may need to emulate a page that mimics the image size you are after.

You might be better off sending your original document to an image and adding your TIFF file.


Depends on how the PDF page is being built. What you probably want to do is ensure that the PDF page that you are creating has the same aspect ratio as your image rather than defaulting to a letter sized page.

Since you don't specify how you're making the PDF page, I can't help you specifically. But in general, PDF pages are in units of 1/72 of an inch. You can figure the right size page like this:

const kPdfPageUnitSize = 72f;

float GetPdfSize(int nPixels, float dotsPerInch) {
    return (nPixels / dotsPerInch) * kPdfPageUnitSize;
}


// later
float pdfwidth = GetPdfSize(image.Width, image.Resolution.X); // or however you have this
float pdfheight = GetPdfSize(image.Height, image.Resolution.Y);


As I can see, image scale coefficient is incorrect. You should divide image Height and image Width on 1,33(3) ( i.e. 96f/72f )

By default PDF user unit is 1⁄72 inch, so your image DPI should be proportional with original.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜