本帖最后由 Sring65 于 2024-9-23 16:24 编辑
teigha 4.02 pdf可以设置大小,成功导出指定大小页面
- private void Update1() // export to pdf
- {
- OdRxModule mod = Globals.odrxDynamicLinker().loadApp("TD_PdfExport");
- if (null == mod)
- {
- MessageBox.Show("Failed to load PDF export module", "Error");
- }
- Microsoft.Win32.SaveFileDialog dlgPdf = new Microsoft.Win32.SaveFileDialog();
- dlgPdf.DefaultExt = ".pdf";
- dlgPdf.Title = "PDF Export default";
- dlgPdf.Filter = "PDF files|*.pdf";
- // Display SaveFileDialog by calling ShowDialog method
- if (dlgPdf.ShowDialog() != true)
- {
- return;
- }
- using (PDFExportParams Params = new PDFExportParams())
- {
- OdGsPageParams pParams = new OdGsPageParams();
- Params.setDatabase(TDDatabase);
- Params.setVersion(PDFExportParams.PDFExportVersions.kPDFv1_5);
- using (OdStreamBuf file = Globals.odrxSystemServices().createFile(dlgPdf.FileName, FileAccessMode.kFileWrite, FileShareMode.kShareDenyNo, FileCreationDisposition.kCreateAlways))
- {
- Params.setOutput(file);
- Params.setExportFlags(
- (PDFExportParams.PDFExportFlags.kEmbededTTF) |
- (PDFExportParams.PDFExportFlags.kSHXTextAsGeometry) | // no in sample
- //(PDFExportParams.PDFExportFlags.kTTFTextAsGeometry) | // no in sample
- (PDFExportParams.PDFExportFlags.kSimpleGeomOptimization) |
- (PDFExportParams.PDFExportFlags.kZoomToExtentsMode) |
- (PDFExportParams.PDFExportFlags.kEnableLayers) | // under condition
- (PDFExportParams.PDFExportFlags.kIncludeOffLayers) | // under condition
- (PDFExportParams.PDFExportFlags.kUseHLR) |
- (PDFExportParams.PDFExportFlags.kFlateCompression) |
- (PDFExportParams.PDFExportFlags.kASCIIHexEncoding) |
- (PDFExportParams.PDFExportFlags.kExportHyperlinks));
- Params.setTitle(dlgPdf.Title);
- //Params.setAuthor("WpfSample2");
- //Params.setSubject("WpfSample2");
- //Params.setKeywords("WpfSample2");
- //Params.setCreator("WpfSample2");
- //Params.setProducer("WpfSample2");
- UInt32[] CurPalette = AllPalettes.getLightPalette();// OdDgColorTable.currentPalette(CurDb);
- CurPalette[255] = 0x00ffffff; // the same as ODRGB(255, 255, 255); in the similar C++ code extract
- //OdDbColorTable.correctPaletteForWhiteBackground(CurPalette);
- Params.Palette = CurPalette;
- Params.setBackground(CurPalette[0]);
- /*if (dlgPdf.m_Layouts == 1) // all
- {
- OdDbModelTable pModelTable = TDDatabase.getModelTable();
- if (null != pModelTable)
- {
- OdDgElementIterator pIter = pModelTable.createIterator();
- for (; !pIter.done(); pIter.step())
- {
- OdDgModel pModel = OdDgModel.cast(pIter.item().openObject());
- if (null != pModel)
- {
- Params.layouts.Add(pModel.getName());
- }
- }
- }
- }*/
- /*Params.layouts.Add(TDDatabase.findActiveLayout(true));
- UInt32 nPages = (UInt32)(1 > Params.layouts.Count ? 1 : Params.layouts.Count);
- OdGsPageParams pageParams = new OdGsPageParams();
- pageParams.set(210, 295);
- Params.pageParams.resize(nPages);*/
- OdGsPageParams pageParams = new OdGsPageParams();
- pageParams.set(400, 400);
- OdGsPageParamsArray odGsPageParamsArray = new OdGsPageParamsArray();
- odGsPageParamsArray.Add(pageParams);
- Params.setPageParams(odGsPageParamsArray);
- PdfExportModule module = new PdfExportModule(OdRxModule.getCPtr(mod).Handle, false); //= PdfExportModule.cast();
- OdPdfExport exporter = module.create();
- UInt32 errCode = exporter.exportPdf(Params);
- if (errCode != 0)
- {
- String errMes = exporter.exportPdfErrorCode(errCode);
- String str;
- str = string.Format("Error number : {0}. \n {1}", errCode, errMes);
- if (errCode == 0x10008)
- {
- str += "\nPlease enable Zoom to extents check box or\ndefine page parameters for layout in page setup dialog.";
- }
- MessageBox.Show("PDF error", str);
- }
- }
- }
- }
|