pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkuehler <andr...@lehmi.de>
Subject Re: Hello. I have a question using PDDocument.addPage()
Date Sun, 23 Jun 2013 12:06:51 GMT
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


Mime
View raw message