Hi,
Hi Nicolas,
Hi Nicolas,
Hi,
Hi,
Hi Nicolas,
Hi Nicolas,
Hi,
Hi Nicolas,
using (Aspose.Pdf.Document
doc = new Aspose.Pdf.Document(“Document (1).pdf”))<o:p></o:p>
{
//Check first page to verify size and adjust if not 8.5 x 11 inches
PageInfo pageInfo = new PageInfo();
if (doc.Pages[1].MediaBox.URY != pageInfo.Height || doc.Pages[1].MediaBox.URX != pageInfo.Width)
{
pageInfo.Height = (int)doc.Pages[1].MediaBox.URY;
pageInfo.Width = (int)doc.Pages[1].MediaBox.URX;
}
Stream imageMemoryStream = new MemoryStream();
float halfWidth = 0.0f, halfHeight = 0.0f, x = 0.0f, y = 0.0f;
// Instantiate linear barcode object
BarCodeBuilder barCodeBuilder = new BarCodeBuilder();
barCodeBuilder.CodeText = "FRE0400 - 0000284A";
barCodeBuilder.CodeTextFont = new System.Drawing.Font(barCodeBuilder.CodeTextFont.Name, 10f);
barCodeBuilder.CodeTextSpace = 1f;
barCodeBuilder.xDimension = 0.2f;
barCodeBuilder.BarHeight = 6.5f;
barCodeBuilder.SymbologyType = Aspose.BarCode.Symbology.Code128;
barCodeBuilder.Resolution = new Aspose.BarCode.Resolution(300f, 300f, ResolutionMode.Customized);
barCodeBuilder.BarCodeImage.Save(imageMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp); // Jpeg and BMP are the fastest
barCodeBuilder.BarCodeImage.Save("barcode.bmp");
halfWidth = (float)ConvertUtil.PixelToPoint(barCodeBuilder.BarCodeImage.Width) / 2f;
halfHeight = (float)ConvertUtil.PixelToPoint(barCodeBuilder.BarCodeImage.Height) / 2f;
// Add image to the input PDF file on the first page at specified location
x = (float)pageInfo.Width - halfWidth;
y = (float)pageInfo.Height - halfHeight;
// Set coordinates
double lowerLeftX = x - halfWidth;
double lowerLeftY = y - halfHeight;
double upperRightX = x + halfWidth;
double upperRightY = y + halfHeight;
// Get the page where image needs to be added
Page page = doc.Pages[1];
// Load image into stream
FileStream imageStream = new FileStream("barcode.bmp", FileMode.Open);
// Create Rectangle
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
page.AddImage(imageStream, rectangle, 1000, 500,true);
Stream outStream = new MemoryStream();
doc.Save(outStream);
// Rewind the stream position back to zero so it is ready for next reader
outStream.Position = 0;
FileStream outFileStream1 = new FileStream("file_barcode.pdf", FileMode.Create);
(outStream as MemoryStream).WriteTo(outFileStream1);
}