Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jun 25, 2018 7:29 pm

hello there!
is there a way to emed a image by using DPI to convert width and height?

EX,
Image width = 1500 px
image Height =2100 px
DPI 300
print size would be 5 X 7
currently it renders by pixels.

Also, is it possible to have large pdf width? something like quantity of 10, 5 X 7 images in a row?
Appreciate your quick response.

MuthuFrank
 
Posts: 3
Joined: Wed Jun 20, 2018 3:24 am

Tue Jun 26, 2018 2:30 am

Dear MuthuFrank,

Thanks for your inquiry.
As for the the image size, I am afraid there is no direct way in Spire to embed image and resize by DPI, yet I think you could do it by yourself, for example:
Code: Select all
float ImageWidth = 1500 px
float ImageHeight = 2100 px
float dpi = 300
//count the new size
float ReWidth = ImageWidth/dpi
float ReHeight = ImageHeight/dpi

As for the pdf width, you could design the pdf size when creating, sample code for your kind reference:
Code: Select all
            PdfDocument doc = new PdfDocument();
            SizeF size = new SizeF(100, 800);
            //add page with custom page size
            PdfPageBase page = doc.Pages.Add(size);

If you want to change the page size of existing pdf, please refer to the guide.

If I misunderstand your requirement or your issue still exists, please share us more details, the code you were using and input files and the expected file you want for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jun 26, 2018 8:39 pm

Thanks for your response!

PDF size works perfect. but am still confused with your reply on image size.

deriving the image size based on dpi is not a problem but how do i specify the image size as inch instead of pixels?

Code: Select all
    PdfGridCellTextAndStyleList lst = new PdfGridCellTextAndStyleList();

            PdfGridCellTextAndStyle textAndStyle = new PdfGridCellTextAndStyle();

            textAndStyle.Image = PdfImage.FromFile(FileName);

            textAndStyle.ImageSize = new SizeF(textAndStyle.Image.Width, textAndStyle.Image.Height);
            lst.List.Add(textAndStyle);


here is my requirement, add multiple images in a row and can have # of rows and each row can be different sizes.

Am not sure does Spire has row level styling in PdfGrid?

PDFgrid.rar

MuthuFrank
 
Posts: 3
Joined: Wed Jun 20, 2018 3:24 am

Wed Jun 27, 2018 3:37 am

Dear MuthuFrank,

Thanks for your feedback.
I checked the code in the Word document you provided, and found it could get image size with unit inch. One thing needs to be noticed is that the unit in PDF is point, when drawing image, the default unit is point.
Code: Select all
 
        PdfGridCellContentList lst = new PdfGridCellContentList();
          PdfGridCellContent textAndStyle = new PdfGridCellContent();
          textAndStyle.Image = PdfImage.FromFile(@"F:\image\image1.jpg");

          float width = textAndStyle.Image.Width;
          float height = textAndStyle.Image.Height;
          float dpi = textAndStyle.Image.VerticalResolution;

          float newWidthInch = width / dpi;
          float newheightInch = height / dpi;
          //1 inch = 72 points
          textAndStyle.ImageSize = new SizeF(newWidthInch * 72, newWidthInch * 72);
         
          //convert image size from pixel to point
          //PdfUnitConvertor uinit = new PdfUnitConvertor();
          //SizeF pageSize = uinit.ConvertFromPixels(new Size(width ,height), PdfGraphicsUnit.Point);

Note, in the latest Spire.PDF Pack(Hot Fix) Version:4.6.4, we had changed the class name PdfGridCellTextAndStyleList to PdfGridCellContentList, PdfGridCellTextAndStyle to PdfGridCellContent. And from your code, I knew you were using old version.

Sorry there is no row style like PdfGridRowContent style, and you need to insert image cell by cell.

Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jun 27, 2018 3:47 pm

Perfect. This helps! will check and get back to you if needed.Thank you!

MuthuFrank
 
Posts: 3
Joined: Wed Jun 20, 2018 3:24 am

Thu Jun 28, 2018 2:23 am

Dear MuthuFrank,

Thanks for your feedback.
Please feel free to contact us if you need any help.
Have a nice day.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF