Hello, i have a problem converting DWG file to PNG
This the code i use:
Aspose.Imaging.ImageOptions.PngOptions OptionsI = new Aspose.Imaging.ImageOptions.PngOptions();
Aspose.Imaging.ResolutionSetting oResI = new Aspose.Imaging.ResolutionSetting(Convert.ToDouble(m_iResolution), Convert.ToDouble(m_iResolution));
OptionsI.ResolutionSettings = oResI;
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsI);
And this is exeption i have when trying saving:
Image export failed.
{“Cannot export non-raster images.”}
what can i do?
I attach DWG sample file i used.
Thank’s a lot
I’m getting the same error saving a DFX to JPG -
using (var img = Aspose.Imaging.Image.Load("fanuc-430-arm.dfx"))
img.Save("fanuc-430-arm.jpg", new Aspose.Imaging.ImageOptions.JpegOptions()
{ Quality = 80, ResolutionSettings = new Aspose.Imaging.ResolutionSetting(150, 150) });
Aspose version 2.5
I’ve found if you go via PDF it works -
using (var img = Aspose.Imaging.Image.Load("fanuc-430-arm.dfx")) using (var ms = new MemoryStream()) { img.Save(ms, new Aspose.Imaging.ImageOptions.PdfOptions() { PageWidth = img.Width, PageHeight = img.Height, DrawType = CadDrawTypeMode.UseDrawColor, ScaleMethod = ScaleType.GrowToFit, ResolutionSettings = new Aspose.Imaging.ResolutionSetting(75, 75) }); var pdf = new Aspose.Pdf.Document(ms); using (var imageStream = new FileStream("fanuc-430-arm.jpg", FileMode.Create)) new Aspose.Pdf.Devices.JpegDevice(150, 150, new Aspose.Pdf.Devices.Resolution(75), 80) .Process(pdf.Pages[1], imageStream); }
Hi all,
I’m trying to save attached DWG as PDF with the workaround suggested by Jonathan, but i obtain a completely white pdf: what’s wrong?
Here’s the code
Aspose.Imaging.ImageOptions.PdfOptions OptionsIP = new Aspose.Imaging.ImageOptions.PdfOptions();
OptionsIP.PageWidth = ((Aspose.Imaging.Image)m_oDocument).Width;
OptionsIP.PageHeight = ((Aspose.Imaging.Image)m_oDocument).Height;
OptionsIP.DrawType = Aspose.Imaging.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
OptionsIP.ScaleMethod = Aspose.Imaging.FileFormats.Cad.ScaleType.GrowToFit;
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsIP);
Hi,
Does not work even if i set 500 to heigth and width in pagesize: are you able to create a non-blank pdf?
Hi,
using (var img = Aspose.Imaging.Image.Load(myDir + “Office.dwg”))
{
var options = new Aspose.Imaging.ImageOptions.PdfOptions();
options.PageHeight = 500;
options.PageWidth = 500;
img.Save(myDir + “output.pdf”, options);
}
OK so two more problems:
1 i can have a non blank pdf commenting this line
OptionsIP.ScaleMethod = Aspose.Imaging.FileFormats.Cad.ScaleType.GrowToFit;
the growtofit goes into page dimension issue itself ?
2 pdf i (and you) obtain is not complete!
if i open dwg file with a dwg reader i can see more items in it (see attached image)
Hi,
- We have logged a new ticket (IMAGING-34285) for the problem of blank PDF generation when large DWG is rendered to smaller canvas with ScaleType.GrowToFit. We will investigate the matter separately, however, we have linked this issue to the previously logged ticket IMAGING-34281 for the problem related to the large page dimensions.
- Textual contents in the DWG drawings cannot be rendered to PDF with current implementation the API, therefore we have logged it as a feature request (IMAGING-34286) in our database, and requested the core team to analyze its feasibility. In case you meant anything else that has been missed while rendering the DWG drawing to PDF format, we would request you to please highlight those areas in a snapshot, and share here for further investigation.
Thanks of the update Babar Raza!
Hi all,
using (var image = (Aspose.Imaging.FileFormats.Cad.CadImage)Image.Load(myDir + “office.dwg”))
{
// Create options
PdfOptions pdfOptions = new PdfOptions();
// Set output file size
pdfOptions.PageWidth = 1500;
pdfOptions.PageHeight = 1200;
// Get layouts of the CadImage
string[] layouts = new string[image.Layouts.Keys.Count];
image.Layouts.Keys.CopyTo(layouts, 0);
// Set Layout name to render
pdfOptions.LayoutName = layouts[1];//“Layout1”;
pdfOptions.ScaleMethod = Aspose.Imaging.FileFormats.Cad.ScaleType.GrowToFit;
// Export
image.Save(myDir + “output.pdf”, pdfOptions);
}
So, using this code:
string[] layouts = new string[((Aspose.Imaging.FileFormats.Cad.CadImage)((Aspose.Imaging.Image)m_oDocument)).Layouts.Keys.Count];
((Aspose.Imaging.FileFormats.Cad.CadImage)((Aspose.Imaging.Image)m_oDocument)).Layouts.Keys.CopyTo(layouts, 0);
OptionsIP.LayoutName = layouts[1]; //“Layout1”;
will insert text layout… but there could be some other layouts? layout2, 3, etc?
that said (and page size issue solved), same option could be implemented in imagesaveoption for converting DWG/DXF to png?
moreover, i have other problem related to page size - see atached files - when i use above code for adding layouts, resultant pdf “shift” bottom in the pdf page: how can i avoid this problem?
in addition to code for layouts i use this code:
Aspose.Imaging.ImageOptions.PdfOptions OptionsIP = new Aspose.Imaging.ImageOptions.PdfOptions();
OptionsIP.PageWidth = 595; //a4
OptionsIP.PageHeight = 595; //a4
to avoid error of wrong pagesize (IMAGING-34285)
so… why you can create the same “mostly centered” image in pdf and we cannot?
thank’s
Hi,
Ok thank you
In the meanwhile i was tinking to solve the issue creating a new pdf document and resizing it, but i’m not able to do it: can you provide me some code for this operation?
This is what i was trying:
save dwg file as pdf …
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsIP);
open new pdf document
Aspose.Pdf.Document oPdfTest = new Aspose.Pdf.Document(_oOutputStream);
the new document has pagesize 842 * 595 points and mediabox/cropbox of 595 * 595 points
i’d like to resize the pagesize to 595 * 595, obviously keeping the entyre mediabox without cutting it, obtaining a pdf with page size same as mediabox/cropbox
is it possible?
demo-1:
This is what i was trying:
save dwg file as pdf …
((Aspose.Imaging.Image)m_oDocument).Save(_oOutputStream, OptionsIP);
open new pdf document
Aspose.Pdf.Document oPdfTest = new Aspose.Pdf.Document(_oOutputStream);
the new document has pagesize 842 * 595 points and mediabox/cropbox of 595 * 595 points
i’d like to resize the pagesize to 595 * 595, obviously keeping the entyre mediabox without cutting it, obtaining a pdf with page size same as mediabox/cropbox
This doesn’t work
I tryed to resize page to (595,595) but the page remain 595, 842
moreover i don’t need actually to resize page but to crop page as the same dimension of cropbox - i can’t know if image in pdf is at the bottom or top of pdf page so i’m trying to crop the page accordingly: remember that my second operation is to save a png from pdf and i have to avoid extra white space in pdf and in images
demo-1:This doesn’t work
I tryed to resize page to (595,595) but the page remain 595, 842
demo-1:moreover i don’t need actually to resize page but to crop page as the same dimension of cropbox - i can’t know if image in pdf is at the bottom or top of pdf page so i’m trying to crop the page accordingly: remember that my second operation is to save a png from pdf and i have to avoid extra white space in pdf and in images
my original test file is the same dwg you have (i attach final generated pdf file with extra white space)
as you can see in commented code, i tryied some different ways but final pdf contains extra white space in every case… can you give me right code for my scenario?
using (MemoryStream oMTempStream = new MemoryStream())
{
((Aspose.Imaging.Image)m_oDocument).Save(oMTempStream, OptionsIP);
Aspose.Pdf.Document oPdfTest = new Aspose.Pdf.Document(new MemoryStream(oMTempStream.ToArray()));
// Aspose.Pdf.Facades.PdfFileEditor oPdfFE = new Aspose.Pdf.Facades.PdfFileEditor();
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeParameters parameters = new Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeParameters(
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units( Convert.ToDouble(oPdfTest.Pages[1].CropBox.Width - oPdfTest.PageInfo.Width)), //left
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units( Convert.ToDouble(oPdfTest.Pages[1].CropBox.Width)), //w
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units(0), //right
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units( Convert.ToDouble(oPdfTest.Pages[1].CropBox.Height - oPdfTest.PageInfo.Height)), //top
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units( Convert.ToDouble(oPdfTest.Pages[1].CropBox.Height)), //h
// Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeValue.Units(0)); //bottom
// oPdfFE.ResizeContents(oPdfTest, new int[]{1}, parameters);
oPdfTest.PageInfo.Width = oPdfTest.Pages[1].CropBox.Width;
oPdfTest.PageInfo.Height = oPdfTest.Pages[1].CropBox.Height;
oPdfTest.Pages[1].MediaBox = new Aspose.Pdf.Rectangle(0, 0, oPdfTest.Pages[1].CropBox.Width, oPdfTest.Pages[1].CropBox.Height);
oPdfTest.Pages[1].CropBox = new Aspose.Pdf.Rectangle(0, 0, oPdfTest.Pages[1].CropBox.Width, oPdfTest.Pages[1].CropBox.Height);
//new Aspose.Pdf.Rectangle(0, 0, oPdfTest.Pages[0].CropBox.Width, oPdfTest.Pages[0].CropBox.Height);
Aspose.Pdf.PageCollection opg = oPdfTest.Pages;
Aspose.Pdf.Page pdfPage = opg[1];
pdfPage.SetPageSize(595, 595);
oPdfTest.Save(_oOutputStream);
}
Hi,