How to generate a PDF for purchase order record in NetSuite ? by using suite scripts or any other way.Please advice - api

How to generate a PDF for purchase order record in NetSuite ? by using suite scripts or any other way.Please advice, I need to export this pdf to salesforce or you can say i need to attach this purchase order pdf to salesforce oppurtunity - attachment
Am expecting a suite script code where i can get for any reference

You can use N/render Module for creating pdf using suitelet script. You need to save the xml file in file cabinet. Convert your purchase order record advanced pdf file in xml and save that to file cabinet.
var xmlTemplateFile = file.load('Templates/PDF Templates/purchasePDFTemplate.xml');
var renderer = render.create();
renderer.templateContent = xmlTemplateFile.getContents();
renderer.addRecord('record', record.load({
type: record.Type.PURCHASE_ORDER,
id: recId //record id of purchase order
}));
var po_Pdf = renderer.renderAsPdf();
}

Related

How to submit PDF File in a JSP to Servlet?

I have a formular in my JSP, that has an input field for a PDF-file and besides that also other inputs for text and numbers. This is my line for the data upload of the PDF-File and that is how my form starts:
Upload for PDF: <input type="file" name="datei" />
When in my Servlet, I just get the name of the PDF-File, when i request it like this:
String pdf = request.getParameter("datei");
Now how do I upload a pdf-File, submit that to my Servlet, so I can get all the data and Update a row with all this data in my PostGreSQL database?
First the problem is in the form that must have the enctype="multipart/form-data", but so I can't bring over inputs from the type="text". And another form in another one is not possible either. If I leave out the enctype and just pass the to my servlet, I don't know more than to request this parameter e.g. with String pdf = request.getParameter("file");, but there I only get the PDF file name. Additionally I need to store the PDF file in the database. For this I will create another column pdf of type oid, but I don't know how to pass this PDF file through all methods, so that I can finally save it in PostGreSQL and assign it to a seminar.
Thank you

GridFs read PDF

I am trying to build a financial dashboard with Flask and pymongo. The starting point is a flask form which saves data in a MongoDB database. One of the fields in the form is a FileField (wtforms) which allows the upload of a PDF, which is then stored in MongoDB with GridFS.
Now I manage to save the pdf and I can see the resulting entries within the .files and .chunks collections. Now I would like to build a function that retrieves the PDFs and analyses them with some basic NLP, however I struggle with the getting meaningful data.
When I do:
storage = gridfs.GridFS(db, collection)
data = storage.get('some id')
a = data.read()
The result is a binary file. If I continue with:
with open(data, 'rb') as f:
b = f.read()
The result is "ValueError: embedded null byte or sometimes an empty "byte string".
Any help on this?
To follow up on the above, I found a solution for myself that consists in 2 separate functions:
(1) Upon upload of the form and before uploading the files to MongoDB, I apply a function based on pdfminer that extracts the string content of the PDF and tranform it into a list of sentences using NLTK. I will then store this list in the .files via the storage.put(file, sent_list = sent_list) #sent_list being the variable name of the list of sentences.
Whenever I wish to run NLP operations on the file, I will just call the "sent_list" variable from mongodb.
(2) If I wish to display the stored pdf in its original content however, I included the following function as a separate route.
storage = GridFS(db, collection)
data = storage.get_last_version(filename)
response = make_response(data.read())
extension = data.filename.split('.')[-1]
response.headers['Content-Type'] = f'application/{extension}'
response.headers['Content-Disposition'] = f'inline; filename={data.filename}'
return response
(2) will open a new tab in my flask app showing the .pdf file in its original format.
I hope this helps anyone coming across a similar problem in the future.

How to change the name of a PDF file in Crystal Reports?

We have crystal report which generates an invoice for our clients, crystal report's name is invoice.rpt. When crystal report is created and print to PDF file, the default pdf file name is invoice.pdf.
is there a way to change the pdf name to the invoice number (which is a variable inside crystal report)?
for example, we open inovice.rpt to create a invoice 10000, can we print to pdf file and name set to 1000 by default, instead of invoice.pdf?
No such option with Crystal alone.
But several 3rd-party tools provide that functionality. See Ken Hamady's excellent web site for lists and reviews of 3rd-party Crystal Reports tools.
Just change to name of CrystalReportViewerID as desired
CrystalReportViewerID="SaleReport-16Nov2019" in code
ReportClientDocument objReportClientDocument = new ReportClientDocument();
objReportClientDocument.open("WEB-INF\reports\Folder/report.rpt", 0);
IReportSource objIReportSource = objReportClientDocument.getReportSource();
ReportExportControl objReportExportControl = new ReportExportControl();
objReportExportControl.setReportSource(objIReportSource);
objReportExportControl.setName("Report_FileName");

