Creating PDF using ITEXT API's - error
Hi,
In my WebDynpro Application I want to generate a PDF (using ITEXT API's) out of the data retrieved from back end system .
I used this source code.
Document document = new Document(PageSize.A4);
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell;
cell = new PdfPCell(new Paragraph("ONE"));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TWO"));
table.addCell(cell);
document.add(table);
document.close();
byte[] b = new byte[100 * 1024];
b = document.toString().getBytes("UTF-8");
IWDCachedWebResource pdfRes = WDWebResource.getPublicCachedWebResource(b, WDWebResourceType.PDF, WDScopeType.CLIENTSESSION_SCOPE, wdThis.wdGetAPI().getComponent().getDeployableObjectPart(),"FileNameHelloText"));
I have used Window Manager to create a external window with the URL from pdfRes.getUrl() method.
After execution i get a pop up window with out PDF document.
Please let me know your thoughts & solutions to the above mentioned problem.
Thanks
Senthil
Hello Folks,
Use the following snippet of the code to generate PDF using ITEXT API.
Document document = new Document(PageSize.A4);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, bos);
document.open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell;
cell = new PdfPCell(new Paragraph("ONE"));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TWO"));
table.addCell(cell);
document.add(table);
document.close();
byte [] byteContent = bos.toByteArray();
IWDCachedWebResource cachedResource =
WDWebResource.getPublicCachedWebResource(
byteContent,
WDWebResourceType.PDF,
WDScopeType.CLIENTSESSION_SCOPE,
wdThis
.wdGetAPI()
.getComponent()
.getDeployableObjectPart(),
"TestPDF");
IWDWindow externalWindow =
wdComponentAPI
.getWindowManager()
.createExternalWindow(cachedResource.getURL(), "PDF Window",true);
externalWindow.open();
Thanks and Regards,
Gopi
Similar Messages
-
Hi
While trying to Create Projects using the API, I'm getting two types of errors -
The first is : 'API failed in one stage 1 Customer Name is a mandatory Quick Entry field. Value must be passed'
The second is : '
'API failed in one stage 1 Project: '<Project_Number>'
The class category is invalid.'
Both the messages are produced by our custom program. .. however I am not able to understand why the underlying errors occur.
The first error ( Customer Name is a mandatory quick entry field), is caused by Projects that are to be created from Project templates where it is configured with Quick Entry Customer Name required. We are passing Customer Site number ( Party Bill to site number and Party Ship to side number). The site numbers being passed are also set as 'Primary'. Yet they are failing.
For the second Error ( The Class Category is invalid), I rechecked multiple times, the Class categories for the Projects I am trying to create, with the Config in R12 and they are fine. Can't understand the reason for these two issues. Has anyone encountered such an issue ? If so how was it resolved?
Regards
VivekHI All
I resolved both the issues. In case there are others facing similar issues, following was the cause and resolution of my errors
1. Error 1: Customer Name is a Mandatory Quick Entry field. Value must be passed.
The cause was that the data loaded into our custom staging table was not in the right fields. This was because the data file values and the CTL were not in sync.
Resolution:
Corrected the data file to be in Sync with the structure defined in the CTL and this loaded it successfully
2. Error 2: The class category is invalid.
The cause of this error was that in the Projects Template (used to create the project from), the Quick Entry setup had a Class Category set as required and I was not passing a value ( a class code value) for that Class Category.
Hope this helps somebody else
Cheers
Turnbill -
when creating invoice using the API AR_INVOICE_AP_PUB.Create_Single_invoice Am Getting the below Error:
Transaction type is invalid with current transaction date
invalid transaction type
either an inventory item description must be provided
Kindly help me hereHi Team,
I tried creating the invoice and I got the above errors, however, when updated the batch source ID I am now getting this following error only, i am just left with the following Error only
Either an inventory item or description must be provided.
Please help me on this. -
Adding a link in PDF using itext
I am adding a link in PDF using itext and opening the link from the final created pdf using app.launchURL and app.getURL
it works fine on windows XP but does nothing on MAC OSX /IOSHi Lynn
And here I was about to suggest you review the link below.
Silly me.
Click
here to read the article
Sincerely... Rick -
I am unable to create pdf using adobe printer to a redirected folder on a server running windows server 2003
In the app-server-ant.xml file, as indiacted in the error message i am getting, at line 145 it is suppose to get the path to \bin\asadmin.bat from the value of a paramater called 'asadmin'. This value is being set in the beginning of the file.
The parameter value of 'asadmin' is further referring to value of another parameter called 'javaee.home' which is being set in tut-install/javaeetutorial5/examples/bp-project/build.properties
I have checked the values of both these parameters and they are set correctly, so since it is still giving me problems, at line 145 i hard coded the path instead of the parameter name:
I replaced line
<exec executable="${asadmin}" failonerror="${failonerror}" dir="${javaee.home}">
with
<exec executable="c:/sun/appserver/bin/asadmin.bat" failonerror="${failonerror}" dir="${javaee.home}">
This works. -
Scrollbar appearing while creating pdf using AlivePDF
Hi,
I am facing a problem while creating pdf using AlivePDF.
I have a VBox on which I am adding multiple pages. If the content overflows it shows scrollbar. All this is working fine.
[PHP]
<mx:VBox x="0" y="80" width="705" height="560" id="content"></mx:VBox>
[/PHP]
When I create the pdf using the following code it shows scrollbar in generated pdf (attached screenshot) while I want all the content without scrollbar
[PHP]
var pg:DisplayObject;
pg = content.getChildAt(i);
var pdf:PDF;
pdf = new PDF (Orientation.PORTRAIT, Unit.POINT, Size.LETTER);
pdf.setDisplayMode(Display.FULL_WIDTH);
pdf.addPage();
pdf.addImage(pg, new Resize(Mode.FIT_TO_PAGE, Position.CENTERED ),0, 0, 0, 0, 0, 1,true,'PNG',100);
[/PHP]
Please suggest what changes should I make to fix this.If the report didn't change, then perhaps the data did. Check
to make sure the data being supplied to the report is as expected.
I have run into mysterious errors where an expected value was of
the wrong type or a required value was now blank. It is also
possible to have existing logical errors in an iif() or other
dynamic evaluation expression that was not previously examined;
until now. So, is there any unexpected or exceptional data the
report cannot handle? -
Adding text to PDF using iText instead of CFPDF
Hi,
I know this may seem a bit off topic being posted here but i'm asking this board since i'm a complete JAVA noob and i figure some of you CF folk might have had to do this before.
Anyway, about my question...i'm already adding a watermark image to a pdf using iText (CF8) thanks to the help of fellow poster (=cfSearching=). What i'm looking for is the best way to go about adding some text to this same pdf. I need to add 4 lines of text (with specific font and size) and center it underneath the added image. Does anyone have a site they could point me to as to how to add formatted text and how to get the width of that text so as to align it correctly? I've search Google and looked at a lot of JAVA code but being a JAVA noob it's tough to figure out exactly which libs and methods can be used to do this.
Any help would be greatly appreciated!
-MichaelHi again!
Well, the merged image is an idea but i'd rather have it be actual text so that it is at least copy/paste-able if viewed on a computer.
The four lines of text are dynamic (company name, broker name, phone number, email address) and limited to 40 characters. Right now they are being added via CFPDF and DDX and use the following code in the DDX file to add it to the PDF.
<PDF result="DestinationFile">
<PDF source="SourceFile">
<Watermark
rotation="0"
opacity="100%"
horizontalAnchor="#horzAnchor#"
horizontalOffset="#horzOffset#"
verticalAnchor="#vertAnchor#"
verticalOffset="#vertOffset#"
alternation="OddPages"
>
<StyledText text-align="center">
<p font="#font#" color="#color#" >#left(dCompany,maxlinechars)#</p>
<p font="#font#" color="#color#" >#left(dName,maxlinechars)#</p>
<p font="#font#" color="#color#" >#left(dPhone,maxlinechars)#</p>
<p font="#font#" color="#color#" >#left(dEmail,maxlinechars)#</p>
</StyledText>
</Watermark>
</PDF>
</PDF>
Then using the created pdf from above, i use a slightly modified version of the cfscript code ( that uses iText) you provided me previously to add a logo image just above this text. The only changes i made to it were resizing of the image and adding where to place it. Here is that code:
<cfscript>
fullPathToInputFile = "#tempdestfilepath#";
writeoutput("<br>fullPathToInputFile=#fullPathToInputFile#");
fullPathToWatermark = osFile("#request.logofilepath##qord.userlogo_file#",request.os);
writeoutput("<br>fullPathToWatermark=#fullPathToWatermark#");
fullPathToOutputFile = "#destfilepath#";
writeoutput("<br>fullPathToOutputFile=#fullPathToOutputFile#");
ppi = 72; // points per inch
watermark_x = ceiling(#qord.pdftemplate_logo_x# * ppi); // from bottom left corder of pdf
watermark_y = ceiling(#qord.pdftemplate_logo_y# * ppi); // from bottom left corder of pdf
fh = ceiling(0.75 * ppi);
fw = ceiling(1.75 * ppi);
if( not fileexists(fullPathToInputFile) )
savedErrorMessage = savedErrorMessage & "<li>Input file pdf for logo add does not exist<br>#fullPathToInputFile#</li>";
else
try {
// create PdfReader instance to read in source pdf
pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(fullPathToInputFile);
totalPages = pdfReader.getNumberOfPages();
// create PdfStamper instance to create new watermarked file
outStream = createObject("java", "java.io.FileOutputStream").init(fullPathToOutputFile);
pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(pdfReader, outStream);
// Read in the watermark image
img = createObject("java", "com.lowagie.text.Image").getInstance(fullPathToWatermark);
w = img.scaledWidth();
h = img.scaledHeight();
//$is[0] = w
//$is[1] = h
if( w >= h )
orientation = 0;
else
orientation = 1;
fw = max_h;
fh = max_w;
if ( w > fw || h > fh )
if( ( w - fw ) >= ( h - fh ) )
iw = fw;
ih = ( fw / w ) * h;
else
ih = fh;
iw = ( ih / h ) * w;
t = 1;
else
iw = w;
ih = h;
t = 2;
// adding content to each page
i = 0;
//while (i LT totalPages) {
i = i + 1;
content = pdfStamper.getOverContent( javacast("int", i) );
img.setAbsolutePosition(javacast("float", watermark_x), javacast("float", watermark_y));
if(t==1)
img.scaleAbsoluteWidth( javacast("float", iw) );
img.scaleAbsoluteHeight( javacast("float", ih) );
content.addImage(img);
WriteOutput("Watermarked page "& i &"<br>");
//WriteOutput("Finished!");
catch (java.lang.Exception e) {
savedErrorMessage = savedErrorMessage & "<li>#e#</li>";
// closing PdfStamper will generate the new PDF file
if (IsDefined("pdfStamper")) {
pdfStamper.close();
if (IsDefined("outStream")) {
outStream.close();
</cfscript>
The above code resized the image to a certain width/height if needed and adds it to the pdf.
I just figured they might be a way to tap into one of the java objects that would allow adding the text. Ideally, adding the text and image to some sort of 'bounding box' that would allow centering of the image and text in relation to that bounding box. Or if there is no way to add to a bounding box, a way to get the horizontal length of the longest line of text so i could calculate a common centerline for the image and text.
I've attached the following pdf to show how the image and text would look together. This example is not to scale but a similar image and text would be added to a separate pdf.
Thanks for you help. -
To generate PDF using BI APIs and loadjava utility
Hi All,
I am trying to generate PDF using BI APIs(FOProcessor etc).
I have generated XML data through the PL/SQl procedure and storing it in a file. This file is loacted in database tier.
The APIs is used through a simple java program which is application tier. To test the process, I had to manually provide the XML file to the java class in order to generate PDF and it does generate.
Now the issue is I need to load the java class to the database so that everything gets automated(loadjava utlility).
when i try to do it, it give no class found error.
Do I need to load the referenced classes in the java file , that is, FOProcessor,RTFProcessor,FOUtility,jdbc.driver.OracleDriver as well?
If the above is not possible, is it possible to reference a file in database tier from application tier so that i can use the XML file as input the java class in application tier.
thanks,
SrikThe only reason I am responding to this post is because the poster sent me a request through the forum message system asking for my help.
Although I did populate PDFs with FDF data generated by web forms a year or so ago, I have since abandoned that kind of solution. It was a big headache. I found it far more stable and flexible to use html, php and css to populate forms that are almost as nice looking as PDFs.
So my advice is, if you can possibly avoid going the FDF/PDF route, you will be better off. -
How to write special characters in PDF using iText
How to write special characters encoded with UTF-8 in PDF using iText.
Regards,
Pandharinath.I don't know what your problem is but that's almost certainly the wrong question to ask about it. Java (including iText) uses only Unicode characters. (You may consider some of them to be "special" if you like but Unicode doesn't.) And when it does that, they aren't encoded in UTF-8 or any other encoding.
So can you describe your problem? That question doesn't make sense. -
Problem while generating PDF using iText
Hi:
I have generated PDF using iText, where i have written all code in sequential flow.
<code>
com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.A4, 55, 5, 20, 20);
OutputStream outputstream = response.getOutputStream();
PdfWriter.getInstance(document,outputstream);
</code>
And i have added all fields in the document.
But my problem is how to display total pagecount on all pages e.g.1\20 (because i have generated PDF sequentially)
Also i want to add watermark on all pages.
So, can any body help me to solve this problem?
Thank You,
Balajisabre150 wrote:
Maybe http://itext-general.2136553.n4.nabble.com/
Nice pron link in there :/ -
Hi,
I am trying to create PDF using BAPI. I got one BAPI(Z_MM_EPSP_BAPI_GET_PO_PDF). That bapi returns bytecodes. How can I generate PDF file using this BAPI output in BLS. Give some example
Thanks & Regards
ArtArt,
Are you familiar with xMII at all? I would like to answer your question but it seems more like a tutoring lesson rather than a technical problem.
Please post a problem and not how somone can help you do your work. Unless of course you are willing to paypal some money over. :-D -
Idea about convert word document to pdf using java api
idea about convert word document to pdf using java api if any one find it mail me at [email protected]
api if any one find it mail me at
[email protected]
What happend to your other mailID :
[email protected] ????
http://forum.java.sun.com/thread.jspa?threadID=639851&
messageID=3756910It received the Spam Of Death. RIP -
How read a pdf file and change TableCell height after reading it using itext api
I have created a pdf form file using itext ( see class CreatingFormClass ) with itext PdfPTable and PdfPCell. It is done successfully .
Now I read this pdf file and filling this pdf file(see class FillingFormClass ) and at this point i want to change PdfPCell height () according to Items.
It is possible or Not???
My code is given below.
Thanx in advance
public class FillPdfFormMainClass {
public static String RESULT1 = "E:/BlankForm.pdf";
public static String RESULT2 = "E:/FilledForm.pdf";
public static void main(String[] args) throws DocumentException, IOException {
String empName="Rakesh Kumar Verma";
// This part is Dynamic. It can be 1 item Or can be 25 items
String listOfItem="Item 1 \n Item 2 \n Item 3\n Item 4 \n Item 5 \n Item 6 \n Item 7 \n Item 8 \n Item 9";
CreatingFormClass example = new CreatingFormClass(0);
example.createPdf(RESULT1);
FillingFormClass class1 = new FillingFormClass();
class1.manipulatePdf(RESULT1, RESULT2,empName,listOfItem);
public class CreatingFormClass implements PdfPCellEvent {
protected int tf;
public CreatingFormClass(int tf) {
this.tf = tf;
public void createPdf(String filename) throws DocumentException, IOException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
PdfPCell cell;
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[]{1, 2});
table.addCell("Name:");
cell = new PdfPCell();
cell.setCellEvent(new CreatingFormClass(1));
table.addCell(cell);
table.addCell("Item List:");
cell = new PdfPCell();
cell.setCellEvent(new CreatingFormClass(2));
cell.setFixedHeight(60);
table.addCell(cell);
document.add(table);
document.close();
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
PdfWriter writer = canvases[0].getPdfWriter();
TextField text = new TextField(writer, rectangle, String.format("text_%s", tf));
text.setBackgroundColor(new GrayColor(0.95f));
switch (tf) {
case 1:
text.setText("Enter your name here...");
text.setFontSize(8);
text.setAlignment(Element.ALIGN_CENTER);
break;
case 2:
text.setFontSize(8);
text.setText("Enter Your Address");
text.setOptions(TextField.MULTILINE);
break;
try {
PdfFormField field = text.getTextField();
writer.addAnnotation(field);
} catch (IOException ioe) {
throw new ExceptionConverter(ioe);
} catch (DocumentException de) {
throw new ExceptionConverter(de);
public class FillingFormClass {
public void manipulatePdf(String src, String dest,String empName,String listOfItem) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(String.format(dest, empName)));
AcroFields form = stamper.getAcroFields();
form.setField("text_1", empName);
form.setField("text_2", listOfItem);
stamper.close();
reader.close();Hi,
I am facing the same problem. Please help me out. I just want to read a PDF file as bytes from one location and write it as another pdf file in some other location with a diolog box prompting to open or save in the location where we want.
I executed the following code:
try{
File report =new File(location);
BufferedInputStream in=new BufferedInputStream(new FileInputStream(report));
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + report.getName());
OutputStream outs = response.getOutputStream();
int readlen;
byte buffer[] = new byte[ 256 ];
while( (readlen = in.read( buffer )) != -1 )
outs.write( buffer, 0, readlen );
outs.flush();
outs.close();
in.close();
response.setStatus(HttpServletResponse.SC_OK);
} catch (FileNotFoundException fileNotFoundException) {
PrintWriter out= response.getWriter();
out.print("<center><Font color = 'RED'><b>"+PxDSLUtils.getApplicationProperty("label.error.CTM_E017")+"</b></Font></center>");
Though it prompts with open, save dialog box when i try to open directly or when i save it some where locally and then open it i am getting the following message " File is repaired ot damaged.Operation failed." Any idea about what can be done??? Its very urgent.Please suggest.
I am not convetin to string just reading and writng as bytes itself.
Thanks in advance,
Mani -
Error while creating PDF using asynchronous
Hi,
I was using Asynchronous call to generate PDF. It was
working for some time. Now it is showing error.
We are not able to able to create PDF reports at that time.
When we are checking the exception log of the CF Server, we can
find the following error.
"Error","Thread-16","12/05/07","10:58:51",,"Error invoking
CFC for gateway CreatePDF: An exception occurred when performing
document processing. The cause of this exception was that:
java.lang.IllegalArgumentException."
coldfusion.tagext.lang.DocumentTagException: An exception
occurred when performing document processing.
at
coldfusion.tagext.lang.DocumentTag.doAfterBody(DocumentTag.java:1209)
at
cfGeneratePDF2ecfc1106407227$funcONINCOMINGMESSAGE.runFunction(C:\Inetpub\wwwroot\mycfsit e\reports\CF\model\GeneratePDF.cfc:343)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:344)
at
coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
at
coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:254)
at
coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:56)
at
coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:207)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:169)
at
coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:194)
at
coldfusion.filter.EventComponentFilter.invoke(EventComponentFilter.java:67)
at
coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:225)
at
coldfusion.filter.EventRequestMonitorFilter.invoke(EventRequestMonitorFilter.java:46)
at
coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:2 8)
at
coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at
coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at
coldfusion.eventgateway.EventProxy.invokeComponent(EventProxy.java:52)
at
coldfusion.eventgateway.EventRequestHandler.invokeCFC(EventRequestHandler.java:165)
at
coldfusion.eventgateway.EventRequestHandler.processRequest(EventRequestHandler.java:102)
at
coldfusion.eventgateway.EventRequestDispatcher$Task.run(EventRequestDispatcher.java:121)
at
coldfusion.util.SimpleWorkerThread.run(SimpleThreadPool.java:214)
Anyone having idea about this error?
Please help to track this.
Thanks in advanceIf the report didn't change, then perhaps the data did. Check
to make sure the data being supplied to the report is as expected.
I have run into mysterious errors where an expected value was of
the wrong type or a required value was now blank. It is also
possible to have existing logical errors in an iif() or other
dynamic evaluation expression that was not previously examined;
until now. So, is there any unexpected or exceptional data the
report cannot handle? -
Create pdf using a .xdp file and iText
Hello experts,
my question is regarding the generation of a pdf file using a .xdp file and the iText API. I have an .xdp file of a designed form and I would like to generate a pdf using this file, the iText API and the context.
Is it possible? are there any tutorials or examples? any help is welcome!
Thanks in advance.
AlperenHi,
Please check the following links:
How to import an xdp-File to Web Dynpro Interactive Forms
https://wiki.sdn.sap.com/wiki/display/XI/CODE-CreateaPDFFileviatheiText+Library
Sample project how to use Itext (pdf) in webdynpro
Itext PDF Creation
Regards.
Rajat
Maybe you are looking for
-
Generic Object Services for a standard transaction code
Hi, We have a requirement where we are depreciating the assets (standard transaction ABAA) using a custom BDC program. We need to maintain a history (called audit trail) for the particular asset that has been depreciated using this program. For this
-
How to use external DLLs in InDesign server plugin
Hi, I am working on a project, which is having dependency on libxml2 library. I compiled the code on 64 bit Windows platform and using InDesign server 64 bit version. I put the required DLLs in Adobe InDesign CS6 Server x64 folder(with other DLLs). B
-
HI, I have SL 10.6.8 installed on a partitions on my external Drive with iPhot 8.1.2 in the applications foleder, I also have a disk I make a couple years ago with photos of myu iPhoto file. The ifor I get from the iPhoto icon on the disk says it i
-
Cssmill - how do you use it?
Looking at cssmill for the first time, and i'm trying to figure out some things... 1) how would you use cssmill to create the default - out-of-the-box stylesheets? The ones that are deployed after install don't have any 508 styles, but they are gener
-
The importer reported a geniric error
Hi, I can't upload any file in my Premiere Elements 10. getting the error message "The importer reported a geniric error". It used to work well before (I have uploaded same file earlier). My laptop was crashed. So i restored it and re-installed PE10.