Hi,
I have an header image that I want it to appear on the Header of the PDF. The image contains a logo and company’s address on the right. Here is how the image looks like.
[ logo | companyaddress]
The problem is when I view PDF on 100% the image appears somewhat sharp(although not exactly as original .jpg file), but when I zoom it the header image doesn’t scale properly and text on the image becomes blur.
Is there any way I can specify a high resolution image that zooms well and doesn’t blur on zoom.
Alternatively, i was thinking of splitting the image into two. The logo will appear as image but address can be added as Text besides the logo. But I don’t know how to place text beside image. Any help?
Thanks in advance for your ideas.
Thanks
amir
==============================
Section sec1 = pdf.Sections.Add();
HeaderFooter hf1 = new HeaderFooter(sec1);
HeaderFooter hf2 = new HeaderFooter(sec1);
hf2.Margin.Right = 0;
hf2.Margin.Left = 80F;
sec1.PageInfo.Margin.Left = 50F;
sec1.PageInfo.Margin.Right = 50F;
//Set the header of odd pages of the PDF document
sec1.OddHeader = hf1;
sec1.OddFooter = hf2;
//Set the header of even pages of the PDF document
sec1.EvenHeader = hf1;
sec1.EvenFooter = hf2;
//Create an image object in the section
Image image1 = new Image(hf1);
Image image2 = new Image(hf2);
//Add image object into the Paragraphs collection of the section
hf1.Paragraphs.Add(image1);
hf2.Paragraphs.Add(image2);
image1.ImageInfo.ImageFileType = ImageFileType.Jpeg;
image2.ImageInfo.ImageFileType = ImageFileType.Png;
//Set the path of image file
image1.ImageInfo.File = HttpContext.Current.Server.MapPath("~/images/h2.jpg");
image2.ImageInfo.File = HttpContext.Current.Server.MapPath("~/images/footer.png");
image1.ImageScale = 2.74F;
Hello Amir,
Thanks for considering Aspose.
I'm not sure why you are facing the Image blur issue when you Zoom over the PDF document. Can you please share the resource image file so that we can test the issue at our end.
Beside this, regarding your second requirement to display Text next to image file in Header section, please visit the following link for related information. Image & Page Number in Header/Footer section.
In case it does not satisfy your requirement or you have any further query, please feel free to contact.
Thank you for your Quick reply.
Please see attached image that i am using as a header. The text on the image blurs when you zoom.
As for the other suggestion. The example in the link Image & Page Number in Header/Footer section is just adding an image to the header. I want to add image and text side-by-side.I tried adding image and text but they come different line not sidebyside.
If you see the attached image there is an address besides image, if somehow we can replace that with the Text object then the text will scale well with the zoom.
Thanks and appreciate for your help.
Amir
Hello Amir,
In order to accomplish this, try using the InlineParagraph property of Segment class. Over the link Image & Page Number in Header/Footer section Please take a look over the section where InLineParagraph is explained.
For more information on InLineParagraph, please visit this link.
In case it still it does not satisfy your requirement or you have any further query, feel free to contact.
Thank, I will try that. By how about to my original question of image coming up as blur when I zoom.
Is there anything i need to change in the code.
Thank you very much for your quick responses. You guys are brilliant.
Hi Nayyer,
Just tried and I can’t align image with the text as shown in the image. If you have a sample that can do please let me know.
Thanks
Amir
Hello Amir,
As you have multiple lines of text, so I would suggest you to use a table in the header section. Where a table is comprised of 1 row and two columns. In first column you can add image and add the text object in second column. Please try using the following code snippet to accomplish your requirement. I've also attached the resultant PDF document.
[C#]
//Instantiate a Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();
//=====================================================//
// Header to show an Image inline with text
//=====================================================//
// Create Header Section of the document
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter(sec1);
// set the Odd header for the PDF file
sec1.OddHeader = header;
// Set the Even Header for the PDF file
sec1.EvenHeader = header;
// Create a table to be added to the Header section.
Aspose.Pdf.Table Header_Table = new Aspose.Pdf.Table();
//Set with column widths of the table
Header_Table.ColumnWidths = "170 110";
//Set table border using another customized BorderInfo object
Header_Table.Border = new BorderInfo((int)BorderSide.All, 1F);
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
Header_Table.DefaultCellPadding = margin;
// set top margin for Header section
header.Margin.Top = margin.Top = 5;
// add the table to header section
header.Paragraphs.Add(Header_Table);
//Create an image object in the section
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
//Set the path of image file
image1.ImageInfo.File = "d:/pdftest/headernew.jpg";
//Set the type of image using ImageFileType enumeration
image1.ImageInfo.ImageFileType = ImageFileType.Jpeg;
// set the image width Information
image1.ImageInfo.FixWidth = 150;
// add the first row to the table
Aspose.Pdf.Row row1 = Header_Table.Rows.Add();
row1.Cells.Add().Paragraphs.Add(image1);
// Create a new segment to be added to text object
Text text1 = new Text("1234 Acme Street, \n Some Street State, \n U.S.A 112344 \n Fax: (345) 987656 \n www.company.com");
row1.Cells.Add().Paragraphs.Add(text1);
//Save the Pdf
pdf1.Save("d:\\pdftest\\InLine_Image_and_text_in_Header.pdf");
Thank you very much Nayyer for solving my problem.
Really appreciate it!