PDF acroform fields become non editable in Adobe reader after writing to it using Pdfbox APIs

I am reading a PDF which has editable fields and the fields can be edited by opening it through Adobe Reader. I am using PDFBox APIs to generate an output PDF with data filled for the editable fields in input PDF. The output PDF can be opened using Adobe Reader and I am able to see the field values but I am unable to edit those fields directly from Adobe reader.
There is also a JIRA ticket for this issue and it is unresolved according to this link :
https://issues.apache.org/jira/browse/PDFBOX-1121
Can anybody please tell me if this got resolved? Also, if possible please answer the following questions related to my question:
Is there any protection policy or access permission that I need to explicitly set in order to edit the output PDF from Adobe reader?
Every time I open the PDF that was written to using pdfbox APIs, I get this message prompt:
" The document has been changed since it was created and use of extended features is no longer available...."
I am using PdfBox 1.8.6 jar and Adobe reader 11.0.8. I would really appreciate if anybody could help me with this issue.
Code snippet added to aid responders in debugging :
String outputFileNameWithPath = "C:\myfolder\testop.pdf";
PDDocument pdf = null;
pdf = PDDocument.load( outputFileNameWithPath );
PDDocumentCatal og docCatalog = pdf.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
//The map pdfValues is a collection of the data that I need to set in the PDF
//I am unable to go into the details of my data soutce
// The key in the data map corresponds to the PDField's expanded name and data
// corresponds to the data that I am trying to set.
Iterator<Entry<String, String>> iter=pdfValues.entrySet().iterator();
String name=null;
String value=null;
PDField field=null;
//Iterate over all data and see if the PDF has a matching field.
while(iter.hasNext()) {
Map.Entry<String, String> currentEntry=iter.next();
name=currentEntry.getKey();
value=currentEntry.getValue();
if(name!=null) {
name=CommonUtils.fromSchemaNameToPdfName(name);
field=acroForm.getField(name);
}
if( field != null && value!=null )
{
field.setValue( value ); //setting the values once field is found.
}
}
// Set access permissions / encryption here before saving
pdf.save(outputFileNameWithPath);
Thanks.
The document has been changed since it was created and use of extended features is no longer available....
This indicates that the original form has been Reader-enabled, i.e. an integrated Usage-Rights digital signature has been applied to the document using a private key held by Adobe which tells the Adobe Reader that it shall make some extra functionality available to the user viewing that form.
If you don't want to break that signature during form fill-ins with PDFBox, you need to make sure that you
don't do any changes but form fill-ins and
save the changes as incremental update.
If you provided your form fill-in code and your source PDF, this could be analyzed in more detail.

Get id of file upload control

I am trying to find the name of ID of the input item that coresponds to the
file that is being uploaded...
<input type="file" id="FUtxtval1" name="FUtxtval1"/>
iterating over input items to find the first file input field:
function FindFirstFileFieldId()
{
var inputFields = document.getElementsByTagName("input")
for(var i=0;i<inputFields.length;i++)
{
if(inputFields[i].type=="file")
return inputFields[i].id;
}
}
The ID of the element is simply "FUtxtval1" (whatever is in the ID tag)
--
For JavaScript you can access this by using
var element = document.getElementById('FUtxtval1');
So you could then do something like
document.element.disabled=true;
--
For jQuery (Also JavaScript) you would use
$('#FUtxtval1').whatever
--
For PHP you would use
$_POST['FUtxtval1']
Assuming this is part of a form
For PHP if you actually want the file you use the handle
$_FILES['FUtxtval1']['whateverwanted'];
See http://www.tizag.com/phpT/fileupload.php
If the problem is that there may be many input tags on the form, and you're interested in discovering which one is specifically used for uploading files, this bit of jQuery code would accomplish that:
var id = $('input[type=file]').attr('id');
If the problem is that you know the element's ID but do not know the name of the field, you can use:
var name = $('#FUtxtval1').attr('name');
If you're hoping to find out the filename of the file your visitor has chosen in that field through JavaScript, you're stuck. JavaScript does not get any access to that information. You'll have to submit the form and let a server-side script determine the filename at that time.
If I understand correctly, you are trying to obtain the id of the uploaded file using javascript? If so, you will have to process the uploaded file using php ($_FILES['FUtxtval1']) and then print the id to a javascript variable.
Is that what you wanted?
If not, update your q to provide a bit more info about what you are trying to achieve.