You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by 정승훈 <4u...@gmail.com> on 2013/06/22 12:52:12 UTC
Hello. I have a question using PDDocument.addPage()
Hello, I'm student at Hanyang UNIV. in Korea.
I study PDFbox for developing my PDF Solution.
But now, I have a problem.
I want to insert page anywhere, however PDFbox api only insert page at last.
So I try to inheritance PDDocument class.
---------------------------------------------
myPDDocument.java
...
public class myPDDocument extends PDDocument{
public myPDDocument() throws IOException {
super();
}
...
}
main.java
...
string filename = "abc.pdf"
myPDDocument document = new myPDDocument();
document = (myPDDocument) PDDocument.load(filename);
---------------------------------------------
But "org.apache.pdfbox.pdmodel.PDDocument cannot be cast to
main.myPDDocument" happen.
How do it?
Thank you. Have a nice day!
>From Seounghun, Jeong
Tel) +82-10-2964-2008
Re: Hello. I have a question using PDDocument.addPage()
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 22.06.2013 12:52, schrieb 정승훈:
> Hello, I'm student at Hanyang UNIV. in Korea.
>
> I study PDFbox for developing my PDF Solution.
> But now, I have a problem.
>
> I want to insert page anywhere, however PDFbox api only insert page at last.
> So I try to inheritance PDDocument class.
>
> ---------------------------------------------
> myPDDocument.java
>
> ...
>
> public class myPDDocument extends PDDocument{
>
> public myPDDocument() throws IOException {
>
> super();
>
> }
>
> ...
>
> }
>
>
> main.java
>
> ...
> string filename = "abc.pdf"
>
> myPDDocument document = new myPDDocument();
>
> document = (myPDDocument) PDDocument.load(filename);
> ---------------------------------------------
>
> But "org.apache.pdfbox.pdmodel.PDDocument cannot be cast to
> main.myPDDocument" happen.
>
> How do it?
PDDocument.load() is a static method and returns always an instance of
PDDocument which can't be cast to your class. There are to possible solutions
- trasnform the provided PDDocument into your class as follows:
PDDocument doc = PDDocument.load(filename);
myPDDocument myDoc = new myPDDocument(doc.getDocument());
- override the load-method too using the same idea as above
> Thank you. Have a nice day!
>
> From Seounghun, Jeong
>
> Tel) +82-10-2964-2008
BR
Andreas Lehmkühler