I am using Aspose.Words to create a PostScript document that I sent to a printer using Windows PrintAPI, and CUPS on Mac/Linux.
This is how I generate the file:
Aspose.Words.Document asposeDoc = new Aspose.Words.Document();
// image format
DocumentBuilder builder = new DocumentBuilder(asposeDoc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromStream(pageData))
{
// Find which dimension the frames in this image represent. For example
// the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(dimension);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
SaveOptions opts = PsSaveOptions.CreateSaveOptions(SaveFormat.Ps);
asposeDoc.Save(outStream, opts);
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
When I send this PS file to the print APIs, the image prints rotated 90 degrees.
However, if I instead save this exact document with SaveFormat.PNG, the image is not rotated.
Am I doing something wrong when making the PostScript file?
The PS file views correctly if I look at it with various online viewers.
Thanks for your inquiry. Could you please attach your input image here for testing? We will investigate the issue on our side and provide you more information.
Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-12764. You will be notified via this forum thread once this issue is resolved.
Thanks for your patience. Please use PageSetup.Orientation as Landscape to fix this issue. See the highlighted code snippet below.
Aspose.Words.Document asposeDoc = new Aspose.Words.Document();
// image format
DocumentBuilder builder = new DocumentBuilder(asposeDoc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(MyDir + "nao.png"))
{
// Find which dimension the frames in this image represent. For example
// the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(dimension);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
asposeDoc.FirstSection.PageSetup.Orientation = Orientation.Landscape;
Aspose.Words.Saving.SaveOptions opts = PsSaveOptions.CreateSaveOptions(SaveFormat.Ps);
asposeDoc.Save(MyDir + "Out.ps", opts);
I am not sure if this is truly the correct solution. When saving the Aspose Document as an image, or as an XPS document, I do not need to do this. The image is correctly oriented.
The image in question should fit within the page layout of “Portrait”. It’s not big enough to require landscape.
The rotation only seems to occur with PostScript output.
Thanks for your feedback. We have logged the shared detail in our issue tracking system. We will let you know once there is any update available about this issue.
Thank you for shared details. I am the developer who are working on this issue. As I can see orientation of the image is correct in all output formats including PostScript. I suppose the problem occurs only when you print PostScript on paper. Am I right? If so, I think there are some settings in print API you can play with, like fit to page or auto detect orientation.
In your code you change dimensions of page to fit the image, but maybe in your case (I mean printing) you should use paper size the same as you have in your printer and scale the image accordingly.
Hi Andew,
Thank you for additional information. I checked PostScript specification and here what it says:
“To allow pages of the same dimensions in portrait (height greater than width) and landscape (width greater than height) orientations to be interspersed on the same physical medium, the setpagedevice operator rotates the default user space for landscape orientation 90 degrees counterclockwise with respect to that for portrait orientation.”
In your case width of page is greater than height and smart PostScript device rotates it.
As a possible solution, I would suggest you use normal page size when you generate document (do not adjust page dimensions to image size). In this case page orientation will be portrait and output will be printed correctly. For example see the following code:
DocumentBuilder builder = new DocumentBuilder();
builder.InsertImage(@"C:\Temp\nao.png");
builder.Document.Save(@"C:\Temp\out.ps");
You can also adjust page margins and shape size if required.
Hope this helps,
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.