This is a puzzler. I can run this exact same code as a stand-alone program and it works fine. But when I run it on a server which has been triggered by a web page, then I get the following error in the Chrome browser console:

Access to XMLHttpRequest at 'http://desktop-60nl2pl:9998/GCad/createDimCtrlPlanPdf' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


The strange part to me is the error occurs on the following line:

|table.draw(); |which is running on the server and has nothing to do with the browser at that time. Here is the full code for perspective |publicStringcreateDimCtrlPlanPdf(EnDatabasedb,intuserId,Stringdata){StringretVal ="[]";try{// Set marginsfloatmargin =10;// Initialize DocumentPDDocumentdoc =newPDDocument();PDPagepage =newPDPage();doc.addPage(page);floatyStartNewPage =page.getMediaBox().getHeight()-(2*margin);// Initialize tablefloattableWidth =page.getMediaBox().getWidth()-(2*margin);booleandrawContent =false;floatyStart =yStartNewPage;floatbottomMargin =70;BaseTabletable =newBaseTable(yStart,yStartNewPage,bottomMargin,tableWidth,margin,doc,page,true,drawContent);// Create Header rowbe.quodlibet.boxable.Row<PDPage>headerRow =table.createRow(15f);be.quodlibet.boxable.Cell<PDPage>cell =headerRow.createCell(100,"Dimensional Control Plan");table.addHeaderRow(headerRow);// Create 6-column 2nd header rowrow =table.createRow(15f);cell =row.createCell(10,"Lower limit");cell =row.createCell(10,"Upper limit");cell =row.createCell(15,"Rep.");cell =row.createCell(15,"Target");cell =row.createCell(15,"Average limit");cell =row.createCell(15,"Standard deviation max");cell =row.createCell(20,"the drawing");table.draw();//CORS error occurs here when running on a server which has been called by a web page// Close Stream and save pdfFilefile =newFile("DimCtrlPlan.pdf");System.out.println("Sample file saved at : "+file.getAbsolutePath());//Files.createParentDirs(file);doc.save(file);doc.close();}catch(IOExceptionex){Logger.getLogger(EnCad.class.getName()).log(Level.SEVERE,null,ex);}catch(COSVisitorExceptionex){Logger.getLogger(EnCad.class.getName()).log(Level.SEVERE,null,ex);}returnretVal;} Any suggestions? |||

Reply via email to